aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Whiteside2012-04-14 19:19:32 (EDT)
committerGlyn Normington2012-05-21 09:20:30 (EDT)
commitf6598a261bc265f05d82a6e76309e381f6fe7093 (patch)
tree12ff6a1c72fae3532edf2305a1f7e3a7863af7cd
parent3d26514fcc9680417aac8427b83f8d26c888d09f (diff)
downloadorg.eclipse.gemini.blueprint-f6598a261bc265f05d82a6e76309e381f6fe7093.zip
org.eclipse.gemini.blueprint-f6598a261bc265f05d82a6e76309e381f6fe7093.tar.gz
org.eclipse.gemini.blueprint-f6598a261bc265f05d82a6e76309e381f6fe7093.tar.bz2
Unit test fixes
- removed some unused constants in JarCreator - removed assumptions about the location of the directory that contains test classes, this is no longer hard coded to './target/test-classes' but resolved using the current threads context classloader. This makes the integration tests run and pass in Intelli-J (Maven is unaffected). - fixed JarCreator, AbstractConfigurableBundleCreatorTests and AbstractOnTheFlyBundleCreatorTests - updated log4j.properties under integration-tests/tests to place all logs under the maven target directory. - fixed assumption in OsgiBundleResourceTest about the working directory of the process executing the unit test, now resolves test files from the classpath - not sure why this just started failing, but now it's fixed. Runs (and passes) the same from maven as from my IDE.
-rw-r--r--integration-tests/tests/src/test/resources/log4j.properties2
-rw-r--r--io/src/test/java/org/eclipse/gemini/blueprint/io/OsgiBundleResourceTest.java6
-rw-r--r--io/src/test/resources/normal0
-rw-r--r--test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractConfigurableBundleCreatorTests.java2
-rw-r--r--test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractOnTheFlyBundleCreatorTests.java13
-rw-r--r--test-support/src/main/java/org/eclipse/gemini/blueprint/test/internal/util/jar/JarCreator.java29
6 files changed, 16 insertions, 36 deletions
diff --git a/integration-tests/tests/src/test/resources/log4j.properties b/integration-tests/tests/src/test/resources/log4j.properties
index c823438..0b9c72c 100644
--- a/integration-tests/tests/src/test/resources/log4j.properties
+++ b/integration-tests/tests/src/test/resources/log4j.properties
@@ -5,7 +5,7 @@ log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.threshold=TRACE
log4j.appender.file=org.apache.log4j.RollingFileAppender
-log4j.appender.file.File=out.log
+log4j.appender.file.File=./target/out.log
log4j.appender.file.threshold=TRACE
log4j.appender.file.MaxFileSize=100KB
# Keep one backup file
diff --git a/io/src/test/java/org/eclipse/gemini/blueprint/io/OsgiBundleResourceTest.java b/io/src/test/java/org/eclipse/gemini/blueprint/io/OsgiBundleResourceTest.java
index 0e6608c..37190c9 100644
--- a/io/src/test/java/org/eclipse/gemini/blueprint/io/OsgiBundleResourceTest.java
+++ b/io/src/test/java/org/eclipse/gemini/blueprint/io/OsgiBundleResourceTest.java
@@ -123,7 +123,7 @@ public class OsgiBundleResourceTest extends TestCase {
}
public void testFileWithSpecialCharsInTheNameBeingResolved() throws Exception {
- String name = "file:./target/test-classes/test-file";
+ String name = Thread.currentThread().getContextClassLoader().getResource( "test-file" ).toString();
FileSystemResourceLoader fileLoader = new FileSystemResourceLoader();
fileLoader.setClassLoader(getClass().getClassLoader());
@@ -134,7 +134,7 @@ public class OsgiBundleResourceTest extends TestCase {
}
public void testFileWithEmptyCharsInTheNameBeingResolved() throws Exception {
- String name = "file:./target/test-classes/test file";
+ String name = Thread.currentThread().getContextClassLoader().getResource( "test file" ).toString();
FileSystemResourceLoader fileLoader = new FileSystemResourceLoader();
fileLoader.setClassLoader(getClass().getClassLoader());
@@ -145,7 +145,7 @@ public class OsgiBundleResourceTest extends TestCase {
}
public void testFileWithNormalCharsInTheNameBeingResolved() throws Exception {
- String name = "file:.project";
+ String name = Thread.currentThread().getContextClassLoader().getResource( "normal" ).toString();
FileSystemResourceLoader fileLoader = new FileSystemResourceLoader();
fileLoader.setClassLoader(getClass().getClassLoader());
diff --git a/io/src/test/resources/normal b/io/src/test/resources/normal
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/io/src/test/resources/normal
diff --git a/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractConfigurableBundleCreatorTests.java b/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractConfigurableBundleCreatorTests.java
index 40a4b65..c403729 100644
--- a/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractConfigurableBundleCreatorTests.java
+++ b/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractConfigurableBundleCreatorTests.java
@@ -101,7 +101,7 @@ public abstract class AbstractConfigurableBundleCreatorTests extends AbstractOnT
private static final Properties DEFAULT_SETTINGS = new Properties();
static {
- DEFAULT_SETTINGS.setProperty(ROOT_DIR, "file:./target/test-classes/");
+ DEFAULT_SETTINGS.setProperty(ROOT_DIR, Thread.currentThread().getContextClassLoader().getResource(".").toString());
DEFAULT_SETTINGS.setProperty(INCLUDE_PATTERNS, JarCreator.EVERYTHING_PATTERN);
DEFAULT_SETTINGS.setProperty(LIBS, "");
DEFAULT_SETTINGS.setProperty(MANIFEST, "");
diff --git a/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractOnTheFlyBundleCreatorTests.java b/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractOnTheFlyBundleCreatorTests.java
index 4b49d10..82c0d9d 100644
--- a/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractOnTheFlyBundleCreatorTests.java
+++ b/test-support/src/main/java/org/eclipse/gemini/blueprint/test/AbstractOnTheFlyBundleCreatorTests.java
@@ -106,13 +106,18 @@ public abstract class AbstractOnTheFlyBundleCreatorTests extends AbstractDepende
/**
* Returns the root path used for locating the resources that will be packed
* in the test bundle (the root path does not become part of the jar).
- * <p/>By default, the Maven2 test layout is used:
- * <code>"file:./target/test-classes"</code>
- *
+ *
+ * <p/>By default, the current threads context ClassLoader is used to locate
+ * the root of the classpath. Because unit tests will either be run from Maven
+ * or an IDE this will resolve a test classes directory of sorts.
+ *
+ * <p/>For example when invoked from Maven <code>"file:./target/test-classes"</code>
+ * will be resolved and used.
+ *
* @return root path given as a String
*/
protected String getRootPath() {
- return "file:./target/test-classes/";
+ return Thread.currentThread().getContextClassLoader().getResource(".").toString();
}
/**
diff --git a/test-support/src/main/java/org/eclipse/gemini/blueprint/test/internal/util/jar/JarCreator.java b/test-support/src/main/java/org/eclipse/gemini/blueprint/test/internal/util/jar/JarCreator.java
index a089ef7..27f0bdb 100644
--- a/test-support/src/main/java/org/eclipse/gemini/blueprint/test/internal/util/jar/JarCreator.java
+++ b/test-support/src/main/java/org/eclipse/gemini/blueprint/test/internal/util/jar/JarCreator.java
@@ -30,9 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.eclipse.gemini.blueprint.test.internal.util.jar.storage.MemoryStorage;
import org.eclipse.gemini.blueprint.test.internal.util.jar.storage.Storage;
import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
-import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.StringUtils;
@@ -48,20 +46,10 @@ public class JarCreator {
private static final Log log = LogFactory.getLog(JarCreator.class);
- public static final String CLASS_PATTERN = "/**/*.class";
-
- public static final String XML_PATTERN = "/**/*.xml";
-
- public static final String PROPS_PATTERN = "/**/*.properties";
-
public static final String EVERYTHING_PATTERN = "/**/*";
- private static final String[] LIMITED_PATTERN = new String[] { CLASS_PATTERN, XML_PATTERN, PROPS_PATTERN };
-
private static final String CLASS_EXT = ".class";
- private static final String TEST_CLASSES_DIR = "test-classes";
-
private String[] contentPattern = new String[] { EVERYTHING_PATTERN };
private ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
@@ -82,27 +70,14 @@ public class JarCreator {
* @return the root path
*/
public String determineRootPath() {
- // load file using absolute path. This seems to be necessary in IntelliJ
- try {
- ResourceLoader fileLoader = new DefaultResourceLoader();
- Resource res = fileLoader.getResource(getClass().getName().replace('.', '/').concat(".class"));
- String fileLocation = "file://" + res.getFile().getAbsolutePath();
- fileLocation = fileLocation.substring(0, fileLocation.indexOf(TEST_CLASSES_DIR)) + TEST_CLASSES_DIR;
- if (res.exists()) {
- return fileLocation;
- }
- }
- catch (Exception e) {
- }
-
- return "file:./target/" + TEST_CLASSES_DIR;
+ return Thread.currentThread().getContextClassLoader().getResource(".").toString();
}
/**
* Actual jar creation.
*
* @param manifest to use
- * @param content array of resource to include in the jar
+ * @param entries array of resource to include in the jar
* @return the number of bytes written to the underlying stream.
*
* @throws IOException