use of org.apache.axiom.testutils.InvocationCounter in project webservices-axiom by apache.
the class TestIOExceptionInGetText method runTest.
@Override
protected void runTest() throws Throwable {
// Construct a stream that will throw an exception in the middle of a text node.
// We need to create a very large document, because some parsers (such as some
// versions of XLXP) have a large input buffer and would throw an exception already
// when the XMLStreamReader is created.
StringBuffer xml = new StringBuffer("<root>");
for (int i = 0; i < 100000; i++) {
xml.append('x');
}
InputStream in = new ExceptionInputStream(new ByteArrayInputStream(xml.toString().getBytes("ASCII")));
XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(in);
InvocationCounter invocationCounter = new InvocationCounter();
XMLStreamReader reader = (XMLStreamReader) invocationCounter.createProxy(originalReader);
OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
try {
element.getNextOMSibling();
fail("Expected exception");
} catch (Exception ex) {
// Expected
}
assertTrue(invocationCounter.getInvocationCount() > 0);
invocationCounter.reset();
try {
element.getNextOMSibling();
fail("Expected exception");
} catch (Exception ex) {
// Expected
}
assertEquals(0, invocationCounter.getInvocationCount());
}
use of org.apache.axiom.testutils.InvocationCounter in project webservices-axiom by apache.
the class TestInvalidXML method runTest.
@Override
protected void runTest() throws Throwable {
XMLStreamReader originalReader = StAXUtils.createXMLStreamReader(TestInvalidXML.class.getResourceAsStream("invalid_xml.xml"));
InvocationCounter invocationCounter = new InvocationCounter();
XMLStreamReader reader = (XMLStreamReader) invocationCounter.createProxy(originalReader);
OMElement element = OMXMLBuilderFactory.createStAXOMBuilder(metaFactory.getOMFactory(), reader).getDocumentElement();
DeferredParsingException exception;
try {
element.getNextOMSibling();
exception = null;
} catch (DeferredParsingException ex) {
exception = ex;
}
assertThat(exception).isNotNull();
assertTrue(invocationCounter.getInvocationCount() > 0);
invocationCounter.reset();
// Intentionally call builder again to make sure the same error is returned.
DeferredParsingException exception2;
try {
element.getNextOMSibling();
exception2 = null;
} catch (DeferredParsingException ex) {
exception2 = ex;
}
assertThat(invocationCounter.getInvocationCount()).isEqualTo(0);
assertThat(exception2).isNotNull();
assertThat(exception2.getMessage()).isEqualTo(exception.getMessage());
}
Aggregations