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