KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > serializer > OMSerializerTest


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
31 import java.io.FileOutputStream JavaDoc;
32 import java.io.FileReader JavaDoc;
33
34 public class OMSerializerTest extends AbstractTestCase {
35     private XMLStreamReader reader;
36     private OMOutput omOutput;
37     private File JavaDoc tempFile;
38
39     public OMSerializerTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         reader = XMLInputFactory.newInstance().
45                 createXMLStreamReader(new FileReader JavaDoc(getTestResourceFile("soap/soapmessage.xml")));
46         tempFile = File.createTempFile("temp", "xml");
47         omOutput = new OMOutput(XMLOutputFactory.newInstance().
48                 createXMLStreamWriter(new FileOutputStream JavaDoc(tempFile)));
49         // writer = XMLOutputFactory.newInstance().
50
// createXMLStreamWriter(System.out);
51
}
52
53     public void testRawSerializer() throws Exception JavaDoc {
54         StreamingOMSerializer serializer = new StreamingOMSerializer();
55         //serializer.setNamespacePrefixStack(new Stack());
56
serializer.serialize(reader, omOutput);
57
58     }
59
60     public void testElementPullStream1() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
86         omOutput.flush();
87         tempFile.delete();
88     }
89 }
90
Popular Tags