1 16 package org.apache.axis2.om.impl.serializer; 17 18 import org.apache.axis2.om.*; 19 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; 20 import org.apache.axis2.soap.SOAPBody; 21 import org.apache.axis2.soap.SOAPEnvelope; 22 23 import javax.xml.stream.XMLInputFactory; 24 import javax.xml.stream.XMLOutputFactory; 25 import javax.xml.stream.XMLStreamReader; 26 import java.io.File ; 27 import java.io.FileOutputStream ; 28 import java.io.FileReader ; 29 30 public class ElementSerializerTest extends AbstractTestCase { 31 private XMLStreamReader reader; 32 private OMOutput omOutput; 33 private OMXMLParserWrapper builder; 34 private File tempFile; 35 36 public ElementSerializerTest(String testName) { 37 super(testName); 38 } 39 40 protected void setUp() throws Exception { 41 reader = XMLInputFactory.newInstance(). 42 createXMLStreamReader(new FileReader (getTestResourceFile("soap/soapmessage.xml"))); 43 tempFile = File.createTempFile("temp", "xml"); 44 omOutput = new OMOutput(XMLOutputFactory.newInstance(). 45 createXMLStreamWriter(new FileOutputStream (tempFile))); 46 builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), reader); 47 } 48 49 public void testElementSerilization() throws Exception { 50 OMElement elt = builder.getDocumentElement(); 51 elt.serializeWithCache(omOutput); 52 53 } 54 55 public void testElementSerilizationCacheOff() throws Exception { 56 OMElement elt = builder.getDocumentElement(); 57 elt.serializeWithCache(omOutput); 58 59 } 60 61 public void testElementSerilizationChild() throws Exception { 62 OMElement elt = builder.getDocumentElement(); 63 OMNode node = elt.getFirstChild().getNextSibling(); 64 node.serializeWithCache(omOutput); 65 66 } 67 68 public void testElementSerilizationSOAPBodyCacheOff() throws Exception { 69 SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement(); 70 OMNode node = env.getBody(); 71 node.serializeWithCache(omOutput); 72 } 73 74 public void testElement() throws Exception { 75 SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement(); 76 SOAPBody body = env.getBody(); 77 body.serializeWithCache(omOutput); 78 } 79 80 public void testCompleteElement() throws Exception { 81 SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement(); 82 env.serializeWithCache(omOutput); 83 } 84 85 public void testDualNamespaces1() throws Exception { 86 OMFactory factory = OMAbstractFactory.getOMFactory(); 87 OMNamespace ns1 = factory.createOMNamespace("bar", "x"); 88 OMNamespace ns2 = factory.createOMNamespace("bar", "y"); 89 OMElement root = factory.createOMElement("root", ns1); 90 OMElement elt11 = factory.createOMElement("foo1", ns1); 91 OMElement elt12 = factory.createOMElement("foo2", ns1); 92 OMElement elt21 = factory.createOMElement("yuck", ns2); 93 OMElement elt22 = factory.createOMElement("yuck", ns2); 94 elt11.addChild(elt21); 95 elt12.addChild(elt22); 96 root.addChild(elt11); 97 root.addChild(elt12); 98 root.serializeWithCache(omOutput); 99 } 100 101 public void testDualNamespaces2() throws Exception { 102 OMFactory factory = OMAbstractFactory.getOMFactory(); 103 OMNamespace ns1 = factory.createOMNamespace("bar", "x"); 104 OMElement root = factory.createOMElement("root", ns1); 105 OMNamespace ns2 = root.declareNamespace("bar", "y"); 106 OMElement elt1 = factory.createOMElement("foo", ns1); 107 OMElement elt2 = factory.createOMElement("yuck", ns2); 108 OMText txt1 = factory.createText(elt2, "blah"); 109 elt2.addChild(txt1); 110 elt1.addChild(elt2); 111 root.addChild(elt1); 112 root.serializeWithCache(omOutput); 113 } 114 115 protected void tearDown() throws Exception { 116 omOutput.flush(); 117 tempFile.delete(); 118 } 119 } 120 | Popular Tags |