FileDocCategorySizeDatePackage
TestSOAPFaultException.javaAPI DocApache Axis 1.47456Sat Apr 22 18:57:28 BST 2006test.faults

TestSOAPFaultException

public class TestSOAPFaultException extends TestCase
Tests for the conversion of a JAX-RPC SOAPFaultException to an AxisFault
author
Thomas Bayer (bayer@oio.de)

Fields Summary
private static final org.apache.axis.soap.SOAPConstants
soapConsts
private static final QName
QNAME_FAULT_SERVER_USER
private static final String
SERVICE_NAME
Constructors Summary
public TestSOAPFaultException()
A construktor is needed for instanciation cause this class is also used as service implementation


                         
      
        super("TestSOAPFaultException");
    
public TestSOAPFaultException(String s)

        super(s);
    
Methods Summary
private voidcheckDetailAgainstTestDetail(org.apache.axis.AxisFault axisFault)
Checks if the AxisFault contains the expected detail elements

param
axisFault

        Element[] details = axisFault.getFaultDetails();

        assertEquals("wrong name for detail element", "MyDetails", details[0].getNodeName());
        assertEquals("wrong node value for detail element", "hossa", ((Text) details[0].getChildNodes().item(0)).getData());
        assertEquals("wrong name for foo element", "foo", details[1].getNodeName());

        boolean found = false;
        NodeList childs = details[1].getChildNodes();
        for (int i = 0; i < childs.getLength(); i++) {
            if ("baz".equals(childs.item(i).getNodeName()))
                found = true;
        }
        assertTrue("subelement baz not found in details", found);
    
public voiddoSth()
Service method which is called with an axis engine. Its used to test if a service can throw an SOAPFaultException and all the information as faultcode and faultactor is passed to the caller

throws
Exception

        throw new SOAPFaultException(QNAME_FAULT_SERVER_USER, "MyFaultString", "http://myactor", getTestDetail());
    
private javax.xml.soap.DetailgetTestDetail()
Produces a Detail object filled with test data

return
a Detail object filled with test data

        Detail detail = null;
        try {
            detail = SOAPFactory.newInstance().createDetail();
            detail.addChildElement("MyDetails").addTextNode("hossa");
            detail.addChildElement("foo").addChildElement("baz");
        } catch (SOAPException e) {
            fail("Can't create detail");
        }
        return detail;
    
public static junit.framework.Testsuite()

        return new TestSuite(TestSOAPFaultException.class);
    
public voidtestDefaults()
Tests the defaults generated from a SOAPFaultException

        SOAPFaultException soapFaultException = new SOAPFaultException(null, null, null, null);

        AxisFault axisFault = AxisFault.makeFault(soapFaultException);

        assertEquals(QNAME_FAULT_SERVER_USER, axisFault.getFaultCode());
        assertNotNull(axisFault.getFaultString());
    
public voidtestDetails()
Tests if SOAP fault details are passed to AxisFault objects

        SOAPFaultException soapFaultException = new SOAPFaultException(QNAME_FAULT_SERVER_USER, "MyFaultString", "http://myactor", getTestDetail());

        AxisFault axisFault = AxisFault.makeFault(soapFaultException);

        assertNotNull(axisFault.getFaultDetails());

        checkDetailAgainstTestDetail(axisFault);
    
public voidtestMakeFaultOutOfSOAPFaultException()
Tests if an AxisFault is initialized with the values from a SOAPFaultException


        QName faultcode = new QName(soapConsts.getEnvelopeURI(), "Server.MySubClass");

        SOAPFaultException soapFaultException = new SOAPFaultException(faultcode, "MyFaultString", "http://myactor", null);

        AxisFault axisFault = AxisFault.makeFault(soapFaultException);

        assertEquals(faultcode, axisFault.getFaultCode());
    
public voidtestThrowingSOAPFaultExceptionFromServiceMethod()
Tests if a SOAPFaultException can be thrown from within a service method and the faultcode, faultstring and detail are passed to the AxisFault object.

throws
Exception


        WSDDDeployment conf = new WSDDDeployment();

        WSDDService service = new WSDDService();
        service.setName(SERVICE_NAME);
        service.setProviderQName(new QName(WSDDConstants.URI_WSDD_JAVA, "RPC"));
        service.setParameter("className", this.getClass().getName());
        service.setParameter("allowedMethods", "doSth");
        service.deployToRegistry(conf);

        AxisServer engine = new AxisServer(conf);

        LocalTransport transport = new LocalTransport(engine);
        transport.setRemoteService(SERVICE_NAME);

        // create messageContext
        MessageContext mc = new MessageContext(engine);
        mc.setService((SOAPService) service.getInstance(conf));
        mc.setProperty(MessageContext.TRANS_URL, "local");

        // create SOAP envelope 
        SOAPEnvelope env = new SOAPEnvelope();
        SOAPBody body = (SOAPBody) env.getBody();
        body.addChildElement(new RPCElement("doSth"));
        Message reqMsg = new Message(env);
        mc.setRequestMessage(reqMsg);

        // invoke the engine and test if the fault contains everything as         
        try {
            engine.invoke(mc);
        } catch (AxisFault af) {
            checkDetailAgainstTestDetail(af);
        }