01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.springframework.xml.stream;
18:
19: import java.io.StringReader;
20: import javax.xml.stream.XMLEventReader;
21: import javax.xml.stream.XMLInputFactory;
22: import javax.xml.transform.Transformer;
23: import javax.xml.transform.TransformerFactory;
24:
25: import org.custommonkey.xmlunit.XMLTestCase;
26: import org.springframework.xml.transform.StaxSource;
27: import org.springframework.xml.transform.StringResult;
28:
29: public class XmlEventStreamReaderTest extends XMLTestCase {
30:
31: private static final String XML = "<?pi content?><root xmlns='namespace'><prefix:child xmlns:prefix='namespace2'>content</prefix:child></root>";
32:
33: private XmlEventStreamReader streamReader;
34:
35: protected void setUp() throws Exception {
36: XMLInputFactory inputFactory = XMLInputFactory.newInstance();
37: XMLEventReader eventReader = inputFactory
38: .createXMLEventReader(new StringReader(XML));
39: streamReader = new XmlEventStreamReader(eventReader);
40: }
41:
42: public void testReadAll() throws Exception {
43: while (streamReader.hasNext()) {
44: streamReader.next();
45: }
46: }
47:
48: public void testReadCorrect() throws Exception {
49: Transformer transformer = TransformerFactory.newInstance()
50: .newTransformer();
51: StaxSource source = new StaxSource(streamReader);
52: StringResult result = new StringResult();
53: transformer.transform(source, result);
54: assertXMLEqual(XML, result.toString());
55: }
56:
57: }
|