AdapterComponentPolicyEngineImpl { public gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPolicyResponseType checkPolicy( gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPolicyRequestType checkPolicyRequest, WebServiceContext context) { CheckPolicyResponseType checkPolicyResp; AdapterPolicyEngineOrchestratorImpl oOrchestrator = getAdapterPolicyEngineOrchestratorImpl(); try { AssertionType assertion = checkPolicyRequest.getAssertion(); loadAssertion(assertion, context); checkPolicyResp = oOrchestrator.checkPolicy(checkPolicyRequest, assertion); } catch (Exception e) { String sMessage = "Error occurred calling AdapterPolicyEngineOrchestratorLib.checkPolicy. Error: " + e.getMessage(); LOG.error(sMessage, e); throw new RuntimeException(sMessage, e); } return checkPolicyResp; }  gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPolicyResponseType checkPolicy(
            gov.hhs.fha.nhinc.common.nhinccommonadapter.CheckPolicyRequestType checkPolicyRequest,
            WebServiceContext context);  }
@Test public void testCheckPolicyHappy() { try { AdapterComponentPolicyEngineImpl sut = new AdapterComponentPolicyEngineImpl() { @Override protected AdapterPolicyEngineOrchestratorImpl getAdapterPolicyEngineOrchestratorImpl() { return mockAdapterPolicyEngineOrchestratorImpl; } @Override protected void loadAssertion(AssertionType assertion, WebServiceContext wsContext) throws Exception { } }; context.checking(new Expectations() { { oneOf(mockAdapterPolicyEngineOrchestratorImpl).checkPolicy( with(aNonNull(CheckPolicyRequestType.class)), with(aNonNull(AssertionType.class))); } }); CheckPolicyRequestType request = new CheckPolicyRequestType(); AssertionType assertion = new AssertionType(); request.setAssertion(assertion); CheckPolicyResponseType response = sut.checkPolicy(request, mockWebServiceContext); assertNotNull("CheckPolicyResponseType was null", response); } catch (Throwable t) { System.out.println("Error running testCheckPolicyHappy: " + t.getMessage()); t.printStackTrace(); fail("Error running testCheckPolicyHappy: " + t.getMessage()); } }
@Test public void testCheckPolicyException() { try { AdapterComponentPolicyEngineImpl sut = new AdapterComponentPolicyEngineImpl() { @Override protected AdapterPolicyEngineOrchestratorImpl getAdapterPolicyEngineOrchestratorImpl() { return mockAdapterPolicyEngineOrchestratorImpl; } @Override protected void loadAssertion(AssertionType assertion, WebServiceContext wsContext) throws Exception { throw new IllegalArgumentException("Forced error."); } }; CheckPolicyRequestType request = new CheckPolicyRequestType(); sut.checkPolicy(request, mockWebServiceContext); fail("Should have had exception."); } catch (RuntimeException e) { assertEquals("Exception message", "Error occurred calling AdapterPolicyEngineOrchestratorLib.checkPolicy. Error: Forced error.", e.getMessage()); } catch (Throwable t) { System.out.println("Error running testCheckPolicyException: " + t.getMessage()); t.printStackTrace(); fail("Error running testCheckPolicyException: " + t.getMessage()); } }