KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > OMNavigatorTest


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;
17
18 import org.apache.axis2.om.impl.llom.OMNavigator;
19 import org.apache.axis2.soap.SOAPEnvelope;
20 import org.apache.axis2.soap.SOAPFactory;
21 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
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 OMNavigatorTest extends AbstractTestCase {
31     private SOAPEnvelope envelope = null;
32     private OMXMLParserWrapper builder;
33     private File JavaDoc tempFile;
34     private OMOutput omOutput;
35
36     public OMNavigatorTest(String JavaDoc testName) {
37         super(testName);
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41         XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().
42                         createXMLStreamReader(new FileReader JavaDoc(getTestResourceFile("soap/soapmessage1.xml")));
43         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
44         builder = new StAXSOAPModelBuilder(xmlStreamReader);
45         envelope = (SOAPEnvelope) builder.getDocumentElement();
46         tempFile = File.createTempFile("temp", "xml");
47         omOutput = new OMOutput(XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream JavaDoc(tempFile)));
48         // writer = XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
49

50
51     }
52
53     public void testnavigatorFullyBuilt() throws Exception JavaDoc {
54         assertNotNull(envelope);
55         //dump the out put to a temporary file
56
envelope.serializeWithCache(omOutput);
57
58         //now the OM is fully created test the navigation
59
OMNavigator navigator = new OMNavigator(envelope);
60         OMNode node = null;
61         while (navigator.isNavigable()) {
62             node = navigator.next();
63             assertNotNull(node);
64         }
65     }
66
67     public void testnavigatorHalfBuilt() {
68         assertNotNull(envelope);
69         //now the OM is not fully created. Try to navigate it
70
OMNavigator navigator = new OMNavigator(envelope);
71         OMNode node = null;
72         while (navigator.isNavigable()) {
73             node = navigator.next();
74             assertNotNull(node);
75         }
76     }
77
78     public void testnavigatorHalfBuiltStep() {
79         assertNotNull(envelope);
80
81         //now the OM is not fully created
82
OMNavigator navigator = new OMNavigator(envelope);
83         OMNode node = null;
84         while (!navigator.isCompleted()) {
85             if (navigator.isNavigable()) {
86                 node = navigator.next();
87             } else {
88                 builder.next();
89                 navigator.step();
90                 node = navigator.next();
91             }
92             assertNotNull(node);
93
94         }
95
96     }
97
98     protected void tearDown() throws Exception JavaDoc {
99         omOutput.flush();
100         tempFile.delete();
101     }
102
103 }
104
Popular Tags