Permalink
Browse files

Copy test resources to be part of the junit jar. No real point in hav…

…ing the unit test jar unless it has the working test resources. References to resources are now done through ClassLoader.getSystemResource*
  • Loading branch information...
1 parent 8f97ff9 commit c3c47b4dace9e5d4346313f96817233d46286751 @rolfl rolfl committed Apr 11, 2012
Showing with 113 additions and 109 deletions.
  1. +3 −0 build.xml
  2. +4 −2 test/src/java/org/jdom2/test/cases/input/HelpTestDOMBuilder.java
  3. +10 −10 test/src/java/org/jdom2/test/cases/input/TestDOMBuilder.java
  4. +10 −8 test/src/java/org/jdom2/test/cases/input/TestSAXBuilder.java
  5. +11 −9 test/src/java/org/jdom2/test/cases/input/TestSAXComplexSchema.java
  6. +19 −20 test/src/java/org/jdom2/test/cases/input/TestStAXEventBuilder.java
  7. +19 −23 test/src/java/org/jdom2/test/cases/input/TestStAXStreamBuilder.java
  8. +3 −3 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSAX2Factory.java
  9. +6 −5 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSchemaFactory.java
  10. +8 −7 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderSingletons.java
  11. +18 −18 test/src/java/org/jdom2/test/cases/input/sax/TestXMLReaderXSDFactory.java
  12. +1 −2 test/src/java/org/jdom2/test/cases/located/TestLocatedJDOMFactory.java
  13. +1 −2 test/src/java/org/jdom2/test/cases/xpath/TestXPathHepler.java
  14. 0 test/{ → src}/resources/DOMBuilder/attributes.xml
  15. 0 test/{ → src}/resources/DOMBuilder/attributesandchildren.xml
  16. 0 test/{ → src}/resources/DOMBuilder/complex.xml
  17. 0 test/{ → src}/resources/DOMBuilder/doctype.xml
  18. 0 test/{ → src}/resources/DOMBuilder/doctypesimple.xml
  19. 0 test/{ → src}/resources/DOMBuilder/namespaces.xml
  20. 0 test/{ → src}/resources/DOMBuilder/simple.xml
  21. 0 test/{ → src}/resources/SAXBuilderTestDecl.dtd
  22. 0 test/{ → src}/resources/SAXBuilderTestDecl.xml
  23. 0 test/{ → src}/resources/SAXBuilderTestEntity.dtd
  24. 0 test/{ → src}/resources/SAXBuilderTestEntity.xml
  25. 0 test/{ → src}/resources/SAXBuilderTestEntity2.xml
  26. 0 test/{ → src}/resources/SAXBuilderTestIntExtEntity.xml
  27. 0 test/{ → src}/resources/complex.xml
  28. 0 test/{ → src}/resources/test.dtd
  29. 0 test/{ → src}/resources/xmlchars.xml
  30. 0 test/{ → src}/resources/xsdcomplex/SAXTestComplexImport.xsd
  31. 0 test/{ → src}/resources/xsdcomplex/SAXTestComplexMain.xsd
  32. 0 test/{ → src}/resources/xsdcomplex/input.xml
  33. 0 test/{ → src}/resources/xsdcomplex/multi.xml
  34. 0 test/{ → src}/resources/xsdcomplex/multi_main.xsd
  35. 0 test/{ → src}/resources/xsdcomplex/multi_one.xsd
  36. 0 test/{ → src}/resources/xsdcomplex/multi_two.xsd
View
@@ -70,6 +70,7 @@ For instructions on how to build JDOM, please view the README.txt file.
<property name="junit" value="./test" />
<property name="junit.src" value="${junit}/src/java" />
+ <property name="junit.resources" value="${junit}/src/resources" />
<property name="junit.build" value="${build}/junit" />
<property name="junit.xml" value="${build}/junit.xml" />
<property name="junit.report" value="${build}/junit.report" />
@@ -250,6 +251,7 @@ For instructions on how to build JDOM, please view the README.txt file.
<!-- Copy resources and stuff - everything except Java code -->
<copy todir="${junit.build}" >
<fileset dir="${junit.src}" excludes="**/*.java" />
+ <fileset dir="${junit.resources}" />
</copy>
<!-- ignore deprecation warnings in jUnit -->
@@ -427,6 +429,7 @@ For instructions on how to build JDOM, please view the README.txt file.
<classpathentry kind="src" path="core/package"/>
<classpathentry kind="src" path="core/samples"/>
<classpathentry kind="src" path="test/src/java"/>
+ <classpathentry kind="src" path="test/src/resources"/>
<classpathentry kind="src" path="contrib/src/java" excluding="org/jdom/contrib/ids/doc-files/|org/jdom/contrib/input/scanner/doc-files/|org/jdom2/contrib/ids/doc-files/|org/jdom2/contrib/ids/doc-files/|org/jdom2/contrib/input/scanner/doc-files/|org/jdom2/contrib/input/scanner/doc-files/"/>
<classpathentry kind="src" path="contrib/samples"/>
<classpathentry kind="src" path="contrib/src/java/org/jdom2/contrib/ids/doc-files"/>
@@ -9,6 +9,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
@@ -21,7 +22,7 @@
@SuppressWarnings("javadoc")
public class HelpTestDOMBuilder {
- public static final Document getDocument(String filename, boolean xsdvalidate) throws ParserConfigurationException, SAXException, IOException {
+ public static final Document getDocument(String resname, boolean xsdvalidate) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(xsdvalidate);
@@ -31,7 +32,8 @@ public static final Document getDocument(String filename, boolean xsdvalidate) t
dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
}
DocumentBuilder db = dbf.newDocumentBuilder();
- return db.parse(filename);
+ InputSource is = new InputSource(ClassLoader.getSystemResource(resname).toExternalForm());
+ return db.parse(is);
}
public static final Element getRoot(Document doc) {
@@ -42,37 +42,37 @@ public void testFactory() {
@Test
public void testSimpleDocument() {
- checkDOM("test/resources/DOMBuilder/simple.xml", false);
+ checkDOM("DOMBuilder/simple.xml", false);
}
@Test
public void testAttributesDocument() {
- checkDOM("test/resources/DOMBuilder/attributes.xml", false);
+ checkDOM("DOMBuilder/attributes.xml", false);
}
@Test
public void testNamespaceDocument() {
- checkDOM("test/resources/DOMBuilder/namespaces.xml", false);
+ checkDOM("DOMBuilder/namespaces.xml", false);
}
@Test
public void testDocTypeDocument() {
- checkDOM("test/resources/DOMBuilder/doctype.xml", false);
+ checkDOM("DOMBuilder/doctype.xml", false);
}
@Test
public void testComplexDocument() {
- checkDOM("test/resources/DOMBuilder/complex.xml", false);
+ checkDOM("DOMBuilder/complex.xml", false);
}
@Test
public void testXSDDocument() {
- checkDOM("test/resources/xsdcomplex/input.xml", true);
+ checkDOM("xsdcomplex/input.xml", true);
}
- private void checkDOM(String filename, boolean xsdvalidate) {
+ private void checkDOM(String resname, boolean xsdvalidate) {
try {
- org.w3c.dom.Document domdoc = HelpTestDOMBuilder.getDocument(filename, xsdvalidate);
+ org.w3c.dom.Document domdoc = HelpTestDOMBuilder.getDocument(resname, xsdvalidate);
DOMBuilder db = new DOMBuilder();
Document dombuild = db.build(domdoc);
Element domroot = db.build(HelpTestDOMBuilder.getRoot(domdoc));
@@ -82,15 +82,15 @@ private void checkDOM(String filename, boolean xsdvalidate) {
: XMLReaders.NONVALIDATING );
sb.setExpandEntities(false);
- Document saxbuild = sb.build(filename);
+ Document saxbuild = sb.build(ClassLoader.getSystemResource(resname));
Element saxroot = saxbuild.hasRootElement() ? saxbuild.getRootElement() : null;
assertEquals(toString(saxbuild), toString(dombuild));
assertEquals(toString(saxroot), toString(domroot));
} catch (Exception e) {
e.printStackTrace();
- fail("Could not parse file '" + filename + "': " + e.getMessage());
+ fail("Could not parse file '" + resname + "': " + e.getMessage());
}
}
@@ -78,6 +78,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
import java.io.IOException;
import java.io.Reader;
import java.net.MalformedURLException;
+import java.net.URL;
import java.nio.CharBuffer;
import java.util.List;
import java.util.ResourceBundle;
@@ -680,14 +681,15 @@ public void testSetPropertyTwo() {
@Test
public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOException {
//test entity exansion on internal entity
+
+ URL src = ClassLoader.getSystemResource("SAXBuilderTestEntity.xml");
SAXBuilder builder = new SAXBuilder();
- File file = new File(resourceDir + "/SAXBuilderTestEntity.xml");
builder.setExpandEntities(true);
assertTrue(builder.getExpandEntities());
- Document doc = builder.build(file);
+ Document doc = builder.build(src);
assertTrue("didn't get entity text", doc.getRootElement().getText().indexOf("simple entity") == 0);
assertTrue("didn't get entity text", doc.getRootElement().getText().indexOf("another simple entity") > 1);
@@ -696,7 +698,7 @@ public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOE
builder.setExpandEntities(false);
assertFalse(builder.getExpandEntities());
- doc = builder.build(file);
+ doc = builder.build(src);
assertTrue("got entity text", ! (doc.getRootElement().getText().indexOf("simple entity") > 1));
assertTrue("got entity text", ! (doc.getRootElement().getText().indexOf("another simple entity") > 1));
List<Content> content = doc.getRootElement().getContent();
@@ -706,20 +708,20 @@ public void test_TCM__void_setExpandEntities_boolean() throws JDOMException, IOE
content.get(2) instanceof EntityRef);
//test entity expansion on external entity
- file = new File(resourceDir + "/SAXBuilderTestEntity2.xml");
+ URL src2 = ClassLoader.getSystemResource("SAXBuilderTestEntity2.xml");
builder.setExpandEntities(true);
assertTrue(builder.getExpandEntities());
- doc = builder.build(file);
+ doc = builder.build(src2);
assertTrue("didn't get entity text", doc.getRootElement().getText().indexOf("simple entity") == 0);
assertTrue("didn't get entity text", doc.getRootElement().getText().indexOf("another simple entity") > 1);
//test that entity declaration appears in doctype
//and EntityRef is created in content with external entity
builder.setExpandEntities(false);
assertFalse(builder.getExpandEntities());
- doc = builder.build(file);
+ doc = builder.build(src2);
assertTrue("got entity text", ! (doc.getRootElement().getText().indexOf("simple entity") > 1));
assertTrue("got entity text", ! (doc.getRootElement().getText().indexOf("another simple entity") > 1));
content = doc.getRootElement().getContent();
@@ -743,7 +745,7 @@ public void test_TCU__DTDComments() throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
//test entity expansion on external entity
- File file = new File(resourceDir + "/SAXBuilderTestDecl.xml");
+ URL file = ClassLoader.getSystemResource("SAXBuilderTestDecl.xml");
//test that entity declaration appears in doctype
//and EntityRef is created in content with external entity
@@ -769,7 +771,7 @@ public void test_TCU__InternalAndExternalEntities() throws JDOMException, IOExce
SAXBuilder builder = new SAXBuilder();
//test entity expansion on internal and external entity
- File file = new File(resourceDir + "/SAXBuilderTestIntExtEntity.xml");
+ URL file = ClassLoader.getSystemResource("SAXBuilderTestIntExtEntity.xml");
builder.setExpandEntities(true);
Document doc = builder.build(file);
@@ -3,17 +3,23 @@
*/
package org.jdom2.test.cases.input;
-import java.io.File;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.io.StringWriter;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;
-import static org.junit.Assert.*;
-import org.jdom2.*;
+import org.jdom2.Attribute;
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.JDOMException;
+import org.jdom2.Namespace;
import org.jdom2.input.SAXBuilder;
import org.jdom2.input.sax.XMLReaders;
import org.jdom2.output.Format;
@@ -39,9 +45,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);
- File inputdir = new File(".");
- URL furl = inputdir.toURI().toURL();
- URL rurl = new URL(furl, "test/resources/xsdcomplex/input.xml");
+ URL rurl = ClassLoader.getSystemResource("xsdcomplex/input.xml");
try {
@@ -81,9 +85,7 @@ public void testBuildFileOldWay() throws IOException {
public void testBuildFileNewSAX() throws IOException {
SAXBuilder builder = new SAXBuilder(XMLReaders.XSDVALIDATING);
- File inputdir = new File(".");
- URL furl = inputdir.toURI().toURL();
- URL rurl = new URL(furl, "test/resources/xsdcomplex/input.xml");
+ URL rurl = ClassLoader.getSystemResource("xsdcomplex/input.xml");
try {
@@ -7,9 +7,8 @@
import static org.junit.Assert.fail;
import java.io.CharArrayWriter;
-import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
@@ -48,101 +47,101 @@ public void testFactory() {
@Test
public void testSimpleDocumentExpand() {
- checkStAX("test/resources/DOMBuilder/simple.xml", true);
+ checkStAX("DOMBuilder/simple.xml", true);
}
@Test
public void testAttributesDocumentExpand() {
- checkStAX("test/resources/DOMBuilder/attributes.xml", true);
+ checkStAX("DOMBuilder/attributes.xml", true);
}
@Test
public void testNamespaceDocumentExpand() {
- checkStAX("test/resources/DOMBuilder/namespaces.xml", true);
+ checkStAX("DOMBuilder/namespaces.xml", true);
}
@Test
@Ignore
// TODO
public void testDocTypeDocumentExpand() {
- checkStAX("test/resources/DOMBuilder/doctype.xml", true);
+ checkStAX("DOMBuilder/doctype.xml", true);
}
@Test
public void testDocTypeDocumentSimpleExpand() {
- checkStAX("test/resources/DOMBuilder/doctypesimple.xml", true);
+ checkStAX("DOMBuilder/doctypesimple.xml", true);
}
@Test
public void testComplexDocumentExpand() {
- checkStAX("test/resources/DOMBuilder/complex.xml", true);
+ checkStAX("DOMBuilder/complex.xml", true);
}
@Test
public void testXSDDocumentExpand() {
- checkStAX("test/resources/xsdcomplex/input.xml", true);
+ checkStAX("xsdcomplex/input.xml", true);
}
@Test
public void testSimpleDocument() {
- checkStAX("test/resources/DOMBuilder/simple.xml", false);
+ checkStAX("DOMBuilder/simple.xml", false);
}
@Test
public void testAttributesDocument() {
- checkStAX("test/resources/DOMBuilder/attributes.xml", false);
+ checkStAX("DOMBuilder/attributes.xml", false);
}
@Test
public void testNamespaceDocument() {
- checkStAX("test/resources/DOMBuilder/namespaces.xml", false);
+ checkStAX("DOMBuilder/namespaces.xml", false);
}
@Test
public void testDocTypeDocument() {
- checkStAX("test/resources/DOMBuilder/doctype.xml", false);
+ checkStAX("DOMBuilder/doctype.xml", false);
}
@Test
public void testDocTypeSimpleDocument() {
- checkStAX("test/resources/DOMBuilder/doctypesimple.xml", false);
+ checkStAX("DOMBuilder/doctypesimple.xml", false);
}
@Test
public void testComplexDocument() {
- checkStAX("test/resources/DOMBuilder/complex.xml", false);
+ checkStAX("DOMBuilder/complex.xml", false);
}
@Test
public void testXSDDocument() {
- checkStAX("test/resources/xsdcomplex/input.xml", false);
+ checkStAX("xsdcomplex/input.xml", false);
}
- private void checkStAX(String filename, boolean expand) {
+ private void checkStAX(String resourcename, boolean expand) {
try {
StAXEventBuilder stxb = new StAXEventBuilder();
XMLInputFactory inputfac = XMLInputFactory.newInstance();
inputfac.setProperty(
"javax.xml.stream.isReplacingEntityReferences", Boolean.valueOf(expand));
inputfac.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE);
- FileReader eventsource = new FileReader(new File(filename));
+ InputStream eventsource = ClassLoader.getSystemResourceAsStream(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(filename);
+ Document saxbuild = sb.build(ClassLoader.getSystemResourceAsStream(resourcename));
Element saxroot = saxbuild.hasRootElement() ? saxbuild.getRootElement() : null;
assertEquals("DOC SAX to StAXEvent", toString(saxbuild), toString(eventbuild));
assertEquals("ROOT SAX to StAXEvent", toString(saxroot), toString(eventroot));
} catch (Exception e) {
e.printStackTrace();
- fail("Could not parse file '" + filename + "': " + e.getMessage());
+ fail("Could not parse resource '" + resourcename + "': " + e.getMessage());
}
}
Oops, something went wrong.

0 comments on commit c3c47b4

Please sign in to comment.