KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
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 JavaDoc;
27 import java.io.FileOutputStream JavaDoc;
28 import java.io.FileReader JavaDoc;
29
30 public class ElementSerializerTest extends AbstractTestCase {
31     private XMLStreamReader reader;
32     private OMOutput omOutput;
33     private OMXMLParserWrapper builder;
34     private File JavaDoc tempFile;
35
36     public ElementSerializerTest(String JavaDoc testName) {
37         super(testName);
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41         reader = XMLInputFactory.newInstance().
42                 createXMLStreamReader(new FileReader JavaDoc(getTestResourceFile("soap/soapmessage.xml")));
43         tempFile = File.createTempFile("temp", "xml");
44         omOutput = new OMOutput(XMLOutputFactory.newInstance().
45                 createXMLStreamWriter(new FileOutputStream JavaDoc(tempFile)));
46         builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), reader);
47     }
48
49     public void testElementSerilization() throws Exception JavaDoc {
50         OMElement elt = builder.getDocumentElement();
51         elt.serializeWithCache(omOutput);
52
53     }
54
55     public void testElementSerilizationCacheOff() throws Exception JavaDoc {
56         OMElement elt = builder.getDocumentElement();
57         elt.serializeWithCache(omOutput);
58
59     }
60
61     public void testElementSerilizationChild() throws Exception JavaDoc {
62         OMElement elt = builder.getDocumentElement();
63         OMNode node = elt.getFirstChild().getNextSibling();
64         node.serializeWithCache(omOutput);
65
66     }
67
68     public void testElementSerilizationSOAPBodyCacheOff() throws Exception JavaDoc {
69         SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
70         OMNode node = env.getBody();
71         node.serializeWithCache(omOutput);
72     }
73
74     public void testElement() throws Exception JavaDoc {
75         SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
76         SOAPBody body = env.getBody();
77         body.serializeWithCache(omOutput);
78     }
79
80     public void testCompleteElement() throws Exception JavaDoc {
81         SOAPEnvelope env = (SOAPEnvelope) builder.getDocumentElement();
82         env.serializeWithCache(omOutput);
83     }
84
85     public void testDualNamespaces1() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
116         omOutput.flush();
117         tempFile.delete();
118     }
119 }
120
Popular Tags