1 16 package org.apache.axis2.om.impl.serializer; 17 18 import org.apache.axis2.om.AbstractTestCase; 19 import org.apache.axis2.om.OMAbstractFactory; 20 import org.apache.axis2.om.OMOutput; 21 import org.apache.axis2.om.OMXMLParserWrapper; 22 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory; 23 import org.apache.axis2.om.impl.llom.serialize.StreamingOMSerializer; 24 import org.apache.axis2.soap.SOAPBody; 25 import org.apache.axis2.soap.SOAPEnvelope; 26 27 import javax.xml.stream.XMLInputFactory; 28 import javax.xml.stream.XMLOutputFactory; 29 import javax.xml.stream.XMLStreamReader; 30 import java.io.File ; 31 import java.io.FileOutputStream ; 32 import java.io.FileReader ; 33 34 public class OMSerializerTest extends AbstractTestCase { 35 private XMLStreamReader reader; 36 private OMOutput omOutput; 37 private File tempFile; 38 39 public OMSerializerTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 reader = XMLInputFactory.newInstance(). 45 createXMLStreamReader(new FileReader (getTestResourceFile("soap/soapmessage.xml"))); 46 tempFile = File.createTempFile("temp", "xml"); 47 omOutput = new OMOutput(XMLOutputFactory.newInstance(). 48 createXMLStreamWriter(new FileOutputStream (tempFile))); 49 } 52 53 public void testRawSerializer() throws Exception { 54 StreamingOMSerializer serializer = new StreamingOMSerializer(); 55 serializer.serialize(reader, omOutput); 57 58 } 59 60 public void testElementPullStream1() throws Exception { 61 OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), 62 reader); 63 SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement(); 64 StreamingOMSerializer serializer = new StreamingOMSerializer(); 65 serializer.serialize(env.getXMLStreamReaderWithoutCaching(), omOutput); 66 } 67 68 public void testElementPullStream1WithCacheOff() throws Exception { 69 OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), 70 reader); 71 SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement(); 72 StreamingOMSerializer serializer = new StreamingOMSerializer(); 73 serializer.serialize(env.getXMLStreamReader(), omOutput); 74 } 75 76 public void testElementPullStream2() throws Exception { 77 OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), 78 reader); 79 SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement(); 80 SOAPBody body = env.getBody(); 81 StreamingOMSerializer serializer = new StreamingOMSerializer(); 82 serializer.serialize(body.getXMLStreamReaderWithoutCaching(), omOutput); 83 } 84 85 protected void tearDown() throws Exception { 86 omOutput.flush(); 87 tempFile.delete(); 88 } 89 } 90 | Popular Tags |