FELIX-2554 simplify integration test setup by adding a build profile "ide" generating a version of the bundle easily accessible with PAX Exam both from within Maven build and from within IDEs
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@988894 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/pom.xml b/configadmin/pom.xml
index f9368f3..c08f355 100644
--- a/configadmin/pom.xml
+++ b/configadmin/pom.xml
@@ -35,6 +35,42 @@
Implementation of the OSGi Configuration Admin Service Specification 1.2
</description>
+ <!--
+ A Note on Testing
+ =================
+
+ This project contains two kinds of tests: regular unit tests running
+ in the test phase and integration tests based on PAX Exam running
+ in the integration-test phase.
+
+ Basically the complete project is build using Java 1.3 source and target
+ compatibility (as inherited from the parent pom). The exception are the
+ unit tests in the "integration" packages. These have to be compiled with
+ Java 5 source and target compatibility because the employ annotations
+ and generics.
+
+ For running the integration tests from the console using Maven nothing
+ special has to be done as the tests run automatically. To run the tests
+ in your IDE, the project has to be built to the "package" phase with
+ the profile "ide" enabled:
+
+ $ mvn -Pide clean package
+
+ This creates the scr.jar file in the target folder, which is used by
+ the integration tests when run from the IDE. Alternatively the
+ "project.bundle.file" system property may be set to the bundle JAR
+ in the IDE launcher.
+ -->
+ <properties>
+ <bundle.build.name>
+ ${basedir}/target
+ </bundle.build.name>
+ <bundle.file.name>
+ ${bundle.build.name}/${project.build.finalName}.jar
+ </bundle.file.name>
+ </properties>
+
+
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
@@ -148,38 +184,6 @@
</configuration>
</plugin>
- <!-- Provide bundle for integration tests -->
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <version>1.3</version>
- <executions>
- <execution>
- <id>configadmin-file-create</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <copy file="${project.build.directory}/${project.build.finalName}.jar" tofile="${project.build.directory}/configadmin.jar" />
- </tasks>
- </configuration>
- </execution>
- <execution>
- <id>configadmin-file-remove</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <delete file="${project.build.directory}/configadmin.jar" />
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
<!--
Exclude Integration tests in (default) unit tests and
conversely enable integration tests for integration testing
@@ -195,6 +199,12 @@
<goal>test</goal>
</goals>
<configuration>
+ <systemProperties>
+ <property>
+ <name>project.bundle.file</name>
+ <value>${bundle.file.name}</value>
+ </property>
+ </systemProperties>
<excludes>
<exclude>**/cm/*</exclude>
<exclude>**/cm/file/*</exclude>
@@ -215,6 +225,38 @@
</plugins>
</build>
+ <profiles>
+ <!--
+ copy the package such that IDEs may easily use it without
+ setting the system property
+ -->
+ <profile>
+ <id>ide</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.3</version>
+ <executions>
+ <execution>
+ <id>cm-file-create</id>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <copy file="${project.build.directory}/${project.build.finalName}.jar" tofile="${project.build.directory}/configadmin.jar" />
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
<!-- repositories for Pax Exam and BND tool -->
<repositories>
<repository>
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
index eda056e..0dcf3c1 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationTestBase.java
@@ -19,6 +19,9 @@
package org.apache.felix.cm.integration;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -39,6 +42,8 @@
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.OptionUtils;
+import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -72,6 +77,20 @@
*/
public static final boolean REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION = false;
+ // the name of the system property providing the bundle file to be installed and tested
+ protected static final String BUNDLE_JAR_SYS_PROP = "project.bundle.file";
+
+ // the default bundle jar file name
+ protected static final String BUNDLE_JAR_DEFAULT = "target/configadmin.jar";
+
+ // the JVM option to set to enable remote debugging
+ protected static final String DEBUG_VM_OPTION = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303";
+
+ // the actual JVM option set, extensions may implement a static
+ // initializer overwriting this value to have the configuration()
+ // method include it when starting the OSGi framework JVM
+ protected static String paxRunnerVmOption = null;
+
@Inject
protected BundleContext bundleContext;
@@ -92,14 +111,22 @@
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration()
{
- return CoreOptions.options(
- CoreOptions.provision(
- CoreOptions.bundle( new File("target/configadmin.jar").toURI().toString() ),
- CoreOptions.mavenBundle( "org.ops4j.pax.swissbox", "pax-swissbox-tinybundles", "1.0.0" )
- )
-// , PaxRunnerOptions.vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
- // , PaxRunnerOptions.logProfile()
+ final String bundleFileName = System.getProperty( BUNDLE_JAR_SYS_PROP, BUNDLE_JAR_DEFAULT );
+ final File bundleFile = new File( bundleFileName );
+ if ( !bundleFile.canRead() )
+ {
+ throw new IllegalArgumentException( "Cannot read from bundle file " + bundleFileName + " specified in the "
+ + BUNDLE_JAR_SYS_PROP + " system property" );
+ }
+
+ final Option[] base = options(
+ provision(
+ CoreOptions.bundle( bundleFile.toURI().toString() ),
+ mavenBundle( "org.ops4j.pax.swissbox", "pax-swissbox-tinybundles", "1.0.0" )
+ )
);
+ final Option vmOption = ( paxRunnerVmOption != null ) ? PaxRunnerOptions.vmOption( paxRunnerVmOption ) : null;
+ return OptionUtils.combine( base, vmOption );
}