KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > encoding > TestOutputter


1 package test.encoding;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.Constants;
5 import org.apache.axis.Message;
6 import org.apache.axis.MessageContext;
7 import org.apache.axis.server.AxisServer;
8 import org.custommonkey.xmlunit.XMLTestCase;
9
10 /**
11  * Test deserialization of SOAP responses
12  */

13 public class TestOutputter extends XMLTestCase {
14
15     private String JavaDoc header;
16     private String JavaDoc footer;
17     private AxisServer server = new AxisServer();
18
19     public TestOutputter(String JavaDoc name) {
20         this(name, Constants.URI_DEFAULT_SCHEMA_XSI,
21                    Constants.URI_DEFAULT_SCHEMA_XSD);
22     }
23
24     public TestOutputter(String JavaDoc name, String JavaDoc NS_XSI, String JavaDoc NS_XSD) {
25         super(name);
26
27         header =
28             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
29             "<soap:Envelope " +
30               "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
31               "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
32               "xmlns:xsi=\"" + NS_XSI + "\" " +
33               "xmlns:xsd=\"" + NS_XSD + "\">\n" +
34               "<soap:Body>\n" +
35                 "<methodResult xmlns=\"http://tempuri.org/\">\n";
36
37         footer =
38                 "</methodResult>\n" +
39               "</soap:Body>\n" +
40             "</soap:Envelope>";
41     }
42
43     /**
44      * Verify that a given XML deserialized produces the expected result
45      */

46     protected void roundtrip(String JavaDoc data)
47        throws Exception JavaDoc
48     {
49        Message message = new Message(header + data + footer);
50        message.setMessageContext(new MessageContext(server));
51
52        message.getSOAPEnvelope();
53
54        assertXMLEqual(header+data+footer, message.getSOAPPartAsString());
55     }
56
57     public void testString() throws Exception JavaDoc {
58         roundtrip("<result xsi:type=\"xsd:string\">abc</result>");
59     }
60
61     public void testEscapedText() throws Exception JavaDoc {
62         roundtrip("<abc>&lt;&amp;&gt;</abc>");
63     }
64
65     public void testEscapedAttributes() throws Exception JavaDoc {
66         roundtrip("<abc foo=\"&lt;&amp;&gt;\"/>");
67         // roundtrip("<abc foo=\"&lt;&amp;&gt;\"/>");
68
}
69
70     public static void main(String JavaDoc [] args) throws Exception JavaDoc
71     {
72         TestOutputter tester = new TestOutputter("test");
73         tester.testString();
74     }
75 }
76
Popular Tags