KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.axis2.om;
2
3 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
4
5 import javax.xml.stream.XMLInputFactory;
6 import javax.xml.stream.XMLStreamReader;
7 import java.io.ByteArrayInputStream JavaDoc;
8
9 /*
10 * Copyright 2004,2005 The Apache Software Foundation.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 * Aim of this test is to check the compatibilty of the stax parser implementation
25 */

26 public class StaxParserTest extends AbstractTestCase {
27
28     XMLStreamReader parser1;
29     XMLStreamReader parser2;
30     XMLStreamReader parser3;
31     String JavaDoc xmlDocument = "<purchase-order xmlns=\"http://openuri.org/easypo\">" +
32             "<customer>" +
33             " <name>Gladys Kravitz</name>" +
34             " <address>Anytown, PA</address>" +
35             " </customer>" +
36             " <date>2005-03-06T14:06:12.697+06:00</date>" +
37             "</purchase-order>";
38
39     public StaxParserTest(String JavaDoc testName) {
40         super(testName);
41     }
42
43     protected void setUp() throws Exception JavaDoc {
44         //make the parsers
45
parser1 = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream JavaDoc(xmlDocument.getBytes()));
46
47         OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(),
48                 XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream JavaDoc(xmlDocument.getBytes())));
49         parser2 = builder.getDocumentElement().getXMLStreamReader();
50
51         OMXMLParserWrapper builder2 = OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getSOAP11Factory(),
52                 XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream JavaDoc(xmlDocument.getBytes())));
53         parser3 = builder2.getDocumentElement().getXMLStreamReaderWithoutCaching();
54
55     }
56
57     public void testParserEventsWithCache() throws Exception JavaDoc{
58
59         assertEquals(parser1.getEventType(),parser2.getEventType());
60
61         while(parser1.hasNext()){
62
63                 int parser1Event = parser1.next();
64                 int parser2Event = parser2.next();
65                 assertEquals(parser1Event,parser2Event);
66
67         }
68
69
70     }
71
72      public void testParserEventsWithoutCache() throws Exception JavaDoc{
73
74         assertEquals(parser1.getEventType(),parser3.getEventType());
75
76         while(parser1.hasNext()){
77             int parser1Event = parser1.next();
78             int parser2Event = parser3.next();
79             assertEquals(parser1Event,parser2Event);
80         }
81
82
83     }
84
85     public void testParserEvents2WithCache() throws Exception JavaDoc{
86         while(parser1.hasNext()){
87             int parser1Event = parser1.getEventType();
88             int parser2Event = parser2.getEventType();
89             parser1.next();
90             parser2.next();
91             assertEquals(parser1Event,parser2Event);
92         }
93
94
95     }
96 }
97 // public void testParserEvents2() throws Exception{
98
//
99
// System.out.println("parser2 initial = " + parser2.getEventType());
100
// while(parser2.hasNext()){
101
// System.out.println(" event "+ parser2.next() + parser2.getLocalName());
102
// }
103

104
105 //}
106

107
108
109
Popular Tags