james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r938377 - in /james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim: FileBasedTest.java PerlDKIMTest.java
Date Tue, 27 Apr 2010 09:34:33 GMT
Author: bago
Date: Tue Apr 27 09:34:33 2010
New Revision: 938377

URL: http://svn.apache.org/viewvc?rev=938377&view=rev
Log:
make sure file based test suites run correctly in every environment (m2 reactor, m2 single
module, netbeans, eclipse..)

Modified:
    james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/FileBasedTest.java
    james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/PerlDKIMTest.java

Modified: james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/FileBasedTest.java
URL: http://svn.apache.org/viewvc/james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/FileBasedTest.java?rev=938377&r1=938376&r2=938377&view=diff
==============================================================================
--- james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/FileBasedTest.java (original)
+++ james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/FileBasedTest.java Tue Apr
27 09:34:33 2010
@@ -25,6 +25,8 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -38,7 +40,7 @@ public class FileBasedTest extends TestC
 
     private File file;
 
-    public FileBasedTest(String testName) {
+    public FileBasedTest(String testName) throws URISyntaxException {
         this(testName, FileBasedTestSuite.getFile(testName));
     }
 
@@ -250,33 +252,36 @@ public class FileBasedTest extends TestC
         }
     }
 
-    public static Test suite() throws IOException {
+    public static Test suite() throws IOException, URISyntaxException {
         return new FileBasedTestSuite();
     }
 
     static class FileBasedTestSuite extends TestSuite {
 
-        private static final File TESTS_FOLDER = new File(
-                "main\\src\\test\\resources\\org\\apache\\james\\jdkim\\corpus");
+        private static final String TESTS_FOLDER = "/org/apache/james/jdkim/corpus";
 
-        public FileBasedTestSuite() throws IOException {
-            super();
-            File dir = TESTS_FOLDER;
-            File[] files = dir.listFiles();
-
-            if (files != null)
-                for (int i = 0; i < files.length; i++) {
-                    File f = files[i];
-                    if (f.getName().toLowerCase().endsWith(".eml")) {
-                        addTest(new FileBasedTest(f.getName().substring(0,
-                                f.getName().length() - 4), f));
+        public FileBasedTestSuite() throws IOException, URISyntaxException {
+            URL resource = FileBasedTestSuite.class.getResource(TESTS_FOLDER);
+            if (resource != null) {
+                File dir = new File(resource.toURI());
+                File[] files = dir.listFiles();
+
+                if (files != null)
+                    for (int i = 0; i < files.length; i++) {
+                        File f = files[i];
+                        if (f.getName().toLowerCase().endsWith(".eml")) {
+                            addTest(new FileBasedTest(f.getName().substring(0,
+                                    f.getName().length() - 4), f));
+                        }
                     }
-                }
+            }
         }
 
-        public static File getFile(String name) {
-            return new File(TESTS_FOLDER.getAbsolutePath() + File.separator
-                    + name + ".eml");
+        public static File getFile(String name) throws URISyntaxException {
+            URL resource =  FileBasedTestSuite.class.getResource(TESTS_FOLDER + File.separator
+ name + ".eml");
+            if (resource != null) {
+                return new File(resource.toURI());
+            } else return null;
         }
 
     }

Modified: james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/PerlDKIMTest.java
URL: http://svn.apache.org/viewvc/james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/PerlDKIMTest.java?rev=938377&r1=938376&r2=938377&view=diff
==============================================================================
--- james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/PerlDKIMTest.java (original)
+++ james/jdkim/trunk/main/src/test/java/org/apache/james/jdkim/PerlDKIMTest.java Tue Apr
27 09:34:33 2010
@@ -25,6 +25,8 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URISyntaxException;
+import java.net.URL;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -41,7 +43,7 @@ public class PerlDKIMTest extends TestCa
     private File file;
     private MockPublicKeyRecordRetriever pkr;
 
-    public PerlDKIMTest(String testName) throws IOException {
+    public PerlDKIMTest(String testName) throws IOException, URISyntaxException {
         this(testName, PerlDKIMTestSuite.getFile(testName),
                 getPublicRecordRetriever());
     }
@@ -58,8 +60,7 @@ public class PerlDKIMTest extends TestCa
         MockPublicKeyRecordRetriever pkr = new MockPublicKeyRecordRetriever();
         BufferedReader fakeDNSlist = new BufferedReader(
                 new InputStreamReader(
-                        new FileInputStream(
-                                "main\\src\\test\\resources\\org\\apache\\james\\jdkim\\Mail-DKIM\\FAKE_DNS.dat")));
+                        PerlDKIMTest.class.getResourceAsStream("/org/apache/james/jdkim/Mail-DKIM/FAKE_DNS.dat")));
         String line;
         while ((line = fakeDNSlist.readLine()) != null) {
             if (!line.startsWith("#")) {
@@ -117,34 +118,37 @@ public class PerlDKIMTest extends TestCa
         }
     }
 
-    public static Test suite() throws IOException {
+    public static Test suite() throws IOException, URISyntaxException {
         return new PerlDKIMTestSuite();
     }
 
     static class PerlDKIMTestSuite extends TestSuite {
 
-        private static final File TESTS_FOLDER = new File(
-                "main\\src\\test\\resources\\org\\apache\\james\\jdkim\\Mail-DKIM\\corpus");
+        private static final String TESTS_FOLDER =  "/org/apache/james/jdkim/Mail-DKIM/corpus";
 
-        public PerlDKIMTestSuite() throws IOException {
-            super();
-            File dir = TESTS_FOLDER;
-            File[] files = dir.listFiles();
-
-            if (files != null)
-                for (int i = 0; i < files.length; i++) {
-                    File f = files[i];
-                    if (f.getName().toLowerCase().endsWith(".txt")) {
-                        addTest(new PerlDKIMTest(f.getName().substring(0,
-                                f.getName().length() - 4), f,
-                                getPublicRecordRetriever()));
+        public PerlDKIMTestSuite() throws IOException, URISyntaxException {
+            URL resource = PerlDKIMTestSuite.class.getResource(TESTS_FOLDER);
+            if (resource != null) {
+                File dir = new File(resource.toURI());
+                File[] files = dir.listFiles();
+
+                if (files != null)
+                    for (int i = 0; i < files.length; i++) {
+                        File f = files[i];
+                        if (f.getName().toLowerCase().endsWith(".txt")) {
+                            addTest(new PerlDKIMTest(f.getName().substring(0,
+                                    f.getName().length() - 4), f,
+                                    getPublicRecordRetriever()));
+                        }
                     }
-                }
+            }
         }
 
-        public static File getFile(String name) {
-            return new File(TESTS_FOLDER.getAbsolutePath() + File.separator
-                    + name + ".txt");
+        public static File getFile(String name) throws URISyntaxException {
+            URL resource =  PerlDKIMTestSuite.class.getResource(TESTS_FOLDER + File.separator
+ name + ".txt");
+            if (resource != null) {
+                return new File(resource.toURI());
+            } else return null;
         }
 
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message