/** * Takes a {@link SoapCall} object and invokes the method by reflection. * * @param soapCall contains the SOAP method, SOAP client, and args to be * called * @return the response from the SOAP web service * @throws Exception thrown if calling the operation on the remote service * fails */ protected Object invoke(SoapCall<T> soapCall) throws Exception { Method soapClientMethod = soapCall.getSoapClientMethod(); Object[] soapArgs = soapCall.getSoapArgs(); soapArgs = processSoapArguments(soapClientMethod, soapArgs); return soapClientMethod.invoke(soapCall.getSoapClient(), soapArgs); } }
/** * Takes a {@link SoapCall} object and invokes the method by reflection. * * @param soapCall contains the SOAP method, SOAP client, and args to be * called * @return the response from the SOAP web service * @throws Exception thrown if calling the operation on the remote service * fails */ protected Object invoke(SoapCall<T> soapCall) throws Exception { Method soapClientMethod = soapCall.getSoapClientMethod(); Object[] soapArgs = soapCall.getSoapArgs(); soapArgs = processSoapArguments(soapClientMethod, soapArgs); return soapClientMethod.invoke(soapCall.getSoapClient(), soapArgs); } }
@Test public void testInvoke_lotsOfArgs() throws Exception { Object firstArg = new Object(); Object[] args = new Object[] {firstArg, new Object[] {}, new Object(), new Object()}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("lotsOfArgsCall", Object.class, Object[].class, Object.class, Object.class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertSame(firstArg, result); }
@Test public void testInvoke_emptyCall() throws Exception { Object[] args = null; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("emptyCall")); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertNull(result); }
@Test public void testCall_identityCall() throws Throwable { Object[] args = new Object[] {1L, "2", 3.0d}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("identityCall", Object[].class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(new Object[] {args}); Object result = soapClientHandler.invoke(soapCall); assertSame(args, result); }
@Test public void testCall_exception() throws Throwable { Object[] args = new Object[] {1L, "2", 3.0d}; MockSoapClient mockSoapClient = new MockSoapClient(); when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("throwException", Object[].class)); when(soapCall.getSoapClient()).thenReturn(mockSoapClient); when(soapCall.getSoapArgs()).thenReturn(new Object[] {args}); thrown.expect(InvocationTargetException.class); thrown.expectCause(Matchers.<Exception>is(MockSoapClient.EXCEPTION)); soapClientHandler.invoke(soapCall); }
@Test public void testInvoke_voidCall() throws Exception { Object[] args = new Object[] {"2", 1}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("voidCall", Object[].class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(new Object[] {args}); Object result = soapClientHandler.invoke(soapCall); assertNull(result); }
@Test public void testInvoke_overloadedOneParam() throws Exception { Object[] args = new Object[] {1}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("testOverloaded", int.class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertSame(1, result); }
@Test public void testInvoke_overloadedTwoParams() throws Exception { Object[] args = new Object[] {"moo", "cow"}; when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("testOverloaded", String.class, String.class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(args); Object result = soapClientHandler.invoke(soapCall); assertSame("moo", result); }
@Test public void testCall_null() throws Throwable { when(soapCall.getSoapClientMethod()).thenReturn( MockSoapClient.class.getMethod("identityCall", Object[].class)); when(soapCall.getSoapClient()).thenReturn(new MockSoapClient()); when(soapCall.getSoapArgs()).thenReturn(new Object[] {null}); Object result = soapClientHandler.invoke(soapCall); assertNull(result); }