File: TestNSStack.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (92 lines) | stat: -rw-r--r-- 3,396 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package test.utils;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.axis.encoding.DeserializationContext;
import org.apache.axis.AxisProperties;
import org.apache.axis.AxisEngine;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.xml.sax.InputSource;
import test.AxisTestBase;

import java.io.StringReader;

public class TestNSStack extends AxisTestBase
{
    public TestNSStack(String name) {
        super(name);
    }

    public static Test suite() {
        return new TestSuite(TestNSStack.class);
    }

    protected void setUp() throws Exception {
        AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"false");
    }

    protected void tearDown() throws Exception {
        AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"true");
    }

    String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                    "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    String suffix = "</soapenv:Envelope>";

    String m1 = "<soapenv:Body wsu:id=\"id-23412344\"\n" +
                    "    xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-2004\">\n" +
                    "  <somepfx:SomeTag id=\"e0sdoaeckrpd\" xmlns=\"ns:uri:one\"\n" +
                    "    xmlns:somepfx=\"ns:uri:one\">hello</somepfx:SomeTag>\n" +
                    "  </soapenv:Body>";
    String m2 = "<soapenv:Body>" +
                    "       <ns1:MyTag xmlns=\"http://ns1.com\" xmlns:ns1=\"http://ns1.com\">SomeText</ns1:MyTag>" +
                    "   </soapenv:Body>";

    public void testNSStack1() throws Exception
    {
        String msg = prefix+m1+suffix;
        StringReader strReader = new StringReader(msg);
        DeserializationContext dser = new DeserializationContext(
                new InputSource(strReader), null,
                org.apache.axis.Message.REQUEST);
        dser.parse();
        org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
        String xml = env.toString();
        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
        XMLUnit.setIgnoreWhitespace(true);
        try {
            assertXMLIdentical("NSStack invalidated XML canonicalization",
                    new Diff(msg, xml), true);
        } finally {
            XMLUnit.setIgnoreWhitespace(oldIgnore);
        }
    }

    public void testNSStack2() throws Exception
    {
        String msg = prefix+m2+suffix;
        StringReader strReader = new StringReader(msg);
        DeserializationContext dser = new DeserializationContext(
                new InputSource(strReader), null,
                org.apache.axis.Message.REQUEST);
        dser.parse();
        org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope();
        String xml = env.toString();
        boolean oldIgnore = XMLUnit.getIgnoreWhitespace();
        XMLUnit.setIgnoreWhitespace(true);
        try {
            assertXMLIdentical("NSStack invalidated XML canonicalization",
                    new Diff(msg, xml), true);
        } finally {
            XMLUnit.setIgnoreWhitespace(oldIgnore);
        }
    }

    public static void main(String[] args) throws Exception
    {
        TestNSStack test = new TestNSStack("TestNSStack");
        test.testNSStack1();
        test.testNSStack2();
    }
}