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

FaultDecode

public class FaultDecode extends TestCase
This class tests Fault deserialization.
author
Mark Roder
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
public static final String
FAULT_CODE
public static final String
FAULT_STRING
public static final String
DETAIL_ENTRY_TEXT
Constructors Summary
public FaultDecode(String name)

    
       
        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        FaultDecode tester = new FaultDecode("test");
        TestRunner runner = new TestRunner();
        runner.doRun(tester.suite(), false);
    
public static junit.framework.Testsuite()

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

        String messageText = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
            + "<soap:Header>"
            + ""
            + "</soap:Header> "
            + "<soap:Body>  "
            + "     <soap:Fault>"
            + "          <faultcode>" + FAULT_CODE + "</faultcode>"
            + "          <faultstring>" + FAULT_STRING + "</faultstring>"
            + "          <detail><d1>" + DETAIL_ENTRY_TEXT + "</d1></detail>"
            + "     </soap:Fault>"
            + "</soap:Body>"
            + "</soap:Envelope>";

        AxisServer server = new AxisServer();
        Message message = new Message(messageText);
        message.setMessageContext(new MessageContext(server));

        SOAPEnvelope envelope = (SOAPEnvelope) message.getSOAPEnvelope();
        assertNotNull("envelope", 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);
        
        QName faultCode = aFault.getFaultCode();
        assertNotNull("faultCode should not be null", faultCode);
        assertEquals("faultCode should match",
                     faultCode.getLocalPart(), 
                     "Some.FaultCode");
        
        String faultString = aFault.getFaultString();
        assertNotNull("faultString should not be null", faultString);
        assertEquals("faultString should match", faultString,
                     FAULT_STRING);
        
        Element [] details = aFault.getFaultDetails();
        assertNotNull("faultDetails should not be null", details);
        assertEquals("details should have exactly one element", details.length, 
                     1);
        
        Element el = details[0];
        assertEquals("detail entry tag name should match",
                     el.getLocalName(), "d1");
        
        Text text = (Text)el.getFirstChild();
        assertEquals("detail entry string should match",
                     text.getData(), DETAIL_ENTRY_TEXT);