KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > om > impl > streamwrapper > OMStaxStreamingWrapperTest


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.streamwrapper;
17
18 import org.apache.axis2.om.AbstractTestCase;
19 import org.apache.axis2.om.OMAbstractFactory;
20 import org.apache.axis2.om.OMXMLParserWrapper;
21 import org.apache.axis2.om.impl.llom.factory.OMXMLBuilderFactory;
22 import org.apache.axis2.soap.SOAPEnvelope;
23
24 import javax.xml.stream.XMLInputFactory;
25 import javax.xml.stream.XMLStreamReader;
26 import java.io.File JavaDoc;
27 import java.io.FileReader JavaDoc;
28
29 public class OMStaxStreamingWrapperTest extends AbstractTestCase {
30     private SOAPEnvelope envelope = null;
31     private File JavaDoc tempFile;
32     private XMLStreamReader parser;
33
34     public OMStaxStreamingWrapperTest(String JavaDoc testName) {
35         super(testName);
36     }
37
38     protected void setUp() throws Exception JavaDoc {
39         XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().
40                         createXMLStreamReader(new FileReader JavaDoc(getTestResourceFile("soap/soapmessage1.xml")));
41         OMXMLParserWrapper builder = OMXMLBuilderFactory.createStAXSOAPModelBuilder(OMAbstractFactory.getSOAP11Factory(), xmlStreamReader);
42         envelope = (SOAPEnvelope) builder.getDocumentElement();
43         tempFile = File.createTempFile("temp", "xml");
44
45     }
46
47
48     // public void testWrapperFullOM() throws Exception {
49
// assertNotNull(envelope);
50
// //this serializing will cause the OM to fully build!
51
// XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(tempFile));
52
// envelope.serializeWithCache(writer,true);
53
// parser = envelope.getXMLStreamReader(false);
54
// while (parser.hasNext()) {
55
// int event = parser.next();
56
// assertTrue(event > 0);
57
// }
58
//
59
// }
60

61     public void testWrapperHalfOM() throws Exception JavaDoc {
62         assertNotNull(envelope);
63         parser = envelope.getXMLStreamReaderWithoutCaching();
64         while (parser.hasNext()) {
65             int event = parser.next();
66             assertTrue(event > 0);
67         }
68     }
69
70     // public void testWrapperHalfOMWithCacheOff() throws Exception {
71
// assertNotNull(envelope);
72
// parser = envelope.getXMLStreamReader(true);
73
// while (parser.hasNext()) {
74
// int event = parser.next();
75
// assertTrue(event > 0);
76
// }
77
// }
78
//
79
// public void testWrapperElementEventGenerationWithHalfOMWithCacheOff() throws XMLStreamException {
80
// assertNotNull(envelope);
81
// parser = envelope.getXMLStreamReader(true);
82
// while (parser.hasNext()) {
83
// int event = parser.next();
84
// assertTrue(event > 0);
85
// if (event == XMLStreamConstants.START_ELEMENT) {
86
// checkStartElement(parser);
87
// } else if (event == XMLStreamConstants.CHARACTERS) {
88
// checkCharacters(parser);
89
// }
90
// }
91
//
92
//
93
// }
94
//
95
// public void testWrapperElementEventGenerationWithHalfOM() throws Exception {
96
// assertNotNull(envelope);
97
// parser = envelope.getXMLStreamReader(false);
98
// while (parser.hasNext()) {
99
// int event = parser.next();
100
// assertTrue(event > 0);
101
// if (event == XMLStreamConstants.START_ELEMENT) {
102
// checkStartElement(parser);
103
// } else if (event == XMLStreamConstants.CHARACTERS) {
104
// checkCharacters(parser);
105
// }
106
// }
107
//
108
//
109
// }
110
//
111
// private void checkCharacters(XMLStreamReader wrapper) {
112
// assertFalse(wrapper.isStartElement());
113
// assertFalse(wrapper.isEndElement());
114
// assertFalse(wrapper.isWhiteSpace());
115
// assertFalse(wrapper.hasName());
116
// assertTrue(wrapper.isCharacters());
117
//
118
// assertNotNull(wrapper.getText());
119
// assertTrue(wrapper.getTextLength() > 0);
120
// }
121
//
122
// private void checkStartElement(XMLStreamReader wrapper) {
123
// assertTrue(wrapper.isStartElement());
124
// assertTrue(wrapper.hasName());
125
// assertFalse(wrapper.isEndElement());
126
// assertFalse(wrapper.isCharacters());
127
// assertFalse(wrapper.isWhiteSpace());
128
//
129
// //at the start element event these need to be supplied
130
// assertNotNull(wrapper.getLocalName());
131
// assertNotNull(wrapper.getName());
132
// assertNotNull(wrapper.getNamespaceURI());
133
// //prefix may be null
134
// wrapper.getPrefix();
135
//
136
// //todo add the other checks here
137
// int attribCount = wrapper.getAttributeCount();
138
// for (int i = 0; i < attribCount; i++) {
139
// assertNotNull(wrapper.getAttributeLocalName(i));
140
// assertNotNull(wrapper.getAttributeValue(i));
141
// assertNotNull(wrapper.getAttributeName(i));
142
// wrapper.getAttributePrefix(i);
143
// wrapper.getAttributeNamespace(i);
144
// //todo add the other checks here
145
// }
146
//
147
//
148
// }
149
//
150
// public void testWrapperElementEventGenerationWithHalfOMWithCacheOff() throws XMLStreamException {
151
// assertNotNull(envelope);
152
// parser = envelope.getXMLStreamReader(true);
153
// while (parser.hasNext()) {
154
// int event = parser.next();
155
// assertTrue(event > 0);
156
// if (event == XMLStreamConstants.START_ELEMENT) {
157
// checkStartElement(parser);
158
// } else if (event == XMLStreamConstants.CHARACTERS) {
159
// checkCharacters(parser);
160
// }
161
// }
162
//
163
//
164
// }
165
//
166
// public void testWrapperElementEventGenerationWithHalfOM() throws Exception {
167
// assertNotNull(envelope);
168
// parser = envelope.getXMLStreamReader(false);
169
// while (parser.hasNext()) {
170
// int event = parser.next();
171
// assertTrue(event > 0);
172
// if (event == XMLStreamConstants.START_ELEMENT) {
173
// checkStartElement(parser);
174
// } else if (event == XMLStreamConstants.CHARACTERS) {
175
// checkCharacters(parser);
176
// }
177
// }
178
//
179
//
180
// }
181
//
182
// private void checkCharacters(XMLStreamReader wrapper) {
183
// assertFalse(wrapper.isStartElement());
184
// assertFalse(wrapper.isEndElement());
185
// assertFalse(wrapper.isWhiteSpace());
186
// assertFalse(wrapper.hasName());
187
// assertTrue(wrapper.isCharacters());
188
//
189
// assertNotNull(wrapper.getText());
190
// assertTrue(wrapper.getTextLength() > 0);
191
// }
192
//
193
// private void checkStartElement(XMLStreamReader wrapper) {
194
// assertTrue(wrapper.isStartElement());
195
// assertTrue(wrapper.hasName());
196
// assertFalse(wrapper.isEndElement());
197
// assertFalse(wrapper.isCharacters());
198
// assertFalse(wrapper.isWhiteSpace());
199
//
200
// //at the start element event these need to be supplied
201
// assertNotNull(wrapper.getLocalName());
202
// assertNotNull(wrapper.getName());
203
// assertNotNull(wrapper.getNamespaceURI());
204
// //prefix may be null
205
// wrapper.getPrefix();
206
//
207
// //todo add the other checks here
208
// int attribCount = wrapper.getAttributeCount();
209
// for (int i = 0; i < attribCount; i++) {
210
// assertNotNull(wrapper.getAttributeLocalName(i));
211
// assertNotNull(wrapper.getAttributeValue(i));
212
// assertNotNull(wrapper.getAttributeName(i));
213
// wrapper.getAttributePrefix(i);
214
// wrapper.getAttributeNamespace(i);
215
// //todo add the other checks here
216
// }
217
//
218
//
219
// }
220

221
222     protected void tearDown() throws Exception JavaDoc {
223         tempFile.delete();
224     }
225 }
226
Popular Tags