Search in sources :

Example 1 with WFCException

use of com.fasterxml.aalto.WFCException in project aalto-xml by FasterXML.

the class TestLaziness method testEventReaderNonLaziness.

/**
 * This test verifies that lazy parsing is not enabled, by making
 * use of a specific side effect of lazy parsing. Specifically, parts
 * of Stax API do not expose XMLStreamException: such as getText()
 * method of the stream reader. Thus we can infer whether lazy mode
 * is enabled or not by whether we get a regular XMLStreamException
 * when trying to access the event, or not.
 *<p>
 * Note: whether this test reliably detecs "laziness" may depend
 * on the event reader implementation.
 */
public void testEventReaderNonLaziness() throws XMLStreamException {
    final String XML = "<root>Some text and &amp; ...\n\n &error;</root>";
    XMLEventReader er = getReader(XML);
    // First things first: what does it say about mode?
    assertEquals("Event reader should have P_LAZY_PARSING == false", Boolean.FALSE, er.getProperty(XMLInputFactory2.P_LAZY_PARSING));
    // start document
    XMLEvent evt = er.nextEvent();
    assertTrue(evt.isStartDocument());
    assertTrue(er.nextEvent().isStartElement());
    // Ok, and now...
    try {
        evt = er.nextEvent();
        // should NOT get this far...
        fail("Expected an exception for invalid content: something not working with event reader");
    } catch (WFCException wex) {
    // This is correct... parsing exc for entity, hopefully
    // System.err.println("GOOD: got "+wex.getClass()+": "+wex);
    } catch (UncheckedStreamException ue) {
        // Not good; lazy exception
        fail("Should not get a lazy exception via (default) event reader, but did get one: " + ue);
    } catch (Throwable t) {
        fail("Unexpected excpetion (class " + t.getClass() + ") caught: " + t);
    }
}
Also used : UncheckedStreamException(com.fasterxml.aalto.UncheckedStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) WFCException(com.fasterxml.aalto.WFCException)

Aggregations

UncheckedStreamException (com.fasterxml.aalto.UncheckedStreamException)1 WFCException (com.fasterxml.aalto.WFCException)1 XMLEvent (javax.xml.stream.events.XMLEvent)1