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

TestAxisClient

public class TestAxisClient extends AJAXRPC
author
Guillaume Sauthier

Fields Summary
Constructors Summary
Methods Summary
private voidaddFaultTransport(org.apache.axis.client.AxisClient client)
Configure a transport handler that simulate a Fault on server-side

param
client AxisClient


        FileProvider config = (FileProvider) client.getConfig();

        WSDDDeployment depl = config.getDeployment();
        if (depl == null) {
            depl = new WSDDDeployment();
        }
        WSDDTransport trans = new AxisFaultWSDDTransport();
        depl.deployTransport(trans);
        
    
protected voidsetUp()

        super.setUp();
    
protected voidtearDown()

        super.tearDown();
    
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 H2.handleFault H1.handleFault throws JAXRPCException

throws
Exception

        handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new JAXRPCException());

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        Handler serviceHandler = new MockServiceHandler();
        SOAPService soapService = new SOAPService(null, serviceHandler, null);
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();        
        addFaultTransport(client);

        MessageContext context = new TestMessageContext(client);
        context.setTransportName("faulter");
        context.setService(soapService);

        try {
            client.invoke(context);
            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, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0);
        }
    
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 H2.handleFault H1.handleFault throws RuntimeException

throws
Exception

        // SETUP THE LAST HANDLER IN THE REQUEST CHAIN TO THROW SOAPFaultException
        handler1Config.put("HANDLE_FAULT_RETURN_VALUE", new RuntimeException());

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        Handler serviceHandler = new MockServiceHandler();
        SOAPService soapService = new SOAPService(null, serviceHandler, null);
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();        
        addFaultTransport(client);

        MessageContext context = new TestMessageContext(client);
        context.setTransportName("faulter");
        context.setService(soapService);

        try {
            client.invoke(context);
            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, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0);
        }
    
public voidtestHandleFaultReturnsFalse()
Tests scenario where one handler returns false on a call to handleFault(...).

Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest H2.handleRequest H2.handleFault H1.handleFault return false

throws
Exception

        // SETUP A MOCK SERVICE THAT SIMULATE A SOAPFAULT THROWN BY ENDPOINT
        handler1Config.put("HANDLE_FAULT_RETURN_VALUE", Boolean.FALSE);

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();        
        addFaultTransport(client);

        MessageContext context = new TestMessageContext(client);
        context.setTransportName("faulter");
        context.setService(soapService);

        try {
            client.invoke(context);
            fail("Expecting an AxisFault");
        } catch (AxisFault f) {
            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, 0, 0);
        }
    
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.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);
        client.invoke(context);

        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

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO RETURN FALSE
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE", Boolean.FALSE);

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);
        client.invoke(context);

        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()
Tests scenario where one handler throws a JAXRPCException to handleRequest(...).

Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest throws JAXRPCException

throws
Exception

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new JAXRPCException());

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);
        
        try {
            client.invoke(context);
        } 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()
Tests scenario where one handler throws a RuntimeException to handleRequest(...).

Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest throws JAXRPCException

throws
Exception

        // SETUP THE 2nd HANDLER IN THE REQUEST CHAIN TO THROW JAXRPCException
        handler1Config.put("HANDLE_REQUEST_RETURN_VALUE",
                new RuntimeException());

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);

        try {
            client.invoke(context);
            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, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 0, 0, 0);
        }
    
public voidtestResponseHandlerReturnsFalse()
Tests scenario where one handler returns false on a call to handleResponse(...).

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

throws
Exception

        // SETUP THE 3rd HANDLER IN THE CHAIN TO RETURN FALSE on handleResponse
        handler2Config.put("HANDLE_RESPONSE_RETURN_VALUE", Boolean.FALSE);

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);

        client.invoke(context);
        
        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()
Tests scenario where one handler throws JAXRPCException on a call to handleResponse(...).

Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest H2.handleRequest H2.handleResponse H1.handlerResponse throws JAXRPCException

throws
Exception

        // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW JAXRPCException on handleResponse
        handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
                new JAXRPCException());

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);

        try {
            client.invoke(context);
            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()
Tests scenario where one handler throws RuntimeException on a call to handleResponse(...).

Expected Chain invocation sequence looks like..... H0.handleRequest H1.handleRequest H2.handleRequest H2.handleResponse H1.handlerResponse throws RuntimeException

throws
Exception

        // SETUP THE 2nd HANDLER IN THE CHAIN TO THROW RuntimeException on handleResponse
        handler1Config.put("HANDLE_RESPONSE_RETURN_VALUE",
                new RuntimeException());

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        SOAPService soapService = new SOAPService();
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();
        MessageContext context = new TestMessageContext(client);
        context.setTransportName("local");
        context.setService(soapService);

        try {
            client.invoke(context);
            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

        TestHandlerInfoChainFactory factory = buildInfoChainFactory();
        Handler serviceHandler = new MockServiceHandler();
        SOAPService soapService = new SOAPService(null, serviceHandler, null);
        soapService.setOption(Constants.ATTR_HANDLERINFOCHAIN, factory);
        soapService.setOption(Call.WSDL_SERVICE, new Service());
        soapService.setOption(Call.WSDL_PORT_NAME, new QName("Fake"));
        soapService.init();
        AxisClient client = new AxisClient();        
        addFaultTransport(client);

        MessageContext context = new TestMessageContext(client);
        context.setTransportName("faulter");
        context.setService(soapService);

        try {
            client.invoke(context);
            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, 0);
            assertHandlerRuntime("handlerTwo", handlerTwo, 1, 0, 0);
        }