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 ; 10 import test.AxisTestBase; 11 12 import java.io.StringReader ; 13 14 public class TestNSStack extends AxisTestBase 15 { 16 public TestNSStack(String 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 { 25 AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"false"); 26 } 27 28 protected void tearDown() throws Exception { 29 AxisProperties.setProperty(AxisEngine.PROP_ENABLE_NAMESPACE_PREFIX_OPTIMIZATION,"true"); 30 } 31 32 String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 33 "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"; 34 String suffix = "</soapenv:Envelope>"; 35 36 String 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 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 46 { 47 String msg = prefix+m1+suffix; 48 StringReader strReader = new StringReader (msg); 49 DeserializationContext dser = new DeserializationContext( 50 new InputSource (strReader), null, 51 org.apache.axis.Message.REQUEST); 52 dser.parse(); 53 org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope(); 54 String xml = env.toString(); 55 assertXMLIdentical("NSStack invalidated XML canonicalization", 56 new Diff(msg, xml), true); 57 } 58 59 public void testNSStack2() throws Exception 60 { 61 String msg = prefix+m2+suffix; 62 StringReader strReader = new StringReader (msg); 63 DeserializationContext dser = new DeserializationContext( 64 new InputSource (strReader), null, 65 org.apache.axis.Message.REQUEST); 66 dser.parse(); 67 org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope(); 68 String xml = env.toString(); 69 assertXMLIdentical("NSStack invalidated XML canonicalization", 70 new Diff(msg, xml), true); 71 } 72 73 public static void main(String [] args) throws Exception 74 { 75 TestNSStack test = new TestNSStack("TestNSStack"); 76 test.testNSStack1(); 77 test.testNSStack2(); 78 } 79 } 80 | Popular Tags |