Search in sources :

Example 1 with MockResolver

use of tests.api.org.xml.sax.support.MockResolver in project robovm by robovm.

the class ParserAdapterTest method testGetSetEntityResolver.

public void testGetSetEntityResolver() {
    EntityResolver resolver = new MockResolver();
    adapter.setEntityResolver(resolver);
    assertEquals(resolver, adapter.getEntityResolver());
    adapter.setEntityResolver(null);
    assertEquals(null, adapter.getEntityResolver());
}
Also used : EntityResolver(org.xml.sax.EntityResolver) MockResolver(tests.api.org.xml.sax.support.MockResolver)

Example 2 with MockResolver

use of tests.api.org.xml.sax.support.MockResolver in project robovm by robovm.

the class XMLFilterImplTest method testResolveEntity.

public void testResolveEntity() {
    InputSource expected = new InputSource();
    MockResolver resolver = new MockResolver();
    resolver.addEntity("foo", "bar", expected);
    InputSource result = null;
    parent.setEntityResolver(resolver);
    // Ordinary case
    try {
        result = parent.resolveEntity("foo", "bar");
    } catch (SAXException e) {
        throw new RuntimeException("Unexpected exception", e);
    } catch (IOException e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    assertEquals(expected, result);
    // No entity resolver case
    parent.setEntityResolver(null);
    try {
        result = parent.resolveEntity("foo", "bar");
    } catch (SAXException e) {
        throw new RuntimeException("Unexpected exception", e);
    } catch (IOException e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    assertEquals(null, result);
}
Also used : InputSource(org.xml.sax.InputSource) MockResolver(tests.api.org.xml.sax.support.MockResolver) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 3 with MockResolver

use of tests.api.org.xml.sax.support.MockResolver in project robovm by robovm.

the class XMLReaderAdapterTest method testSetEntityResolver.

public void testSetEntityResolver() {
    EntityResolver resolver = new MockResolver();
    // Ordinary case
    adapter.setEntityResolver(resolver);
    assertEquals(resolver, reader.getEntityResolver());
    // null case
    adapter.setEntityResolver(null);
    assertEquals(null, reader.getEntityResolver());
}
Also used : EntityResolver(org.xml.sax.EntityResolver) MockResolver(tests.api.org.xml.sax.support.MockResolver)

Example 4 with MockResolver

use of tests.api.org.xml.sax.support.MockResolver in project robovm by robovm.

the class DocumentBuilderTest method testReset.

public void testReset() {
    // Make sure EntityResolver gets reset
    InputStream source = new ByteArrayInputStream("<a>&foo;</a>".getBytes());
    InputStream entity = new ByteArrayInputStream("bar".getBytes());
    MockResolver resolver = new MockResolver();
    resolver.addEntity("foo", "foo", new InputSource(entity));
    Document d;
    try {
        db = dbf.newDocumentBuilder();
        db.setEntityResolver(resolver);
        db.reset();
        d = db.parse(source);
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    Element root = (Element) d.getElementsByTagName("a").item(0);
    assertEquals("foo", ((EntityReference) root.getFirstChild()).getNodeName());
    // Make sure ErrorHandler gets reset
    source = new ByteArrayInputStream("</a>".getBytes());
    MethodLogger logger = new MethodLogger();
    ErrorHandler handler = new MockHandler(logger);
    try {
        db = dbf.newDocumentBuilder();
        db.setErrorHandler(handler);
        db.reset();
        d = db.parse(source);
    } catch (SAXParseException e) {
    // Expected
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    assertEquals(0, logger.size());
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) Element(org.w3c.dom.Element) MockHandler(tests.api.org.xml.sax.support.MockHandler) MockResolver(tests.api.org.xml.sax.support.MockResolver) Document(org.w3c.dom.Document) MethodLogger(tests.api.org.xml.sax.support.MethodLogger) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 5 with MockResolver

use of tests.api.org.xml.sax.support.MockResolver in project robovm by robovm.

the class DocumentBuilderTest method testSetEntityResolver.

public void testSetEntityResolver() {
    // Ordinary case
    InputStream source = new ByteArrayInputStream("<a>&foo;</a>".getBytes());
    InputStream entity = new ByteArrayInputStream("bar".getBytes());
    MockResolver resolver = new MockResolver();
    resolver.addEntity("foo", "foo", new InputSource(entity));
    Document d;
    try {
        db = dbf.newDocumentBuilder();
        db.setEntityResolver(resolver);
        d = db.parse(source);
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    Element root = (Element) d.getElementsByTagName("a").item(0);
    assertEquals("bar", ((Text) root.getFirstChild()).getData());
    // null case
    source = new ByteArrayInputStream("<a>&foo;</a>".getBytes());
    try {
        db = dbf.newDocumentBuilder();
        db.setEntityResolver(null);
        d = db.parse(source);
    } catch (Exception e) {
        throw new RuntimeException("Unexpected exception", e);
    }
    root = (Element) d.getElementsByTagName("a").item(0);
    assertEquals("foo", ((EntityReference) root.getFirstChild()).getNodeName());
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) MockResolver(tests.api.org.xml.sax.support.MockResolver) Document(org.w3c.dom.Document) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Aggregations

MockResolver (tests.api.org.xml.sax.support.MockResolver)6 IOException (java.io.IOException)3 EntityResolver (org.xml.sax.EntityResolver)3 InputSource (org.xml.sax.InputSource)3 SAXException (org.xml.sax.SAXException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 SAXParseException (org.xml.sax.SAXParseException)2 ErrorHandler (org.xml.sax.ErrorHandler)1 MethodLogger (tests.api.org.xml.sax.support.MethodLogger)1 MockHandler (tests.api.org.xml.sax.support.MockHandler)1