1 package org.apache.axis2.om.impl.serializer; 2 3 import junit.framework.TestCase; 4 import org.apache.axis2.om.OMAbstractFactory; 5 import org.apache.axis2.om.OMElement; 6 import org.apache.axis2.om.OMOutput; 7 import org.apache.axis2.om.OMXMLParserWrapper; 8 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; 9 import org.apache.axis2.soap.SOAPEnvelope; 10 import org.apache.axis2.soap.SOAPFactory; 11 12 import javax.xml.stream.XMLInputFactory; 13 import javax.xml.stream.XMLOutputFactory; 14 import javax.xml.stream.XMLStreamReader; 15 import java.io.ByteArrayInputStream ; 16 import java.io.InputStreamReader ; 17 18 35 36 public class NoNamespaceSerializerTest extends TestCase { 37 38 private String xmlTextOne = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + 39 "<soapenv:Body>\n" + 40 " <ns1:getBalance xmlns:ns1=\"http://localhost:8081/axis/services/BankPort/\">\n" + 41 " <accountNo HREF=\"#id0\"/>\n" + 42 " </ns1:getBalance>\n" + 43 " </soapenv:Body></soapenv:Envelope>"; 44 45 private String xmlText2 = "<purchase-order xmlns=\"http://openuri.org/easypo\">\n" + 46 " <customer>\n" + 47 " <name>Gladys Kravitz</name>\n" + 48 " <address>Anytown, PA</address>\n" + 49 " </customer>\n" + 50 " <date>2005-03-06T14:06:12.697+06:00</date>\n" + 51 "</purchase-order>"; 52 53 private String xmlTextTwo = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" + 54 "<soapenv:Body>\n" + 55 " <getBalance xmlns=\"http://localhost:8081/axis/services/BankPort/\">\n" + 56 " <accountNo HREF=\"#id0\"/>\n" + 57 " </getBalance>\n" + 58 " </soapenv:Body></soapenv:Envelope>"; 59 60 private XMLStreamReader readerOne; 61 private XMLStreamReader readerTwo; 62 private OMOutput omOutput; 63 64 67 private OMXMLParserWrapper builderOne; 68 private OMXMLParserWrapper builderTwo; 69 71 72 73 protected void setUp() throws Exception { 74 readerOne = XMLInputFactory.newInstance(). 75 createXMLStreamReader(new InputStreamReader (new ByteArrayInputStream (xmlTextOne.getBytes()))); 76 readerTwo = XMLInputFactory.newInstance(). 77 createXMLStreamReader(new InputStreamReader (new ByteArrayInputStream (xmlTextTwo.getBytes()))); 78 omOutput = new OMOutput(XMLOutputFactory.newInstance(). 79 createXMLStreamWriter(System.out)); 80 builderOne = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), readerOne); 81 builderTwo = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), readerTwo); 82 } 83 84 85 99 100 public void testSerilizationWithDefaultNamespaces() throws Exception { 101 SOAPEnvelope env = (SOAPEnvelope) builderTwo.getDocumentElement(); 102 env.serializeWithCache(omOutput); 103 OMElement balanceElement = env.getBody().getFirstElement(); 104 assertEquals("Deafualt namespace has not been set properly", balanceElement.getNamespace().getName(), "http://localhost:8081/axis/services/BankPort/"); 105 106 OMElement accountNo = balanceElement.getFirstElement(); 107 assertEquals("Deafualt namespace of children has not been set properly", accountNo.getNamespace().getName(), "http://localhost:8081/axis/services/BankPort/"); 108 109 } 110 111 public void submitPurchaseOrderTest() 112 throws Exception { 113 SOAPFactory omFactory = OMAbstractFactory.getSOAP11Factory(); 114 SOAPEnvelope env = omFactory.getDefaultEnvelope(); 115 OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(omFactory,XMLInputFactory.newInstance(). 116 createXMLStreamReader(new InputStreamReader (new ByteArrayInputStream (xmlText2.getBytes())))); 117 env.getBody().addChild(builder.getDocumentElement()); 118 119 OMOutput omOutput = new OMOutput(System.out,false); 120 122 env.serializeWithCache(omOutput); 123 125 omOutput.flush(); 126 127 } 128 public void testSerilizationWithCacheOn() throws Exception { 129 SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement(); 130 env.serializeWithCache(omOutput); 131 omOutput.flush(); 132 } 133 134 public void testSerilizationWithCacheOff() throws Exception { 135 SOAPEnvelope env = (SOAPEnvelope) builderOne.getDocumentElement(); 136 env.serializeWithCache(omOutput); 137 omOutput.flush(); 138 } 139 } 140 | Popular Tags |