FileDocCategorySizeDatePackage
TestFault.javaAPI DocApache Axis 1.43358Sat Apr 22 18:57:26 BST 2006test.soap12

TestFault

public class TestFault extends TestCase
A test of soap 1.2 fault serialization and deserialization.
author
Andras Avar (andras.avar@nokia.com)

Fields Summary
public static final QName
FAULTCODE
public static final QName[]
FAULTSUBCODE
public static final String
FAULTREASON
public static final String
FAULTROLE
public static final String
FAULTNODE
Constructors Summary
public TestFault(String name)

        super(name);
    
Methods Summary
public voidsetUp()

    
public static junit.framework.Testsuite()

        return new TestSuite(TestFault.class);
    
public voidtestFault()


        
    
        // Serialize
        MessageContext msgContext = new MessageContext(new AxisServer());
        msgContext.setSOAPConstants(SOAPConstants.SOAP12_CONSTANTS);
        msgContext.setProperty(Constants.MC_NO_OPERATION_OK, Boolean.TRUE);
        
        SOAPEnvelope msg = new SOAPEnvelope(SOAPConstants.SOAP12_CONSTANTS);

        SOAPFault fault = new SOAPFault(new AxisFault(FAULTCODE, FAULTSUBCODE,
                                                      FAULTREASON, FAULTROLE,
                                                      FAULTNODE, null));

        msg.addBodyElement(fault);
        Writer stringWriter = new StringWriter();
        SerializationContext context = 
                new SerializationContext(stringWriter, msgContext);
        context.setDoMultiRefs(false);
        msg.output(context);
        String msgString = stringWriter.toString();

        // Deserialize and check
        AxisServer server = new AxisServer();
        Message message = new Message(msgString);
        message.setMessageContext(new MessageContext(server));

        SOAPEnvelope envelope = message.getSOAPEnvelope();
        assertNotNull("envelope should not be null", envelope);

        SOAPBodyElement respBody = envelope.getFirstBody();
        assertTrue("respBody should be a SOAPFaultElement", respBody
                        instanceof SOAPFault);
        AxisFault aFault = ((SOAPFault) respBody).getFault();

        assertNotNull("Fault should not be null", aFault);

        assertEquals(FAULTCODE, aFault.getFaultCode());
        assertEquals(FAULTREASON, aFault.getFaultReason());
        assertEquals(FAULTROLE, aFault.getFaultRole());
        assertEquals(FAULTNODE, aFault.getFaultNode());
        QName q[] = aFault.getFaultSubCodes();
        for (int i = 0; i < q.length; i++)
            assertEquals(FAULTSUBCODE[i], q[i]);