FileDocCategorySizeDatePackage
TestDOM.javaAPI DocApache Axis 1.47268Sat Apr 22 18:57:28 BST 2006test.encoding

TestDOM

public class TestDOM extends org.custommonkey.xmlunit.XMLTestCase
Verify that deserialization actually can cause the soap service to be set...

Fields Summary
private String
header
private String
request1
private String
request2
private String
footer
Constructors Summary
public TestDOM(String name)

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

        TestDOM tester = new TestDOM("TestDOM");
        tester.testAttributes();
        tester.testHeaders();
        tester.testNodeWithAttribute();
        tester.testEmptyNode();
        tester.testDOM();
    
public voidtestAttributes()
Test for Bug 7132

       AxisEngine engine = new AxisServer();
       engine.init();
       MessageContext msgContext = new MessageContext(engine);
       msgContext.setHighFidelity(true);
       String request = header + request2 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);
       SOAPEnvelope envelope = message.getSOAPEnvelope();
       SOAPBodyElement bodyElement = (SOAPBodyElement)envelope.getBodyElements().elementAt(0);
       MessageElement me = (MessageElement) bodyElement.getChildren().get(0);
       org.xml.sax.Attributes atts = me.getCompleteAttributes();
       assertTrue(atts.getLength()==2);
    
public voidtestDOM()


         

       // setup
       AxisEngine engine = new AxisServer();
       engine.init();
       MessageContext msgContext = new MessageContext(engine);
       msgContext.setHighFidelity(true);
       String request = header + request1 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);

       // Now completely round trip it
       message.getSOAPEnvelope();
       // Element dom = message.getAsDOM();
       String result = message.getSOAPPartAsString();

       assertXMLEqual("Request is not the same as the result.", request, result);
    
public voidtestDOM2()

        // Simulate receiving a signed message.
        //
        String xml1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
            "  <soapenv:Body>\n";
        String xml2 = "    <SASLResponse xmlns=\"urn:liberty:sa:2004-04\">\n" +
            "      <Status code=\"OK\" comment=\"Authenticated\"/>\n" +
            "    </SASLResponse>\n";
        String xml3 =
            "  </soapenv:Body>\n" +
            "</soapenv:Envelope>";

        DeserializationContext ctx = new DeserializationContext(new InputSource(new StringReader(xml1 + xml2 + xml3)), null, "response");
        ctx.parse();

        SOAPEnvelope env = ctx.getEnvelope();
        SOAPBody body = (SOAPBody) env.getBody();

        // I am using the body child as my "token".  The basic idea is that
        // this element must be serialized _exactly_ as it was received.
        MessageElement elt = (MessageElement) body.getFirstChild();
        assertTrue(!elt.isDirty());

        StringWriter writer = new StringWriter();
        SerializationContext serializeContext = new SerializationContext(writer, null);
        serializeContext.setSendDecl(false);
        elt.output(serializeContext);
        writer.close();

        assertXMLIdentical("Deserialization invalidated XML",
                new Diff(xml2, writer.getBuffer().toString()), true);
    
public voidtestEmptyNode()

        SOAPBodyElement body = new SOAPBodyElement(XMLUtils.newDocument().createElementNS(null,"tmp"));
        assertXMLEqual("<tmp/>",body.toString());
    
public voidtestHeaders()

       AxisEngine engine = new AxisServer();
       engine.init();
       MessageContext msgContext = new MessageContext(engine);
       msgContext.setHighFidelity(true);
        String request = header + request1 + footer;
       Message message = new Message(request);
       message.setMessageContext(msgContext);

       // Now completely round trip it
       SOAPEnvelope envelope = message.getSOAPEnvelope();
       envelope.addHeader(new SOAPHeaderElement("foo1", "foo1"));
       envelope.addHeader(new SOAPHeaderElement("foo2", "foo2"));
       envelope.addHeader(new SOAPHeaderElement("foo3", "foo3"));
       String result = message.getSOAPPartAsString();

       assertTrue(result.indexOf("foo1")!=-1);
       assertTrue(result.indexOf("foo2")!=-1);
       assertTrue(result.indexOf("foo3")!=-1);

       Message message2 = new Message(result);
       message2.setMessageContext(msgContext);
       message2.getSOAPEnvelope();
       String result2 = message2.getSOAPPartAsString();

       assertTrue(result2.indexOf("foo1")!=-1);
       assertTrue(result2.indexOf("foo2")!=-1);
       assertTrue(result2.indexOf("foo3")!=-1);
    
public voidtestNodeWithAttribute()

        org.w3c.dom.Element element = XMLUtils.newDocument().createElementNS(null,"tmp");
        element.setAttributeNS(null,"attrib", "foo");
        SOAPBodyElement body = new SOAPBodyElement(element);
        assertXMLEqual("<tmp attrib=\"foo\"/>",body.toString());