@Test public void testCheckPolicyException() { try { AdapterComponentPolicyEngineImpl sut = new AdapterComponentPolicyEngineImpl() { @Override protected Log createLogger() { return mockLog; } @Override protected AdapterPolicyEngineOrchestratorImpl getAdapterPolicyEngineOrchestratorImpl() { return mockAdapterPolicyEngineOrchestratorImpl; } @Override protected void loadAssertion(AssertionType assertion, WebServiceContext wsContext) throws Exception { throw new IllegalArgumentException("Forced error."); } }; context.checking( new Expectations() { { allowing(mockLog).debug(with(aNonNull(String.class))); oneOf(mockLog) .error( with(aNonNull(String.class)), with(aNonNull(IllegalArgumentException.class))); } }); 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()); } }
@Test public void testCheckPolicyHappy() { try { AdapterComponentPolicyEngineImpl sut = new AdapterComponentPolicyEngineImpl() { @Override protected Log createLogger() { return mockLog; } @Override protected AdapterPolicyEngineOrchestratorImpl getAdapterPolicyEngineOrchestratorImpl() { return mockAdapterPolicyEngineOrchestratorImpl; } @Override protected void loadAssertion(AssertionType assertion, WebServiceContext wsContext) throws Exception {} }; context.checking( new Expectations() { { allowing(mockLog).debug(with(aNonNull(String.class))); 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()); } }