FileDocCategorySizeDatePackage
TestSOAPService.javaAPI DocApache Axis 1.416137Sat Apr 22 18:57:28 BST 2006test.jaxrpc

TestSOAPService

public class TestSOAPService extends AJAXRPC

Fields Summary
Constructors Summary
Methods Summary
public voidtestFaultHandlerThrowsJAXRPCException()
Tests to see if we handle the scenario of a handler throwing a runtime exception during the handleFault(...) processing correctly

Expected chain sequence: H0.handleRequest H1.handleRequest H2.handleRequest SOAPFaultException H2.handleFault H1.handleFault throws JAXRPCException

throws
Exception

        SOAPService soapService = new SOAPService();

        // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
        handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new SOAPFaultException(null, "f", "f", new Detail()));
        handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new JAXRPCException());
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
            fail("Expected AxisFault to be thrown");
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
        }
    
public voidtestFaultHandlerThrowsRuntimeException()
Tests to see if we handle the scenario of a handler throwing a runtime exception during the handleFault(...) processing correctly

Expected chain sequence: H0.handleRequest H1.handleRequest H2.handleRequest throws SOAPFaultException H2.handleFault H1.handleFault throws RuntimeException

throws
Exception

        SOAPService soapService = new SOAPService();

        // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
        handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new SOAPFaultException(null, "f", "f", new Detail()));
        handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new RuntimeException());
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
            fail("Expected AxisFault to be thrown");
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
        }
    
public voidtestHandleFaultReturnsFalse()

        SOAPService soapService = new SOAPService();

        // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
        handler2Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new SOAPFaultException(null, "f", "f", new Detail()));
        handler1Config.put("HANDLE_FAULT_RETURN_VALUE", Boolean.FALSE);
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        soapService.invoke(msgContext);
        AAAHandler handlerZero = factory.getHandlers()[0];
        AAAHandler handlerOne = factory.getHandlers()[1];
        AAAHandler handlerTwo = factory.getHandlers()[2];
        assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
        assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
        assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
    
public voidtestPositiveCourseFlow()
All Handlers in Chain return true for handleRequest and handleResponse

* Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest H2.handleRequest H2.handleResponse H1.handleResponse H0.handleResponse

throws
Exception

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        soapService.invoke(new TestMessageContext());
        AAAHandler handlerZero = factory.getHandlers()[0];
        AAAHandler handlerOne = factory.getHandlers()[1];
        AAAHandler handlerTwo = factory.getHandlers()[2];
        assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0);
        assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
        assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
    
public voidtestRequestHandlerReturnsFalse()
Tests scenario where one handler returns false on a call to handleRequest(...).

Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest returns false H1.handleResponse H0.handleResponse

throws
Exception

        SOAPService soapService = new SOAPService();

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO RETURN FALSE
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", Boolean.FALSE);
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        soapService.invoke(msgContext);
        AAAHandler handlerZero = factory.getHandlers()[0];
        AAAHandler handlerOne = factory.getHandlers()[1];
        AAAHandler handlerTwo = factory.getHandlers()[2];
        assertHandlerRuntime("handlerZero", handlerZero, 1, 1, 0);
        assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
        assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
    
public voidtestRequestHandlerThrowsJAXRPCException()

throws
Exception

        SOAPService soapService = new SOAPService();

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new JAXRPCException());
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
        }
    
public voidtestRequestHandlerThrowsRuntimeException()

        SOAPService soapService = new SOAPService();

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new RuntimeException());
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
        }
    
public voidtestRequestHandlerThrowsSFE()

throws
Exception

        SOAPService soapService = new SOAPService();

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new SOAPFaultException(null, "f", "f", new Detail()));
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        soapService.invoke(msgContext);
        AAAHandler handlerZero = factory.getHandlers()[0];
        AAAHandler handlerOne = factory.getHandlers()[1];
        AAAHandler handlerTwo = factory.getHandlers()[2];
        assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 1);
        assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
        assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
    
public voidtestResponseHandlerReturnsFalse()

        SOAPService soapService = new SOAPService();

        // SETUP THE 3rd HANDLER IN THE CHAIN TO RETURN FALSE on handleResponse
        handler2Config.put("HANDLE_RESPONSE_RETURN_VALUE", Boolean.FALSE);
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        soapService.invoke(msgContext);
        AAAHandler handlerZero = factory.getHandlers()[0];
        AAAHandler handlerOne = factory.getHandlers()[1];
        AAAHandler handlerTwo = factory.getHandlers()[2];
        assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
        assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 0);
        assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
    
public voidtestResponseHandlerThrowsJAXRPCException()

        SOAPService soapService = new SOAPService();

        // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW JAXRPCException on handleResponse
        handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
                new JAXRPCException());
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
            fail("Expected AxisFault to be thrown");
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
        }
    
public voidtestResponseHandlerThrowsRuntimeException()

        SOAPService soapService = new SOAPService();

        // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW RuntimeException on handleResponse
        handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
                new RuntimeException());
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
            fail("Expected AxisFault to be thrown");
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 0);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 1, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 1, 0);
        }
    
public voidtestServiceObjectThrowsAxisFault()
Tests scenario where service object throws Axis Fault.

Expected chain sequence: H0.handleRequest H1.handleRequest H2.handleRequest ServiceObject.invoke() throws AxisFault H2.handleFault H1.handleFault H0.handleFault

throws
Exception

        Handler serviceHandler = new MockServiceHandler();
        SOAPService soapService = new SOAPService(null, null, serviceHandler);
        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.init();
        MessageContext msgContext = new TestMessageContext();
        try {
            soapService.invoke(msgContext);
            fail("Expected AxisFault to be thrown");
        } catch (AxisFault e) {
            AAAHandler handlerZero = factory.getHandlers()[0];
            AAAHandler handlerOne = factory.getHandlers()[1];
            AAAHandler handlerTwo = factory.getHandlers()[2];
            assertHandlerRuntime("handlerZero", handlerZero, 1, 0, 1);
            assertHandlerRuntime("handlerOne", handlerOne, 1, 0, 1);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 1);
        }