This change moves the code for reading xml files off of disk into a
common base class for the parser tests, and makes the
AtomConformanceTest and FeedParserTest use the new base class.

Note that for this to work, you also need to rename some of the
resources in parser/src/test/resources, they now need to live in
directories that match the name of their original home on the net.

For example, the files that currently live in resources/conformance
are really from www.snellspace.com/public, so they get moved to
resources/www.snellspace.com/public.  Similarly, the ones in
resources/feedparser get moved to
resources/www.feedparser.org/tests/welformed/atom10.  I didn't include
this in the diff because if you apply that sort of patch it'll give
you the removal but not the add, since diffs don't hold rename
operations.

There's also a follow up patch for this that does the same stuff for
the feed validator tests, but well, it's really huge, so I split it
out, and I'm also waiting on some license questions from the feed
validator guys.

-garrett

[[[
Move code for reading xml files off of disk into a common base class.

[ in parser/src/java/org/apache/abdera/test/parser/stax ]

* BaseParserTestCase.java: New file.

* AtomConformanceTest.java
 Extend BaseParserTestCase.
 (parse): Removed.
 (testContentTypes, testOrder, testLink): Don't call .toString() on our
  URI.

* FeedParserTest.java
 Extend BaseParserTestCase.
 (parse): Removed.
 (baseURI): New member.
 (setUp): New method, initializes baseURI.
 (testAtom10Namespace, testEntryAuthorEmail, testEntryAuthorName,
  testEntryContentBase64, testEntryContentBase642): Use our baseURI to
  resolve the actual URI, and pass it to parse.
]]]
Index: 
parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTest.java
===================================================================
--- 
parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTest.java
    (revision 416043)
+++ 
parser/src/test/java/org/apache/abdera/test/parser/stax/AtomConformanceTest.java
    (working copy)
@@ -36,31 +36,22 @@
 
 import junit.framework.TestCase;
 
-public class AtomConformanceTest extends TestCase {
+public class AtomConformanceTest extends BaseParserTestCase {
 
-  private static Document<Feed> parse(String uri) {
-    try {
-      String path = "/conformance/" + uri.substring(uri.lastIndexOf('/'));
-      InputStream stream = AtomConformanceTest.class.getResourceAsStream(path);
-      return Parser.INSTANCE.parse(stream, uri);
-    } catch (Exception e) {}
-    return null;
-  }
-
   private static Document<Feed> get(URI uri) {
     try {
       return Parser.INSTANCE.parse(uri.toURL().openStream(), uri);
     } catch (Exception e) {}
     return null;
   }
-  
+
   /**
    * Test to make sure that the parser properly detects the various kinds of
    * extended content types allowed by Atom
    */
   public static void testContentTypes() throws Exception {
     URI uri = new URI("http://www.snellspace.com/public/contentsummary.xml";);
-    Document<Feed> doc = parse(uri.toString());
+    Document<Feed> doc = parse(uri);
     Feed feed = doc.getRoot();
     int n = 1;
     for (Entry entry : feed.getEntries()) {
@@ -328,7 +319,7 @@
   public static void testOrder() throws Exception {
     //http://www.snellspace.com/public/ordertest.xml
     URI uri = new URI("http://www.snellspace.com/public/ordertest.xml";);
-    Document<Feed> doc = parse(uri.toString());
+    Document<Feed> doc = parse(uri);
     assertNotNull(doc);
     Feed feed = doc.getRoot();
     List<Entry> entries = feed.getEntries();
@@ -423,7 +414,7 @@
   public static void testLink() throws Exception {
     //http://www.snellspace.com/public/linktests.xml
     URI uri = new URI("http://www.snellspace.com/public/linktests.xml";);
-    Document<Feed> doc = parse(uri.toString());
+    Document<Feed> doc = parse(uri);
     assertNotNull(doc);
     Feed feed = doc.getRoot();
     List<Entry> entries = feed.getEntries();
Index: 
parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java
===================================================================
--- 
parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java 
    (revision 0)
+++ 
parser/src/test/java/org/apache/abdera/test/parser/stax/BaseParserTestCase.java 
    (revision 0)
@@ -0,0 +1,42 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.test.parser.stax;
+
+import junit.framework.TestCase;
+
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.parser.Parser;
+
+import java.io.InputStream;
+import java.net.URI;
+
+public abstract class BaseParserTestCase extends TestCase {
+
+  protected static <T extends Element>Document<T> parse(URI uri) {
+    try {
+      String uriStr = uri.toString();
+      String path = uriStr.substring(uriStr.indexOf("//") + 1);
+      InputStream stream = BaseParserTestCase.class.getResourceAsStream(path);
+      return Parser.INSTANCE.parse(stream, uri);
+    } catch (Exception e) {}
+    return null;
+  }
+
+}
Index: 
parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTest.java
===================================================================
--- parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTest.java 
(revision 416043)
+++ parser/src/test/java/org/apache/abdera/test/parser/stax/FeedParserTest.java 
(working copy)
@@ -20,6 +20,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.net.URI;
 
 import javax.activation.DataHandler;
 
@@ -33,24 +34,21 @@
 
 import junit.framework.TestCase;
 
-public class FeedParserTest extends TestCase {
+public class FeedParserTest extends BaseParserTestCase {
 
-  private static Document<Feed> parse(String name) {
-    try {
-      String path = "/feedparser/" + name;
-      InputStream stream = FeedParserTest.class.getResourceAsStream(path);
-      return Parser.INSTANCE.parse(stream);
-    } catch (Exception e) {}
-    return null;
+  static URI baseURI;
+
+  protected void setUp() throws Exception {
+    baseURI = new URI("http://www.feedparser.org/tests/wellformed/atom10/";);
   }
-  
+
   public void testAtom10Namespace() throws Exception {
-    Document doc = parse("atom10_namespace.xml");
+    Document doc = parse(baseURI.resolve("atom10_namespace.xml"));
     assertNotNull(doc);
   }
   
   public void testEntryAuthorEmail() throws Exception {
-    Document doc = parse("entry_author_email.xml");
+    Document doc = parse(baseURI.resolve("entry_author_email.xml"));
     Feed feed = (Feed) doc.getRoot();
     Entry entry = feed.getEntries().get(0);
     Person person = entry.getAuthor();
@@ -58,7 +56,7 @@
   }
   
   public void testEntryAuthorName() throws Exception {
-    Document doc = parse("entry_author_name.xml");
+    Document doc = parse(baseURI.resolve("entry_author_name.xml"));
     Feed feed = (Feed) doc.getRoot();
     Entry entry = feed.getEntries().get(0);
     Person person = entry.getAuthor();
@@ -66,7 +64,7 @@
   }
   
   public void testEntryContentBase64() throws Exception {
-    Document doc = parse("entry_content_base64.xml");
+    Document doc = parse(baseURI.resolve("entry_content_base64.xml"));
     Feed feed = (Feed)doc.getRoot();
     Entry entry = feed.getEntries().get(0);
     Content mediaContent = entry.getContentElement();
@@ -80,7 +78,7 @@
   }
   
   public void testEntryContentBase642() throws Exception {
-    Document doc = parse("entry_content_base64_2.xml");
+    Document doc = parse(baseURI.resolve("entry_content_base64_2.xml"));
     Feed feed = (Feed)doc.getRoot();
     Entry entry = feed.getEntries().get(0);
     Content mediaContent = entry.getContentElement();
Index: build/build.xml
===================================================================
--- build/build.xml     (revision 416005)
+++ build/build.xml     (working copy)
@@ -102,23 +102,11 @@
               destdir="${test}"
               classpathref="jar.dependencies"
               classpath="${core.work};${parser.work}" />
-       <copy todir="${test}">
-         <fileset dir="${parser.test.resources}">
-           <include name="*.xml"/>
-         </fileset>
-       </copy>
-        <mkdir dir="${test}/feedparser" />
-        <copy todir="${test}/feedparser">
-         <fileset dir="${parser.test.resources}/feedparser">
-           <include name="*.xml"/>
-         </fileset>
-       </copy>
-        <mkdir dir="${test}/conformance" />
-        <copy todir="${test}/conformance">
-         <fileset dir="${parser.test.resources}/conformance">
-           <include name="*.xml"/>
-         </fileset>
-       </copy>
+    <copy todir="${test}">
+      <fileset dir="${parser.test.resources}">
+        <include name="**"/>
+      </fileset>
+    </copy>
   </target>
        
   <target name="compile.server" depends="init, compile.core">

Reply via email to