KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > utils > TestNSStack


1 package test.utils;
2
3 import junit.framework.Test;
4 import junit.framework.TestSuite;
5 import org.apache.axis.encoding.DeserializationContext;
6 import org.apache.axis.AxisProperties;
7 import org.apache.axis.AxisEngine;
8 import org.custommonkey.xmlunit.Diff;
9 import org.xml.sax.InputSource JavaDoc;
10 import test.AxisTestBase;
11
12 import java.io.StringReader JavaDoc;
13
14 public class TestNSStack extends AxisTestBase
15 {
16     public TestNSStack(String JavaDoc name) {
17         super(name);
18     }
19
20     public static Test suite() {
21         return new TestSuite(TestNSStack.class);
22     }
23
24     protected void setUp() throws Exception JavaDoc {
25         AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"false");
26     }
27     
28     protected void tearDown() throws Exception JavaDoc {
29         AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"true");
30     }
31
32     String JavaDoc prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
33                     "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">";
34     String JavaDoc suffix = "</soapenv:Envelope>";
35
36     String JavaDoc m1 = "<soapenv:Body wsu:id=\"id-23412344\"\n" +
37                     " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-2004\">\n" +
38                     " <somepfx:SomeTag id=\"e0sdoaeckrpd\" xmlns=\"ns:uri:one\"\n" +
39                     " xmlns:somepfx=\"ns:uri:one\">hello</somepfx:SomeTag>\n" +
40                     " </soapenv:Body>";
41     String JavaDoc m2 = "<soapenv:Body>" +
42                     " <ns1:MyTag xmlns=\"http://ns1.com\" xmlns:ns1=\"http://ns1.com\">SomeText</ns1:MyTag>" +
43                     " </soapenv:Body>";
44
45     public void testNSStack1() throws Exception JavaDoc
46     {
47         String JavaDoc msg = prefix+m1+suffix;
48         StringReader JavaDoc strReader = new StringReader JavaDoc(msg);
49         DeserializationContext dser = new DeserializationContext(
50                 new InputSource JavaDoc(strReader), null,
51                 org.apache.axis.Message.REQUEST);
52         dser.parse();
53         org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
54         String JavaDoc xml = env.toString();
55         assertXMLIdentical("NSStack invalidated XML canonicalization",
56                 new Diff(msg, xml), true);
57     }
58
59     public void testNSStack2() throws Exception JavaDoc
60     {
61         String JavaDoc msg = prefix+m2+suffix;
62         StringReader JavaDoc strReader = new StringReader JavaDoc(msg);
63         DeserializationContext dser = new DeserializationContext(
64                 new InputSource JavaDoc(strReader), null,
65                 org.apache.axis.Message.REQUEST);
66         dser.parse();
67         org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
68         String JavaDoc xml = env.toString();
69         assertXMLIdentical("NSStack invalidated XML canonicalization",
70                 new Diff(msg, xml), true);
71     }
72
73     public static void main(String JavaDoc[] args) throws Exception JavaDoc
74     {
75         TestNSStack test = new TestNSStack("TestNSStack");
76         test.testNSStack1();
77         test.testNSStack2();
78     }
79 }
80
Popular Tags