Author: nick
Date: Fri Jul 15 14:44:55 2011
New Revision: 1147167

URL: http://svn.apache.org/viewvc?rev=1147167&view=rev
Log:
TIKA-683 New TikaTest parent class for tests (which RTF test will shortly use)

Added:
    tika/trunk/tika-parsers/src/test/java/org/apache/tika/TikaTest.java
Modified:
    tika/trunk/tika-parsers/src/test/java/org/apache/tika/TestParsers.java
    
tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/prt/PRTParserTest.java

Modified: tika/trunk/tika-parsers/src/test/java/org/apache/tika/TestParsers.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/TestParsers.java?rev=1147167&r1=1147166&r2=1147167&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/test/java/org/apache/tika/TestParsers.java 
(original)
+++ tika/trunk/tika-parsers/src/test/java/org/apache/tika/TestParsers.java Fri 
Jul 15 14:44:55 2011
@@ -16,7 +16,10 @@
  */
 package org.apache.tika;
 
-import junit.framework.TestCase;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
 import org.apache.tika.config.TikaConfig;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.mime.MediaType;
@@ -24,16 +27,10 @@ import org.apache.tika.parser.Parser;
 import org.apache.tika.utils.ParseUtils;
 import org.xml.sax.helpers.DefaultHandler;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.net.URISyntaxException;
-import java.net.URL;
-
 /**
  * Junit test class for Tika {@link Parser}s.
  */
-public class TestParsers extends TestCase {
+public class TestParsers extends TikaTest {
 
     private TikaConfig tc;
 
@@ -216,31 +213,4 @@ public class TestParsers extends TestCas
         Parser parser = tc.getParser(MediaType.parse("audio/mpeg"));
         assertNotNull(parser);
     }
-
-    /**
-     * This method will give you back the filename incl. the absolute path name
-     * to the resource. If the resource does not exist it will give you back 
the
-     * resource name incl. the path.
-     * 
-     * @param name
-     *            The named resource to search for.
-     * @return an absolute path incl. the name which is in the same directory 
as
-     *         the the class you've called it from.
-     */
-    public File getResourceAsFile(String name) throws URISyntaxException {
-        URL url = this.getClass().getResource(name);
-        if (url != null) {
-            return new File(url.toURI());
-        } else {
-            // We have a file which does not exists
-            // We got the path
-            url = this.getClass().getResource(".");
-            return new File(new File(url.toURI()), name);
-        }
-    }
-
-    public InputStream getResourceAsStream(String name) {
-        return this.getClass().getResourceAsStream(name);
-    }
-
 }

Added: tika/trunk/tika-parsers/src/test/java/org/apache/tika/TikaTest.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/TikaTest.java?rev=1147167&view=auto
==============================================================================
--- tika/trunk/tika-parsers/src/test/java/org/apache/tika/TikaTest.java (added)
+++ tika/trunk/tika-parsers/src/test/java/org/apache/tika/TikaTest.java Fri Jul 
15 14:44:55 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.tika;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+/**
+ * Parent class of Tika tests
+ */
+public abstract class TikaTest extends TestCase {
+   /**
+    * This method will give you back the filename incl. the absolute path name
+    * to the resource. If the resource does not exist it will give you back the
+    * resource name incl. the path.
+    * 
+    * @param name
+    *            The named resource to search for.
+    * @return an absolute path incl. the name which is in the same directory as
+    *         the the class you've called it from.
+    */
+   public File getResourceAsFile(String name) throws URISyntaxException {
+       URL url = this.getClass().getResource(name);
+       if (url != null) {
+           return new File(url.toURI());
+       } else {
+           // We have a file which does not exists
+           // We got the path
+           url = this.getClass().getResource(".");
+           File file = new File(new File(url.toURI()), name);
+           if (file == null) {
+              fail("Unable to find requested file " + name);
+           }
+           return file;
+       }
+   }
+
+   public InputStream getResourceAsStream(String name) {
+       InputStream stream = this.getClass().getResourceAsStream(name);
+       if (stream == null) {
+          fail("Unable to find requested resource " + name);
+       }
+       return stream;
+   }
+    
+    public void assertContains(String needle, String haystack) {
+       assertTrue(needle + " not found in:\n" + haystack, 
haystack.contains(needle));
+    }
+}

Modified: 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/prt/PRTParserTest.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/prt/PRTParserTest.java?rev=1147167&r1=1147166&r2=1147167&view=diff
==============================================================================
--- 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/prt/PRTParserTest.java
 (original)
+++ 
tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/prt/PRTParserTest.java
 Fri Jul 15 14:44:55 2011
@@ -18,19 +18,17 @@ package org.apache.tika.parser.prt;
 
 import java.io.InputStream;
 
-import junit.framework.TestCase;
-
+import org.apache.tika.TikaTest;
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.sax.BodyContentHandler;
 import org.xml.sax.ContentHandler;
 
-public class PRTParserTest extends TestCase {
+public class PRTParserTest extends TikaTest {
     /**
      * Try with a simple file
      */
     public void testPRTParserBasics() throws Exception {
-       InputStream input = PRTParserTest.class.getResourceAsStream(
-             "/test-documents/testCADKEY.prt");
+       InputStream input = 
getResourceAsStream("/test-documents/testCADKEY.prt");
        try  {
           Metadata metadata = new Metadata();
           ContentHandler handler = new BodyContentHandler();
@@ -68,8 +66,7 @@ public class PRTParserTest extends TestC
      * Now a more complex one
      */
     public void testPRTParserComplex() throws Exception {
-       InputStream input = PRTParserTest.class.getResourceAsStream(
-             "/test-documents/testCADKEY2.prt");
+       InputStream input = 
getResourceAsStream("/test-documents/testCADKEY2.prt");
        try  {
           Metadata metadata = new Metadata();
           ContentHandler handler = new BodyContentHandler();
@@ -113,8 +110,4 @@ public class PRTParserTest extends TestC
           input.close();
        }
     }
-    
-    public void assertContains(String needle, String haystack) {
-       assertTrue(needle + " not found in:\n" + haystack, 
haystack.contains(needle));
-    }
 }


Reply via email to