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