Permalink
Browse files

Issue #75 - Android.

Use new FidoFetch mechanism for getting test resources. This 'abstracts' the process so that it can be different between regular Java testing and Android testing.
  • Loading branch information...
1 parent 0816408 commit 2f695f368ee19edde049ee46fc6b19dfe5486de9 @rolfl rolfl committed Apr 19, 2012
@@ -12,6 +12,8 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.jdom2.test.util.FidoFetch;
+
/**
* This class encapsulates all the org.w3c.dom.DOM details, so that the actual
* TestDOMBuilder class has a cleaner import * setup with just
@@ -32,7 +34,7 @@ public static final Document getDocument(String resname, boolean xsdvalidate) th
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
}
DocumentBuilder db = dbf.newDocumentBuilder();
- InputSource is = new InputSource(ClassLoader.getSystemResource(resname).toExternalForm());
+ InputSource is = new InputSource(FidoFetch.getFido().getURL(resname).toExternalForm());
return db.parse(is);
}
@@ -18,6 +18,7 @@
import org.jdom2.input.sax.XMLReaders;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
import org.junit.Test;
@@ -82,7 +83,7 @@ private void checkDOM(String resname, boolean xsdvalidate) {
: XMLReaders.NONVALIDATING );
sb.setExpandEntities(false);
- Document saxbuild = sb.build(ClassLoader.getSystemResource(resname));
+ Document saxbuild = sb.build(FidoFetch.getFido().getURL(resname));
Element saxroot = saxbuild.hasRootElement() ? saxbuild.getRootElement() : null;
assertEquals(toString(saxbuild), toString(dombuild));
@@ -81,7 +81,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import java.net.URL;
import java.nio.CharBuffer;
import java.util.List;
-import java.util.ResourceBundle;
import org.junit.Assume;
import org.junit.Ignore;
@@ -114,6 +113,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import org.jdom2.input.sax.XMLReaders;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
+import org.jdom2.test.util.FidoFetch;
@SuppressWarnings("javadoc")
@@ -147,13 +147,6 @@ public XMLReader createParser() throws JDOMException {
}
}
- /**
- * the directory where needed resource files will be kept
- */
- private final String resourceDir =
- ResourceBundle.getBundle("org.jdom2.test.Test")
- .getString("test.resourceRoot");
-
@SuppressWarnings("deprecation")
@Test
public void testSAXBuilder() {
@@ -682,7 +675,7 @@ public void testSetPropertyTwo() {
public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOException {
//test entity exansion on internal entity
- URL src = ClassLoader.getSystemResource("SAXBuilderTestEntity.xml");
+ URL src = FidoFetch.getFido().getURL("SAXBuilderTestEntity.xml");
SAXBuilder builder = new SAXBuilder();
@@ -708,7 +701,7 @@ public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOE
content.get(2) instanceof EntityRef);
//test entity expansion on external entity
- URL src2 = ClassLoader.getSystemResource("SAXBuilderTestEntity2.xml");
+ URL src2 = FidoFetch.getFido().getURL("SAXBuilderTestEntity2.xml");
builder.setExpandEntities(true);
assertTrue(builder.getExpandEntities());
@@ -745,7 +738,7 @@ public void test_TCU__DTDComments() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
//test entity expansion on external entity
- URL file = ClassLoader.getSystemResource("SAXBuilderTestDecl.xml");
+ URL file = FidoFetch.getFido().getURL("SAXBuilderTestDecl.xml");
//test that entity declaration appears in doctype
//and EntityRef is created in content with external entity
@@ -771,7 +764,7 @@ public void test_TCU__InternalAndExternalEntities() throws JDOMException, IOExce
SAXBuilder builder = new SAXBuilder();
//test entity expansion on internal and external entity
- URL file = ClassLoader.getSystemResource("SAXBuilderTestIntExtEntity.xml");
+ URL file = FidoFetch.getFido().getURL("SAXBuilderTestIntExtEntity.xml");
builder.setExpandEntities(true);
Document doc = builder.build(file);
@@ -808,7 +801,7 @@ public void test_TCU__InternalSubset() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
//test entity expansion on internal subset
- File file = new File(resourceDir + "/SAXBuilderTestEntity.xml");
+ URL file = FidoFetch.getFido().getURL("SAXBuilderTestEntity.xml");
builder.setExpandEntities(true);
Document doc = builder.build(file);
@@ -24,6 +24,7 @@
import org.jdom2.input.sax.XMLReaders;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
+import org.jdom2.test.util.FidoFetch;
/**
@@ -45,7 +46,7 @@ public void testBuildFileOldWay() throws IOException {
builder.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
- URL rurl = ClassLoader.getSystemResource("xsdcomplex/input.xml");
+ URL rurl = FidoFetch.getFido().getURL("xsdcomplex/input.xml");
try {
@@ -85,7 +86,7 @@ public void testBuildFileOldWay() throws IOException {
public void testBuildFileNewSAX() throws IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
- URL rurl = ClassLoader.getSystemResource("xsdcomplex/input.xml");
+ URL rurl = FidoFetch.getFido().getURL("xsdcomplex/input.xml");
try {
@@ -24,6 +24,7 @@
import org.jdom2.input.StAXEventBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
@SuppressWarnings("javadoc")
@@ -125,15 +126,15 @@ private void checkStAX(String resourcename, boolean expand) {
"javax.xml.stream.isReplacingEntityReferences", Boolean.valueOf(expand));
inputfac.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE);
- InputStream eventsource = ClassLoader.getSystemResourceAsStream(resourcename);
+ InputStream eventsource = FidoFetch.getFido().getStream(resourcename);
XMLEventReader events = inputfac.createXMLEventReader(eventsource);
Document eventbuild = stxb.build(events);
Element eventroot = eventbuild.hasRootElement() ? eventbuild.getRootElement() : null;
SAXBuilder sb = new SAXBuilder();
sb.setExpandEntities(expand);
- Document saxbuild = sb.build(ClassLoader.getSystemResourceAsStream(resourcename));
+ Document saxbuild = sb.build(FidoFetch.getFido().getStream(resourcename));
Element saxroot = saxbuild.hasRootElement() ? saxbuild.getRootElement() : null;
assertEquals("DOC SAX to StAXEvent", toString(saxbuild), toString(eventbuild));
@@ -25,6 +25,7 @@
import org.jdom2.input.stax.DefaultStAXFilter;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
@SuppressWarnings("javadoc")
@@ -125,11 +126,11 @@ private void checkStAX(String resname, boolean expand) {
inputfac.setProperty(
"javax.xml.stream.isReplacingEntityReferences", Boolean.valueOf(expand));
inputfac.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE);
- XMLStreamReader reader = inputfac.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(resname));
+ XMLStreamReader reader = inputfac.createXMLStreamReader(FidoFetch.getFido().getStream(resname));
Document staxbuild = stxb.build(reader);
Element staxroot = staxbuild.hasRootElement() ? staxbuild.getRootElement() : null;
- XMLStreamReader fragreader = inputfac.createXMLStreamReader(ClassLoader.getSystemResourceAsStream(resname));
+ XMLStreamReader fragreader = inputfac.createXMLStreamReader(FidoFetch.getFido().getStream(resname));
List<Content> contentlist = stxb.buildFragments(fragreader, new DefaultStAXFilter());
Document fragbuild = new Document();
fragbuild.addContent(contentlist);
@@ -138,7 +139,7 @@ private void checkStAX(String resname, boolean expand) {
SAXBuilder sb = new SAXBuilder();
sb.setExpandEntities(expand);
- Document saxbuild = sb.build(ClassLoader.getSystemResource(resname));
+ Document saxbuild = sb.build(FidoFetch.getFido().getURL(resname));
Element saxroot = saxbuild.hasRootElement() ? saxbuild.getRootElement() : null;
assertEquals("DOC SAX to StAXReader", toString(saxbuild), toString(staxbuild));
@@ -11,6 +11,7 @@
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaderSAX2Factory;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
@SuppressWarnings("javadoc")
@@ -76,7 +77,7 @@ public void testParseValidateWorks() throws JDOMException, IOException {
XMLReaderSAX2Factory fac = new XMLReaderSAX2Factory(true);
assertTrue(fac.isValidating());
SAXBuilder builder = new SAXBuilder(fac);
- Document doc = builder.build(ClassLoader.getSystemResource("DOMBuilder/doctype.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/doctype.xml"));
assertEquals("root", doc.getRootElement().getName());
}
@@ -86,7 +87,7 @@ public void testParseValidateFails() {
assertTrue(fac.isValidating());
SAXBuilder builder = new SAXBuilder(fac);
try {
- builder.build(ClassLoader.getSystemResource("DOMBuilder/attributes.xml"));
+ builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
UnitTestUtil.failNoException(JDOMException.class);
} catch (Exception e) {
UnitTestUtil.checkException(JDOMException.class, e);
@@ -98,7 +99,7 @@ public void testParseNonValidateWorks() throws JDOMException, IOException {
XMLReaderSAX2Factory fac = new XMLReaderSAX2Factory(false);
assertFalse(fac.isValidating());
SAXBuilder builder = new SAXBuilder(fac);
- Document doc = builder.build(ClassLoader.getSystemResource("DOMBuilder/attributes.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
assertEquals("root", doc.getRootElement().getName());
}
@@ -19,6 +19,7 @@
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaderSchemaFactory;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
@SuppressWarnings("javadoc")
@@ -28,7 +29,7 @@
public void testSchemaXMLReaderFactory() throws SAXException, JDOMException {
SchemaFactory schemafac =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = schemafac.newSchema(ClassLoader.getSystemResource("xsdcomplex/SAXTestComplexMain.xsd"));
+ Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("xsdcomplex/SAXTestComplexMain.xsd"));
XMLReaderSchemaFactory readerfac = new XMLReaderSchemaFactory(schema);
assertTrue(readerfac.isValidating());
assertNotNull(readerfac.createXMLReader());
@@ -48,11 +49,11 @@ public void testSchemaXMLReaderFactoryNull() {
public void testParseValidateWorks() throws JDOMException, IOException, SAXException {
SchemaFactory schemafac =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = schemafac.newSchema(ClassLoader.getSystemResource("xsdcomplex/SAXTestComplexMain.xsd"));
+ Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("xsdcomplex/SAXTestComplexMain.xsd"));
XMLReaderSchemaFactory readerfac = new XMLReaderSchemaFactory(schema);
assertTrue(readerfac.isValidating());
SAXBuilder builder = new SAXBuilder(readerfac);
- Document doc = builder.build(ClassLoader.getSystemResource("xsdcomplex/input.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("xsdcomplex/input.xml"));
assertEquals("test", doc.getRootElement().getName());
// the whole point of this particular XML input is that it should apply
// default attribute values.... lets make sure they make it.
@@ -14,6 +14,7 @@
import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaders;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
@SuppressWarnings("javadoc")
@@ -23,15 +24,15 @@
public void testNonValidatingReader() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
assertFalse(builder.isValidating());
- Document doc = builder.build(ClassLoader.getSystemResource("DOMBuilder/attributes.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
assertEquals("root", doc.getRootElement().getName());
}
@Test
public void testDTDValidatingReader() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING);
assertTrue(builder.isValidating());
- Document doc = builder.build(ClassLoader.getSystemResource("DOMBuilder/doctype.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("DOMBuilder/doctype.xml"));
assertEquals("root", doc.getRootElement().getName());
}
@@ -40,7 +41,7 @@ public void testDTDValidatingReaderFails() {
SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING);
assertTrue(builder.isValidating());
try {
- builder.build(ClassLoader.getSystemResource("DOMBuilder/attributes.xml"));
+ builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
UnitTestUtil.failNoException(JDOMException.class);
} catch (Exception e) {
UnitTestUtil.checkException(JDOMException.class, e);
@@ -51,7 +52,7 @@ public void testDTDValidatingReaderFails() {
public void testXSDValidatingReader() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
assertTrue(builder.isValidating());
- Document doc = builder.build(ClassLoader.getSystemResource("xsdcomplex/input.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("xsdcomplex/input.xml"));
assertEquals("test", doc.getRootElement().getName());
// the whole point of this particular XML input is that it should apply
// default attribute values.... lets make sure they make it.
@@ -68,7 +69,7 @@ public void testXSDValidatingReaderFails() {
SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
assertTrue(builder.isValidating());
try {
- builder.build(ClassLoader.getSystemResource("DOMBuilder/attributes.xml"));
+ builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
UnitTestUtil.failNoException(JDOMException.class);
} catch (Exception e) {
UnitTestUtil.checkException(JDOMException.class, e);
@@ -19,16 +19,17 @@
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaderJDOMFactory;
import org.jdom2.input.sax.XMLReaderXSDFactory;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.test.util.UnitTestUtil;
@SuppressWarnings("javadoc")
public class TestXMLReaderXSDFactory {
//"./test/resources/xscomplex/multi_one.xsd",
- URL filemain = ClassLoader.getSystemResource("xsdcomplex/multi_main.xsd");
- URL fileone = ClassLoader.getSystemResource("xsdcomplex/multi_one.xsd");
- URL filetwo = ClassLoader.getSystemResource("xsdcomplex/multi_two.xsd");
- URL source = ClassLoader.getSystemResource("xsdcomplex/multi.xml");
+ URL filemain = FidoFetch.getFido().getURL("xsdcomplex/multi_main.xsd");
+ URL fileone = FidoFetch.getFido().getURL("xsdcomplex/multi_one.xsd");
+ URL filetwo = FidoFetch.getFido().getURL("xsdcomplex/multi_two.xsd");
+ URL source = FidoFetch.getFido().getURL("xsdcomplex/multi.xml");
private void checkXML(XMLReaderJDOMFactory fac) {
SAXBuilder builder = new SAXBuilder(fac);
@@ -18,6 +18,7 @@
import org.jdom2.located.Located;
import org.jdom2.located.LocatedJDOMFactory;
import org.jdom2.test.cases.AbstractTestJDOMFactory;
+import org.jdom2.test.util.FidoFetch;
import org.jdom2.xpath.XPathFactory;
@SuppressWarnings("javadoc")
@@ -51,7 +52,7 @@ public void testLocation() throws JDOMException, IOException {
SAXBuilder sb = new SAXBuilder();
sb.setJDOMFactory(new LocatedJDOMFactory());
sb.setExpandEntities(false);
- Document doc = sb.build(ClassLoader.getSystemResource("complex.xml"));
+ Document doc = sb.build(FidoFetch.getFido().getURL("complex.xml"));
// it appears the location of the DocType is the start of the internal subset.
checkLocation(doc.getDocType(), 2, 16);
final Element root = doc.getRootElement();
@@ -368,16 +368,18 @@ public void testOutputAttribute() throws JDOMException {
assertEquals("name", doma.getNodeName());
assertEquals("name", doma.getLocalName());
assertEquals("val", doma.getNodeValue());
- assertEquals(null, doma.getPrefix());
- assertEquals(null, doma.getNamespaceURI());
+ // Android can have "" values, xerces has null. Technically it is implementation dependant
+ assertTrue(null == doma.getPrefix() || "".equals(doma.getPrefix()));
+ // Android can have "" values, xerces has null. Technically it is implementation dependant
+ assertTrue(null == doma.getNamespaceURI() || "".equals(doma.getNamespaceURI()));
assertTrue(domdoc != doma.getOwnerDocument());
doma = out.output(domdoc, att);
assertEquals("name", doma.getNodeName());
assertEquals("name", doma.getLocalName());
assertEquals("val", doma.getNodeValue());
- assertEquals(null, doma.getPrefix());
- assertEquals(null, doma.getNamespaceURI());
+ assertTrue(null == doma.getPrefix() || "".equals(doma.getPrefix()));
+ assertTrue(null == doma.getNamespaceURI() || "".equals(doma.getNamespaceURI()));
assertTrue(domdoc == doma.getOwnerDocument());
att = new Attribute("name", "val", Namespace.getNamespace("ns", "http://jdom.org/junit/ns"));
@@ -10,14 +10,16 @@
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
+import org.jdom2.test.util.FidoFetch;
+
import org.junit.Test;
@SuppressWarnings("javadoc")
public class TestIssue008ExpandEntity {
private final void roundTrip(boolean expand, boolean validating, String encoding, String expect) {
String docloc = this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
- URL docurl = ClassLoader.getSystemResource(docloc);
+ URL docurl = FidoFetch.getFido().getURL(docloc);
if (docurl == null) {
throw new IllegalStateException("Unable to get resource " + docloc);
Oops, something went wrong.

0 comments on commit 2f695f3

Please sign in to comment.