@Before public void setUp() { MockitoAnnotations.initMocks(this); soapServiceClient = new TestSoapServiceClient(soapClientHandler, soapClient); }
@Test @SuppressWarnings("unchecked") public void testCallSoapClient_exception() { RemoteCallReturn expectedRemoteCallReturn = new RemoteCallReturn.Builder().withException(MockSoapClient.EXCEPTION).build(); SoapCall<Object> soapCall = Mockito.mock(SoapCall.class); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(expectedRemoteCallReturn); RemoteCallReturn testRemoteCallReturn = soapServiceClient.callSoapClient(soapCall); assertSame(MockSoapClient.EXCEPTION, testRemoteCallReturn.getException()); }
@Test public void testInvoke_soapClientMethod() throws Throwable { Object returnValue = new Object(); RemoteCallReturn callReturn = new RemoteCallReturn.Builder().withReturnValue(returnValue).build(); Method identityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] arg = new String[] {"arg1", "arg2"}; Object[] args = new Object[] {arg}; SoapCall<Object> soapCall = new SoapCall<Object>(identityCallMethod, soapClient, args); when(soapClientHandler.getSoapClientMethod(soapClient, identityCallMethod)) .thenReturn(identityCallMethod); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(callReturn); Object result = soapServiceClient.invoke(null, identityCallMethod, args); assertEquals(returnValue, result); }
@Test public void testGetSoapClientHandler() { assertEquals(soapClientHandler, soapServiceClient.getSoapClientHandler()); }
@Test public void testGetSoapClient() { assertEquals(soapClient, soapServiceClient.getSoapClient()); }
@Test public void testUnwrapRemoteCallReturn_exception() throws Throwable { RemoteCallReturn remoteCallReturn = new RemoteCallReturn.Builder().withException(new NoSuchMethodException()).build(); thrown.expect(NoSuchMethodException.class); soapServiceClient.unwrapRemoteCallReturn(remoteCallReturn); }
@Test public void testHandleException() { Exception expectedException = new NoSuchMethodException(); assertEquals(expectedException, soapServiceClient.handleException(expectedException)); }
@Test public void testInvoke_serviceClientSubclassMethod() throws Throwable { soapServiceClient.invoke(null, TestSoapServiceClient.class.getMethod("doSomething", Object.class), new Object[] {""}); }
@Test public void testSetEndpointAddress() { String expectedEndpointAddress = "endpoint"; soapServiceClient.setEndpointAddress(expectedEndpointAddress); verify(soapClientHandler).setEndpointAddress(soapClient, expectedEndpointAddress); }
@Test public void testInvoke_soapClientMethodAuthenticationException() throws Throwable { Method indentityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] args = new String[] {"arg1", "arg2"}; soapServiceClient.throwAuthException = true; thrown.expect(Matchers.<Exception>equalTo(TestSoapServiceClient.AUTH_EXCEPTION)); soapServiceClient.invoke(null, indentityCallMethod, args); }
@Test public void testCreateSoapCall() throws SecurityException, NoSuchMethodException { Method indentityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] args = new String[] {"arg1", "arg2"}; SoapCall<Object> expectedSoapCall = new SoapCall<Object>(indentityCallMethod, soapClient, args); SoapCall<Object> soapCall = soapServiceClient.createSoapCall(indentityCallMethod, args); assertEquals(expectedSoapCall, soapCall); }
@Test public void testUnwrapRemoteCallReturn_successful() throws Throwable { Object expectedReturnValue = "return"; RemoteCallReturn remoteCallReturn = new RemoteCallReturn.Builder().withReturnValue(expectedReturnValue).build(); assertEquals(expectedReturnValue, soapServiceClient.unwrapRemoteCallReturn(remoteCallReturn)); }
@Test public void testInvoke_soapClientMethodNoSuchmethodException() throws Throwable { Method indentityCallMethod = MockSoapClient.class.getMethod("identityCall", Object[].class); Object[] args = new String[] {"arg1", "arg2"}; when(soapClientHandler.getSoapClientMethod(soapClient, indentityCallMethod)) .thenThrow(new NoSuchMethodException()); thrown.expect(NoSuchMethodException.class); soapServiceClient.invoke(null, indentityCallMethod, args); }
@Test public void testInvoke_serviceClientMethod() throws Throwable { String endpointAddress = "http://test.com"; soapServiceClient.invoke(null, SoapServiceClient.class.getMethod("setEndpointAddress", String.class), new Object[] {endpointAddress}); verify(soapClientHandler).setEndpointAddress(soapClient, endpointAddress); }
@Test @SuppressWarnings("unchecked") public void testCallSoapClient() throws Throwable { RemoteCallReturn expectedRemoteCallReturn = new RemoteCallReturn.Builder().build(); SoapCall<Object> soapCall = Mockito.mock(SoapCall.class); when(soapClientHandler.invokeSoapCall(soapCall)).thenReturn(expectedRemoteCallReturn); RemoteCallReturn remoteCallReturn = soapServiceClient.callSoapClient(soapCall); assertSame(expectedRemoteCallReturn, remoteCallReturn); }