Skip to content
Browse files

Issue #75 - change Resource paths to be absolute.

change the android tests to use simpler process (no longer needs to use android Assets), instead us this.getClass().getResource(...). The same mechanism now works in Java an Android.
  • Loading branch information...
1 parent a5a1a75 commit c2c34d6b3d5935306d4c743e9044b1cc3c094024 @rolfl rolfl committed Apr 22, 2012
View
15 build.xml
@@ -354,21 +354,12 @@ For instructions on how to build JDOM, please view the README.txt file.
<java classname="org.jdom2.contrib.android.TranslateTests"
classpathref="at.class.path" >
<arg value="${package}/${jarbase}-junit.jar" />
- <arg value="${android}/${android.project}/assets" />
<arg value="${android}/${android.project}Test/src" />
</java>
-
- <mkdir dir="${android}/${android.project}Test/src/org/jdom2/test/util" />
- <copy todir="${android}/${android.project}Test/src/org/jdom2/test/util"
- file="test/android/AndroidFetch.java" />
-
- <!-- Create a Jar file with just the JUnit4 tests, not the resources. -->
- <jar jarfile="${android.libs}/${jarbase}-android-junit4.jar" >
- <fileset dir="${junit.build}" includes="**/*.class" />
- </jar>
-
+
<copy todir="${android.libs}">
- <fileset dir="${package}" includes="${jarbase}.jar, ${jarbase}-contrib.jar" />
+ <fileset dir="${package}"
+ includes="${jarbase}.jar, ${jarbase}-contrib.jar ${jarbase}-junit.jar" />
</copy>
<copy todir="${android.libs}" file="${jaxen.jar}"/>
View
39 contrib/src/java/org/jdom2/contrib/android/TranslateTests.java
@@ -1,10 +1,8 @@
package org.jdom2.contrib.android;
import java.io.File;
-import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -68,20 +66,12 @@ private static String potentialTest(String zename) {
* @throws IOException
*/
public static void main(String[] args) throws IOException {
- if (args.length != 3) {
- throw new IllegalArgumentException("Usage: Jar AssetOutDir SrcOutDir");
+ if (args.length != 2) {
+ throw new IllegalArgumentException("Usage: Jar SrcOutDir");
}
final String jarname = args[0];
- File assoutdir = new File(args[1]);
- if (!assoutdir.exists()) {
- assoutdir.mkdirs();
- }
- if (!assoutdir.isDirectory()) {
- throw new IllegalArgumentException("Could not create/use AssetOutput directory: " + assoutdir);
- }
-
- final File srcoutdir = new File(args[2]);
+ final File srcoutdir = new File(args[1]);
if (!srcoutdir.exists()) {
srcoutdir.mkdirs();
}
@@ -92,7 +82,6 @@ public static void main(String[] args) throws IOException {
final ArrayList<String> classes = new ArrayList<String>();
final ZipFile zfile = new ZipFile(jarname);
- StringBuilder assetnames = new StringBuilder();
try {
final Enumeration<? extends ZipEntry> e = zfile.entries();
while (e.hasMoreElements()) {
@@ -107,28 +96,8 @@ public static void main(String[] args) throws IOException {
TranslateTests tt = new TranslateTests(srcoutdir, classname);
classes.add(tt.translate());
}
- } else if (zename.indexOf("META-INF") < 0){
- // copy resources in to output folder with full path.
- System.out.println("Asset: " + zename);
- assetnames.append(zename).append("\n");
- final InputStream zis = zfile.getInputStream(ze);
- final File outfile = new File(assoutdir, zename);
- outfile.getParentFile().mkdirs();
- final FileOutputStream fos = new FileOutputStream(outfile);
- final byte[] buffer = new byte[4096];
- int len = 0;
- while ((len = zis.read(buffer)) >= 0) {
- fos.write(buffer, 0, len);
- }
- fos.flush();
- fos.close();
- zis.close();
}
}
- final FileWriter fw = new FileWriter(new File(assoutdir, "assetlist.txt"));
- fw.write(assetnames.toString());
- fw.flush();
- fw.close();
} finally {
zfile.close();
}
@@ -210,7 +179,6 @@ private String translate() throws IOException {
sb.append(" // tests run when class starts...\n");
sb.append(" System.setProperty(\"javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema\",\n");
sb.append(" \"org.apache.xerces.jaxp.validation.XMLSchemaFactory\");\n");
- sb.append(" org.jdom2.test.util.AndroidFetch.check(this.getContext());\n");
for (Method m : methods) {
if (m.getAnnotation(BeforeClass.class) != null) {
sb.append(" test.").append(m.getName()).append("();\n");
@@ -235,7 +203,6 @@ private String translate() throws IOException {
final String tname = getTestName(m);
sb.append("\n");
sb.append(" public void ").append(tname).append("()").append(buildThrows(excepts, m)).append("{\n");
- sb.append(" org.jdom2.test.util.AndroidFetch.check(this.getContext());\n");
for (Method pre : pretest) {
sb.append(" // pre test\n");
sb.append(" test.").append(pre.getName()).append("();\n");
View
129 test/android/AndroidFetch.java
@@ -1,129 +0,0 @@
-package org.jdom2.test.util;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.concurrent.atomic.AtomicReference;
-
-import android.content.Context;
-import android.content.res.AssetManager;
-import android.util.Log;
-
-/**
- * This class is a hack class that adapts the JDOM Unit test environment to work on android.
- * See the wiki page: https://github.com/hunterhacker/jdom/wiki/JDOM2-and-Android
- *
- * @author Rolf Lear
- *
- */
-public class AndroidFetch extends FidoFetch{
-
- private final AtomicReference<File> folder = new AtomicReference<File>();
-
- private void writeCache(File cf, byte[] data) throws IOException {
- final File d = cf.getParentFile();
- if (!d.exists()) {
- d.mkdirs();
- }
- final FileOutputStream fos = new FileOutputStream(cf);
- fos.write(data);
- fos.flush();
- fos.close();
- }
-
- private byte[] readAsset(AssetManager am, String name) throws IOException {
- final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final InputStream is = am.open(name);
- final byte[] buffer = new byte[2048];
- int len = 0;
- while ((len = is.read(buffer)) >= 0) {
- baos.write(buffer, 0, len);
- }
- is.close();
- return baos.toByteArray();
- }
-
- private String[] parseAssets(byte[] data) throws IOException {
- final BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data)));
- final ArrayList<String> al = new ArrayList<String>();
- String line = null;
- while ((line = br.readLine()) != null) {
- if (line.trim().length() > 0) {
- al.add(line.trim());
- }
- }
- return al.toArray(new String[al.size()]);
- }
-
-
- /**
- * @param o This should be a context object
- */
- public static final void check(Context o) {
- final FidoFetch ff = getFido();
- final AndroidFetch af = (AndroidFetch)ff;
- af.checkFolder(o);
-
- }
-
- private void checkFolder(Context ctx) {
- if (folder.get() == null) {
- // first time in....
-
- // OK, now set the cache folder.
- final File dir = new File(ctx.getCacheDir(), "jdomassets");
- if (!dir.exists()) {
- dir.mkdirs();
- }
-
- // Then, get the Asset Manager.
- final AssetManager am = ctx.getAssets();
-
- try {
-
- // we want the special asset 'assetlist.txt' which is created by the
- // JDOM 'android' build target, listing all the required assets.
- final String[] assets = parseAssets(readAsset(am, "assetlist.txt"));
- for (String asset : assets) {
- final byte[] data = readAsset(am, asset);
- final File f = new File(dir, asset);
- writeCache(f, data);
- Log.i("JDOM", "Transfer asset " + asset + " to cache.");
- }
- } catch (Exception e) {
- throw new IllegalStateException("Unable to transfer assets to " + dir, e);
- }
-
- folder.set(dir.getAbsoluteFile());
- }
- }
-
- @Override
- public URL getURL(String name) {
- try {
- final File f = new File(folder.get(), name);
- return f.toURI().toURL();
- } catch (Exception e) {
- throw new IllegalStateException("Unable to get resource " + name, e);
- }
- }
-
- @Override
- public InputStream getStream(String name) {
- try {
- final File f = new File(folder.get(), name);
- return new FileInputStream(f);
- } catch (Exception e) {
- throw new IllegalStateException("Unable to get resource " + name, e);
- }
- }
-
-}
View
12 test/src/java/org/jdom2/test/cases/input/TestDOMBuilder.java
@@ -43,32 +43,32 @@ public void testFactory() {
@Test
public void testSimpleDocument() {
- checkDOM("DOMBuilder/simple.xml", false);
+ checkDOM("/DOMBuilder/simple.xml", false);
}
@Test
public void testAttributesDocument() {
- checkDOM("DOMBuilder/attributes.xml", false);
+ checkDOM("/DOMBuilder/attributes.xml", false);
}
@Test
public void testNamespaceDocument() {
- checkDOM("DOMBuilder/namespaces.xml", false);
+ checkDOM("/DOMBuilder/namespaces.xml", false);
}
@Test
public void testDocTypeDocument() {
- checkDOM("DOMBuilder/doctype.xml", false);
+ checkDOM("/DOMBuilder/doctype.xml", false);
}
@Test
public void testComplexDocument() {
- checkDOM("DOMBuilder/complex.xml", false);
+ checkDOM("/DOMBuilder/complex.xml", false);
}
@Test
public void testXSDDocument() {
- checkDOM("xsdcomplex/input.xml", true);
+ checkDOM("/xsdcomplex/input.xml", true);
}
private void checkDOM(String resname, boolean xsdvalidate) {
View
10 test/src/java/org/jdom2/test/cases/input/TestSAXBuilder.java
@@ -675,7 +675,7 @@ public void testSetPropertyTwo() {
public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOException {
//test entity exansion on internal entity
- URL src = FidoFetch.getFido().getURL("SAXBuilderTestEntity.xml");
+ URL src = FidoFetch.getFido().getURL("/SAXBuilderTestEntity.xml");
SAXBuilder builder = new SAXBuilder();
@@ -701,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 = FidoFetch.getFido().getURL("SAXBuilderTestEntity2.xml");
+ URL src2 = FidoFetch.getFido().getURL("/SAXBuilderTestEntity2.xml");
builder.setExpandEntities(true);
assertTrue(builder.getExpandEntities());
@@ -738,7 +738,7 @@ public void test_TCU__DTDComments() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
//test entity expansion on external entity
- URL file = FidoFetch.getFido().getURL("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
@@ -764,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 = FidoFetch.getFido().getURL("SAXBuilderTestIntExtEntity.xml");
+ URL file = FidoFetch.getFido().getURL("/SAXBuilderTestIntExtEntity.xml");
builder.setExpandEntities(true);
Document doc = builder.build(file);
@@ -801,7 +801,7 @@ public void test_TCU__InternalSubset() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
//test entity expansion on internal subset
- URL file = FidoFetch.getFido().getURL("SAXBuilderTestEntity.xml");
+ URL file = FidoFetch.getFido().getURL("/SAXBuilderTestEntity.xml");
builder.setExpandEntities(true);
Document doc = builder.build(file);
View
4 test/src/java/org/jdom2/test/cases/input/TestSAXComplexSchema.java
@@ -46,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 = FidoFetch.getFido().getURL("xsdcomplex/input.xml");
+ URL rurl = FidoFetch.getFido().getURL("/xsdcomplex/input.xml");
try {
@@ -86,7 +86,7 @@ public void testBuildFileOldWay() throws IOException {
public void testBuildFileNewSAX() throws IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
- URL rurl = FidoFetch.getFido().getURL("xsdcomplex/input.xml");
+ URL rurl = FidoFetch.getFido().getURL("/xsdcomplex/input.xml");
try {
View
28 test/src/java/org/jdom2/test/cases/input/TestStAXEventBuilder.java
@@ -48,74 +48,74 @@ public void testFactory() {
@Test
public void testSimpleDocumentExpand() {
- checkStAX("DOMBuilder/simple.xml", true);
+ checkStAX("/DOMBuilder/simple.xml", true);
}
@Test
public void testAttributesDocumentExpand() {
- checkStAX("DOMBuilder/attributes.xml", true);
+ checkStAX("/DOMBuilder/attributes.xml", true);
}
@Test
public void testNamespaceDocumentExpand() {
- checkStAX("DOMBuilder/namespaces.xml", true);
+ checkStAX("/DOMBuilder/namespaces.xml", true);
}
@Test
@Ignore
// TODO
public void testDocTypeDocumentExpand() {
- checkStAX("DOMBuilder/doctype.xml", true);
+ checkStAX("/DOMBuilder/doctype.xml", true);
}
@Test
public void testDocTypeDocumentSimpleExpand() {
- checkStAX("DOMBuilder/doctypesimple.xml", true);
+ checkStAX("/DOMBuilder/doctypesimple.xml", true);
}
@Test
public void testComplexDocumentExpand() {
- checkStAX("DOMBuilder/complex.xml", true);
+ checkStAX("/DOMBuilder/complex.xml", true);
}
@Test
public void testXSDDocumentExpand() {
- checkStAX("xsdcomplex/input.xml", true);
+ checkStAX("/xsdcomplex/input.xml", true);
}
@Test
public void testSimpleDocument() {
- checkStAX("DOMBuilder/simple.xml", false);
+ checkStAX("/DOMBuilder/simple.xml", false);
}
@Test
public void testAttributesDocument() {
- checkStAX("DOMBuilder/attributes.xml", false);
+ checkStAX("/DOMBuilder/attributes.xml", false);
}
@Test
public void testNamespaceDocument() {
- checkStAX("DOMBuilder/namespaces.xml", false);
+ checkStAX("/DOMBuilder/namespaces.xml", false);
}
@Test
public void testDocTypeDocument() {
- checkStAX("DOMBuilder/doctype.xml", false);
+ checkStAX("/DOMBuilder/doctype.xml", false);
}
@Test
public void testDocTypeSimpleDocument() {
- checkStAX("DOMBuilder/doctypesimple.xml", false);
+ checkStAX("/DOMBuilder/doctypesimple.xml", false);
}
@Test
public void testComplexDocument() {
- checkStAX("DOMBuilder/complex.xml", false);
+ checkStAX("/DOMBuilder/complex.xml", false);
}
@Test
public void testXSDDocument() {
- checkStAX("xsdcomplex/input.xml", false);
+ checkStAX("/xsdcomplex/input.xml", false);
}
private void checkStAX(String resourcename, boolean expand) {
View
28 test/src/java/org/jdom2/test/cases/input/TestStAXStreamBuilder.java
@@ -49,74 +49,74 @@ public void testFactory() {
@Test
public void testSimpleDocumentExpand() {
- checkStAX("DOMBuilder/simple.xml", true);
+ checkStAX("/DOMBuilder/simple.xml", true);
}
@Test
public void testAttributesDocumentExpand() {
- checkStAX("DOMBuilder/attributes.xml", true);
+ checkStAX("/DOMBuilder/attributes.xml", true);
}
@Test
public void testNamespaceDocumentExpand() {
- checkStAX("DOMBuilder/namespaces.xml", true);
+ checkStAX("/DOMBuilder/namespaces.xml", true);
}
@Test
@Ignore
public void testDocTypeDocumentExpand() {
- checkStAX("DOMBuilder/doctype.xml", true);
+ checkStAX("/DOMBuilder/doctype.xml", true);
}
@Test
@Ignore
public void testDocTypeDocumentSimpleExpand() {
- checkStAX("DOMBuilder/doctypesimple.xml", true);
+ checkStAX("/DOMBuilder/doctypesimple.xml", true);
}
@Test
public void testComplexDocumentExpand() {
- checkStAX("DOMBuilder/complex.xml", true);
+ checkStAX("/DOMBuilder/complex.xml", true);
}
@Test
public void testXSDDocumentExpand() {
- checkStAX("xsdcomplex/input.xml", true);
+ checkStAX("/xsdcomplex/input.xml", true);
}
@Test
public void testSimpleDocument() {
- checkStAX("DOMBuilder/simple.xml", false);
+ checkStAX("/DOMBuilder/simple.xml", false);
}
@Test
public void testAttributesDocument() {
- checkStAX("DOMBuilder/attributes.xml", false);
+ checkStAX("/DOMBuilder/attributes.xml", false);
}
@Test
public void testNamespaceDocument() {
- checkStAX("DOMBuilder/namespaces.xml", false);
+ checkStAX("/DOMBuilder/namespaces.xml", false);
}
@Test
public void testDocTypeDocument() {
- checkStAX("DOMBuilder/doctype.xml", false);
+ checkStAX("/DOMBuilder/doctype.xml", false);
}
@Test
public void testDocTypeSimpleDocument() {
- checkStAX("DOMBuilder/doctypesimple.xml", false);
+ checkStAX("/DOMBuilder/doctypesimple.xml", false);
}
@Test
public void testComplexDocument() {
- checkStAX("DOMBuilder/complex.xml", false);
+ checkStAX("/DOMBuilder/complex.xml", false);
}
@Test
public void testXSDDocument() {
- checkStAX("xsdcomplex/input.xml", false);
+ checkStAX("/xsdcomplex/input.xml", false);
}
private void checkStAX(String resname, boolean expand) {
View
6 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSAX2Factory.java
@@ -77,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(FidoFetch.getFido().getURL("DOMBuilder/doctype.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/doctype.xml"));
assertEquals("root", doc.getRootElement().getName());
}
@@ -87,7 +87,7 @@ public void testParseValidateFails() {
assertTrue(fac.isValidating());
SAXBuilder builder = new SAXBuilder(fac);
try {
- builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
+ builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
UnitTestUtil.failNoException(JDOMException.class);
} catch (Exception e) {
UnitTestUtil.checkException(JDOMException.class, e);
@@ -99,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(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
assertEquals("root", doc.getRootElement().getName());
}
View
6 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSchemaFactory.java
@@ -29,7 +29,7 @@
public void testSchemaXMLReaderFactory() throws SAXException, JDOMException {
SchemaFactory schemafac =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("xsdcomplex/SAXTestComplexMain.xsd"));
+ Schema schema = schemafac.newSchema(FidoFetch.getFido().getURL("/xsdcomplex/SAXTestComplexMain.xsd"));
XMLReaderSchemaFactory readerfac = new XMLReaderSchemaFactory(schema);
assertTrue(readerfac.isValidating());
assertNotNull(readerfac.createXMLReader());
@@ -49,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(FidoFetch.getFido().getURL("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(FidoFetch.getFido().getURL("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.
View
10 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSingletons.java
@@ -24,15 +24,15 @@
public void testNonValidatingReader() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING);
assertFalse(builder.isValidating());
- Document doc = builder.build(FidoFetch.getFido().getURL("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(FidoFetch.getFido().getURL("DOMBuilder/doctype.xml"));
+ Document doc = builder.build(FidoFetch.getFido().getURL("/DOMBuilder/doctype.xml"));
assertEquals("root", doc.getRootElement().getName());
}
@@ -41,7 +41,7 @@ public void testDTDValidatingReaderFails() {
SAXBuilder builder = new SAXBuilder(XMLReaders.DTDVALIDATING);
assertTrue(builder.isValidating());
try {
- builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
+ builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
UnitTestUtil.failNoException(JDOMException.class);
} catch (Exception e) {
UnitTestUtil.checkException(JDOMException.class, e);
@@ -52,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(FidoFetch.getFido().getURL("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.
@@ -69,7 +69,7 @@ public void testXSDValidatingReaderFails() {
SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
assertTrue(builder.isValidating());
try {
- builder.build(FidoFetch.getFido().getURL("DOMBuilder/attributes.xml"));
+ builder.build(FidoFetch.getFido().getURL("/DOMBuilder/attributes.xml"));
UnitTestUtil.failNoException(JDOMException.class);
} catch (Exception e) {
UnitTestUtil.checkException(JDOMException.class, e);
View
8 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderXSDFactory.java
@@ -27,17 +27,17 @@
//"./test/resources/xscomplex/multi_one.xsd",
private final URL filemain() {
- return FidoFetch.getFido().getURL("xsdcomplex/multi_main.xsd");
+ return FidoFetch.getFido().getURL("/xsdcomplex/multi_main.xsd");
}
private final URL fileone() {
- return FidoFetch.getFido().getURL("xsdcomplex/multi_one.xsd");
+ return FidoFetch.getFido().getURL("/xsdcomplex/multi_one.xsd");
}
private final URL filetwo() {
- return FidoFetch.getFido().getURL("xsdcomplex/multi_two.xsd");
+ return FidoFetch.getFido().getURL("/xsdcomplex/multi_two.xsd");
}
private final URL source() {
- return FidoFetch.getFido().getURL("xsdcomplex/multi.xml");
+ return FidoFetch.getFido().getURL("/xsdcomplex/multi.xml");
}
private void checkXML(XMLReaderJDOMFactory fac) {
View
2 test/src/java/org/jdom2/test/cases/located/TestLocatedJDOMFactory.java
@@ -52,7 +52,7 @@ public void testLocation() throws JDOMException, IOException {
SAXBuilder sb = new SAXBuilder();
sb.setJDOMFactory(new LocatedJDOMFactory());
sb.setExpandEntities(false);
- Document doc = sb.build(FidoFetch.getFido().getURL("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();
View
2 test/src/java/org/jdom2/test/cases/special/TestIssue008ExpandEntity.java
@@ -18,7 +18,7 @@
public class TestIssue008ExpandEntity {
private final void roundTrip(boolean expand, boolean validating, String encoding, String expect) {
- String docloc = this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
+ String docloc = "/" + this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
URL docurl = FidoFetch.getFido().getURL(docloc);
if (docurl == null) {
View
2 test/src/java/org/jdom2/test/cases/xpath/TestXPathHepler.java
@@ -123,7 +123,7 @@ private static final void checkRelative(final NamespaceAware nsa, final Namespac
public void testComplex() throws JDOMException, IOException {
SAXBuilder sb = new SAXBuilder();
sb.setExpandEntities(false);
- Document doc = sb.build(FidoFetch.getFido().getURL("complex.xml"));
+ Document doc = sb.build(FidoFetch.getFido().getURL("/complex.xml"));
final Iterator<Content> des = doc.getDescendants();
final ArrayList<NamespaceAware> allc = new ArrayList<NamespaceAware>();
while (des.hasNext()) {
View
14 test/src/java/org/jdom2/test/util/FidoFetch.java
@@ -4,8 +4,6 @@
import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
-import org.jdom2.internal.ReflectionConstructor;
-
/**
* Android does not have a reliable ClassLoader.getResource() set of methods.
* We do a poor-man's hack that works on Android too.
@@ -22,15 +20,15 @@
* @return The URL to the name.
*/
public URL getURL(String name) {
- return ClassLoader.getSystemResource(name);
+ return this.getClass().getResource(name);
}
/**
* @param name The resource name to get.
* @return The Resource as a stream
*/
public InputStream getStream(String name) {
- return ClassLoader.getSystemResourceAsStream(name);
+ return this.getClass().getResourceAsStream(name);
}
private static final AtomicReference<FidoFetch> fetch = new AtomicReference<FidoFetch>();
@@ -42,11 +40,11 @@ public InputStream getStream(String name) {
public static final FidoFetch getFido() {
FidoFetch ret = fetch.get();
if (ret == null) {
- if ("Dalvik".equalsIgnoreCase(System.getProperty("java.vm.name", "junk"))) {
- ret = ReflectionConstructor.construct("org.jdom2.test.util.AndroidFetch", FidoFetch.class);
- } else {
+// if ("Dalvik".equalsIgnoreCase(System.getProperty("java.vm.name", "junk"))) {
+// ret = ReflectionConstructor.construct("org.jdom2.test.util.AndroidFetch", FidoFetch.class);
+// } else {
ret = new FidoFetch();
- }
+// }
fetch.set(ret);
}
return ret;

0 comments on commit c2c34d6

Please sign in to comment.
Something went wrong with that request. Please try again.