use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class EventSpecificTestCase method runTest.
protected final void runTest() throws Throwable {
XMLInputFactory factory = staxImpl.getDialect().enableCDataReporting(staxImpl.newNormalizedXMLInputFactory());
factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
InputStream in = IllegalStateExceptionTestCase.class.getResourceAsStream("alleventtypes.xml");
try {
XMLStreamReader reader = factory.createXMLStreamReader(in);
while (true) {
if (reader.getEventType() == event) {
break;
} else if (reader.hasNext()) {
reader.next();
} else {
fail("Internal error: didn't encounter event " + event);
}
}
runTest(reader);
} finally {
in.close();
}
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class XMLFragmentStreamReaderTest method test.
/**
* Test comparing the output of {@link XMLFragmentStreamReader} with that
* of a native StAX parser. In particular this tests the behavior for START_DOCUMENT
* and END_DOCUMENT events.
*
* @throws Exception
*/
public void test() throws Exception {
String xml = "<ns:a xmlns:ns='urn:ns'>test</ns:a>";
XMLStreamReader expected = StAXUtils.createXMLStreamReader(new StringReader(xml));
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader(xml));
reader.nextTag();
XMLStreamReader actual = new XMLFragmentStreamReader(reader);
new XMLStreamReaderComparator(expected, actual).compare();
assertEquals(XMLStreamReader.END_DOCUMENT, reader.getEventType());
expected.close();
reader.close();
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementWithUnexpectedContent.
private void testGetDataHandlerFromElementWithUnexpectedContent(boolean useDHR) throws Exception {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test>\n<child/>\n</test>"));
if (useDHR) {
reader = new XMLStreamReaderWithDataHandlerReader(reader);
}
try {
reader.next();
// Check precondition
assertTrue(reader.isStartElement());
try {
XMLStreamReaderUtils.getDataHandlerFromElement(reader);
fail("Expected XMLStreamException");
} catch (XMLStreamException ex) {
// Expected
}
} finally {
reader.close();
}
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class XMLStreamReaderUtilsTest method testGetDataHandlerFromElementWithZeroLength.
private void testGetDataHandlerFromElementWithZeroLength(boolean useDHR) throws Exception {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<test/>"));
if (useDHR) {
reader = new XMLStreamReaderWithDataHandlerReader(reader);
}
try {
reader.next();
// Check precondition
assertTrue(reader.isStartElement());
DataHandler dh = XMLStreamReaderUtils.getDataHandlerFromElement(reader);
// Check postcondition
assertTrue(reader.isEndElement());
assertEquals(-1, dh.getInputStream().read());
} finally {
reader.close();
}
}
use of javax.xml.stream.XMLStreamReader in project webservices-axiom by apache.
the class XMLStreamReaderUtilsTest method testGetElementTextAsStreamWithAllowedNonTextChildren.
public void testGetElementTextAsStreamWithAllowedNonTextChildren() throws Exception {
XMLStreamReader reader = StAXUtils.createXMLStreamReader(new StringReader("<a>xxx<b>yyy</b>zzz</a>"));
reader.next();
Reader in = XMLStreamReaderUtils.getElementTextAsStream(reader, true);
assertEquals("xxxzzz", IOUtils.toString(in));
}
Aggregations