/** * Tests the API using the supplied tester instance. First the API is tested with non-null * parameters, then with null parameters and finally the failure of the API is tested. * * @param inTester the tester to test the API invocation. * @param <R> the return type of the API. * @throws Exception if there were unexpected errors */ private static <R> void testAPI(final WSTester<R> inTester) throws Exception { // Test a regular invocation. R value = inTester.setReturnValue(false); verifyEquals(value, inTester.invokeApi(false)); inTester.verifyInputParams(false); // Test invocation with nulls resetServiceParameters(); value = inTester.setReturnValue(true); verifyEquals(value, inTester.invokeApi(true)); inTester.verifyInputParams(true); // Test a failure resetServiceParameters(); I18NException failure = new I18NException(new I18NMessage0P(Messages.LOGGER, "test")); getMockSAService().setFailure(failure); inTester.setReturnValue(false); ConnectionException e = new ExpectedFailure<ConnectionException>() { @Override protected void run() throws Exception { inTester.invokeApi(false); } }.getException(); assertNotNull(e.getCause()); assertEquals(failure, e.getCause()); // Verify that input parameters were received even when failure occured. inTester.verifyInputParams(false); // Test service interruption verifyInvocationCannotBeInterrupted(inTester); }
private ConnectionException parseDetail(XmlInputStream xin, QName faultCode, String faultstring) throws IOException, ConnectionException { ConnectionException e; xin.nextTag(); // consume <detail> xin.peekTag(); // move to the body of <detail> if (xin.getEventType() == XmlInputStream.END_TAG) { // check for empty detail element throw new SoapFaultException(faultCode, faultstring); } TypeInfo info = new TypeInfo(null, null, null, null, 1, 1, true); try { e = (ConnectionException) typeMapper.readObject(xin, info, ConnectionException.class); if (e instanceof SoapFaultException) { ((SoapFaultException) e).setFaultCode(faultCode); if (faultstring != null && (faultstring.contains("Session timed out") || faultstring.contains("Session not found") || faultstring.contains("Illegal Session")) && "INVALID_SESSION_ID".equals(faultCode.getLocalPart())) { e = new SessionTimedOutException(faultstring, e); } } } catch (ConnectionException ce) { throw new ConnectionException( "Failed to parse detail: " + xin + " due to: " + ce, ce.getCause()); } xin.nextTag(); // consume </detail> if (!"detail".equals(xin.getName())) { throw new ConnectionException("Failed to find </detail>"); } return e; }