PatientDiscoveryPolicyChecker extends
        AbstractPatientDiscoveryPolicyChecker<RespondingGatewayPRPAIN201305UV02RequestType, PRPAIN201305UV02> { @Override public boolean checkOutgoingPolicy(RespondingGatewayPRPAIN201305UV02RequestType request) { LOG.debug("checking the policy engine for the new request to a target community"); PatientDiscoveryPolicyTransformHelper oPatientDiscoveryPolicyTransformHelper = new PatientDiscoveryPolicyTransformHelper(); CheckPolicyRequestType checkPolicyRequest = oPatientDiscoveryPolicyTransformHelper .transformPatientDiscoveryEntityToCheckPolicy(request); return invokePolicyEngine(checkPolicyRequest); } PatientDiscoveryPolicyChecker(GenericFactory<PolicyEngineProxy> policyEngFactory); static PatientDiscoveryPolicyChecker getInstance(); @Override boolean checkIncomingPolicy(PRPAIN201305UV02 request, AssertionType assertion); @Override boolean checkOutgoingPolicy(RespondingGatewayPRPAIN201305UV02RequestType request);  }
@Test public void testCheckOutgoingPolicy() { System.out.println("testCheckOutgoingPolicy"); RespondingGatewayPRPAIN201305UV02RequestType request = new RespondingGatewayPRPAIN201305UV02RequestType(); GenericFactory<PolicyEngineProxy> policyEngineProxyFactory = new GenericFactory<PolicyEngineProxy>() { @Override public PolicyEngineProxy create() { return mockPolicyEngineProxy; } }; final CheckPolicyResponseType response = new CheckPolicyResponseType(); createPermitPolicy(response); context.checking(new Expectations() { { oneOf(mockPolicyEngineProxy).checkPolicy(with(aNull(CheckPolicyRequestType.class)), with(aNull(AssertionType.class))); will(returnValue(response)); } }); PatientDiscoveryPolicyChecker instance = new PatientDiscoveryPolicyChecker(policyEngineProxyFactory); boolean result = instance.checkOutgoingPolicy(request); assertEquals(true, result); }
@Test public void testCheckOutgoingPolicyFails() { System.out.println("testCheckOutgoingPolicyFails"); RespondingGatewayPRPAIN201305UV02RequestType request = new RespondingGatewayPRPAIN201305UV02RequestType(); GenericFactory<PolicyEngineProxy> policyEngineProxyFactory = new GenericFactory<PolicyEngineProxy>() { @Override public PolicyEngineProxy create() { return mockPolicyEngineProxy; } }; final CheckPolicyResponseType response = new CheckPolicyResponseType(); createDenyPolicy(response); context.checking(new Expectations() { { oneOf(mockPolicyEngineProxy).checkPolicy(with(aNull(CheckPolicyRequestType.class)), with(aNull(AssertionType.class))); will(returnValue(response)); } }); PatientDiscoveryPolicyChecker instance = new PatientDiscoveryPolicyChecker(policyEngineProxyFactory); boolean result = instance.checkOutgoingPolicy(request); assertEquals(false, result); }