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