use of tests.api.org.xml.sax.support.MethodLogger 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.MethodLogger in project robovm by robovm.
the class DocumentBuilderTest method testSetErrorHandler.
public void testSetErrorHandler() {
// Ordinary case
InputStream source = new ByteArrayInputStream("</a>".getBytes());
MethodLogger logger = new MethodLogger();
ErrorHandler handler = new MockHandler(logger);
try {
db = dbf.newDocumentBuilder();
db.setErrorHandler(handler);
db.parse(source);
} catch (SAXParseException e) {
// Expected, ErrorHandler does not mask exception
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
assertEquals("error", logger.getMethod());
assertTrue(logger.getArgs()[0] instanceof SAXParseException);
// null case
source = new ByteArrayInputStream("</a>".getBytes());
try {
db = dbf.newDocumentBuilder();
db.setErrorHandler(null);
db.parse(source);
} catch (SAXParseException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
}
use of tests.api.org.xml.sax.support.MethodLogger in project robovm by robovm.
the class SAXParserTest method testReset.
public void testReset() {
try {
spf = SAXParserFactory.newInstance();
parser = spf.newSAXParser();
parser.setProperty(LEXICAL_HANDLER_PROPERTY, new MockHandler(new MethodLogger()));
parser.reset();
assertEquals(null, parser.getProperty(LEXICAL_HANDLER_PROPERTY));
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
}
use of tests.api.org.xml.sax.support.MethodLogger in project robovm by robovm.
the class SAXParserTest method testSetGetProperty.
public void testSetGetProperty() {
// Ordinary case
String validName = "http://xml.org/sax/properties/lexical-handler";
LexicalHandler validValue = new MockHandler(new MethodLogger());
try {
SAXParser parser = spf.newSAXParser();
parser.setProperty(validName, validValue);
assertEquals(validValue, parser.getProperty(validName));
parser.setProperty(validName, null);
assertEquals(null, parser.getProperty(validName));
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
// Unsupported property
try {
SAXParser parser = spf.newSAXParser();
parser.setProperty("foo", "bar");
fail("SAXNotRecognizedException expected");
} catch (SAXNotRecognizedException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
try {
SAXParser parser = spf.newSAXParser();
parser.getProperty("foo");
fail("SAXNotRecognizedException expected");
} catch (SAXNotRecognizedException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
// No name case
try {
SAXParser parser = spf.newSAXParser();
parser.setProperty(null, "bar");
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
try {
SAXParser parser = spf.newSAXParser();
parser.getProperty(null);
fail("NullPointerException expected");
} catch (NullPointerException e) {
// Expected
} catch (Exception e) {
throw new RuntimeException("Unexpected exception", e);
}
}
Aggregations