Author: bago
Date: Sun Dec 27 18:50:13 2009
New Revision: 894094
URL: http://svn.apache.org/viewvc?rev=894094&view=rev
Log:
Alter the multi-file testsuite to use classpath lookup instead of source
reference. This make tests work out of the box in a maven imported eclipse
(multiple module in single project) while keeping the behaviour in standard
maven. Also this is much better as it does not references the source location
for files while refers it using the final test-classes package name.
Modified:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
Modified:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java?rev=894094&r1=894093&r2=894094&view=diff
==============================================================================
---
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
(original)
+++
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/ExampleMessagesRoundtripTest.java
Sun Dec 27 18:50:13 2009
@@ -19,21 +19,22 @@
package org.apache.james.mime4j.message;
-import org.apache.james.mime4j.codec.CodecUtil;
-import org.apache.james.mime4j.parser.MimeEntityConfig;
-import org.apache.log4j.BasicConfigurator;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.URISyntaxException;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.james.mime4j.codec.CodecUtil;
+import org.apache.james.mime4j.parser.MimeEntityConfig;
+import org.apache.log4j.BasicConfigurator;
+
/**
* Creates a TestSuite running the test for each .msg file in the test resouce
folder.
* Allow running of a single test from Unit testing GUIs
@@ -43,7 +44,7 @@
private File file;
- public ExampleMessagesRoundtripTest(String testName) {
+ public ExampleMessagesRoundtripTest(String testName) throws
URISyntaxException {
this(testName, ExampleMessagesRountripTestSuite.getFile(testName));
}
@@ -82,18 +83,18 @@
}
}
- public static Test suite() throws IOException {
+ public static Test suite() throws IOException, URISyntaxException {
return new ExampleMessagesRountripTestSuite();
}
static class ExampleMessagesRountripTestSuite extends TestSuite {
- private static final File TESTS_FOLDER = new
File("src/test/resources/testmsgs");
+ private static final String TESTS_FOLDER = "/testmsgs";
- public ExampleMessagesRountripTestSuite() throws IOException {
+ public ExampleMessagesRountripTestSuite() throws IOException,
URISyntaxException {
super();
- File dir = TESTS_FOLDER;
+ File dir = new
File(ExampleMessagesRountripTestSuite.class.getResource(TESTS_FOLDER).toURI());
File[] files = dir.listFiles();
for (File f : files) {
@@ -103,8 +104,8 @@
}
}
- public static File getFile(String name) {
- return new
File(TESTS_FOLDER.getAbsolutePath()+File.separator+name+".msg");
+ public static File getFile(String name) throws URISyntaxException {
+ return new
File(ExampleMessagesRountripTestSuite.class.getResource(TESTS_FOLDER+File.separator+name+".msg").toURI());
}
}
Modified:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java?rev=894094&r1=894093&r2=894094&view=diff
==============================================================================
---
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
(original)
+++
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/message/MessageParserTest.java
Sun Dec 27 18:50:13 2009
@@ -35,6 +35,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
+import java.net.URISyntaxException;
import java.util.List;
import junit.framework.Test;
@@ -44,7 +45,7 @@
public class MessageParserTest extends TestCase {
private File file = null;
- public MessageParserTest(String name) {
+ public MessageParserTest(String name) throws URISyntaxException {
this(name, MessageParserTestSuite.getFile(name));
}
@@ -59,16 +60,16 @@
BasicConfigurator.configure();
}
- public static Test suite() {
+ public static Test suite() throws URISyntaxException {
return new MessageParserTestSuite();
}
static class MessageParserTestSuite extends TestSuite {
- private static final File TESTS_FOLDER = new
File("src/test/resources/testmsgs");
+ private static final String TESTS_FOLDER = "/testmsgs";
- public MessageParserTestSuite() {
- File dir = TESTS_FOLDER;
+ public MessageParserTestSuite() throws URISyntaxException {
+ File dir = new
File(MessageParserTestSuite.class.getResource(TESTS_FOLDER).toURI());
File[] files = dir.listFiles();
for (int i = 0; i < files.length && i < 5000; i++) {
@@ -79,8 +80,8 @@
}
}
- public static File getFile(String name) {
- return new
File(TESTS_FOLDER.getAbsolutePath()+File.separator+name+".msg");
+ public static File getFile(String name) throws URISyntaxException {
+ return new
File(MessageParserTestSuite.class.getResource(TESTS_FOLDER+File.separator+name+".msg").toURI());
}
}
Modified:
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
URL:
http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java?rev=894094&r1=894093&r2=894094&view=diff
==============================================================================
---
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
(original)
+++
james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/parser/MimeStreamParserExampleMessagesTest.java
Sun Dec 27 18:50:13 2009
@@ -19,20 +19,20 @@
package org.apache.james.mime4j.parser;
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mime4j.parser.MimeStreamParser;
-import org.apache.log4j.BasicConfigurator;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.net.URISyntaxException;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.BasicConfigurator;
+
/**
* Creates a TestSuite running the test for each .msg file in the test resouce
folder.
* Allow running of a single test from Unit testing GUIs
@@ -42,7 +42,7 @@
private File file;
- public MimeStreamParserExampleMessagesTest(String testName) {
+ public MimeStreamParserExampleMessagesTest(String testName) throws
URISyntaxException {
this(testName,
MimeStreamParserExampleMessagesTestSuite.getFile(testName));
}
@@ -86,18 +86,18 @@
}
}
- public static Test suite() throws IOException {
+ public static Test suite() throws IOException, URISyntaxException {
return new MimeStreamParserExampleMessagesTestSuite();
}
static class MimeStreamParserExampleMessagesTestSuite extends TestSuite {
- private static final File TESTS_FOLDER = new
File("src/test/resources/testmsgs");
+ private static final String TESTS_FOLDER = "/testmsgs";
- public MimeStreamParserExampleMessagesTestSuite() throws IOException {
+ public MimeStreamParserExampleMessagesTestSuite() throws IOException,
URISyntaxException {
super();
- File dir = TESTS_FOLDER;
+ File dir = new
File(MimeStreamParserExampleMessagesTestSuite.class.getResource(TESTS_FOLDER).toURI());
File[] files = dir.listFiles();
for (File f : files) {
@@ -107,8 +107,8 @@
}
}
- public static File getFile(String name) {
- return new
File(TESTS_FOLDER.getAbsolutePath()+File.separator+name+".msg");
+ public static File getFile(String name) throws URISyntaxException {
+ return new
File(MimeStreamParserExampleMessagesTestSuite.class.getResource(TESTS_FOLDER+File.separator+name+".msg").toURI());
}
}