Search in sources :

Example 1 with DeferredParsingException

use of org.apache.axiom.om.DeferredParsingException 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());
}
Also used : DeferredParsingException(org.apache.axiom.om.DeferredParsingException) XMLStreamReader(javax.xml.stream.XMLStreamReader) OMElement(org.apache.axiom.om.OMElement) InvocationCounter(org.apache.axiom.testutils.InvocationCounter)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)1 DeferredParsingException (org.apache.axiom.om.DeferredParsingException)1 OMElement (org.apache.axiom.om.OMElement)1 InvocationCounter (org.apache.axiom.testutils.InvocationCounter)1