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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations