1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 =
32 "<?pi content?><root xmlns='namespace'><prefix:child xmlns:prefix='namespace2'>content</prefix:child></root>";
33
34 private XmlEventStreamReader streamReader;
35
36 protected void setUp() throws Exception {
37 XMLInputFactory inputFactory = XMLInputFactory.newInstance();
38 XMLEventReader eventReader = inputFactory.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().newTransformer();
50 StaxSource source = new StaxSource(streamReader);
51 StringResult result = new StringResult();
52 transformer.transform(source, result);
53 assertXMLEqual(XML, result.toString());
54 }
55
56 }