Search in sources :

Example 1 with MockResolver

use of org.apache.harmony.tests.org.xml.sax.support.MockResolver in project j2objc by google.

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(org.apache.harmony.tests.org.xml.sax.support.MockHandler) MockResolver(org.apache.harmony.tests.org.xml.sax.support.MockResolver) Document(org.w3c.dom.Document) MethodLogger(org.apache.harmony.tests.org.xml.sax.support.MethodLogger) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 2 with MockResolver

use of org.apache.harmony.tests.org.xml.sax.support.MockResolver in project j2objc by google.

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(org.apache.harmony.tests.org.xml.sax.support.MockResolver)

Example 3 with MockResolver

use of org.apache.harmony.tests.org.xml.sax.support.MockResolver in project j2objc by google.

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(org.apache.harmony.tests.org.xml.sax.support.MockResolver)

Example 4 with MockResolver

use of org.apache.harmony.tests.org.xml.sax.support.MockResolver in project j2objc by google.

the class XMLFilterImplTest method testGetSetEntityResolver.

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

Example 5 with MockResolver

use of org.apache.harmony.tests.org.xml.sax.support.MockResolver in project j2objc by google.

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(org.apache.harmony.tests.org.xml.sax.support.MockResolver) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

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