I've set up a test project and it worked fine.
I finally found what is causing the issue. It seems that the execution of the tests is stopped during the configuration.
I use Eclipse Gemini 2.0.M02 and I use placeholders in my application contexts. For example, I need the datasource URL to be set as property. I wanted to use a @Before
method to setup a configuration for a PID using the Configuration Admin service.
Since the application contexts are loaded during the configuration and that at this point the PID is not configured (since the @Before
method is not called yet), I get an error from Spring which causes PAX EXAM to abort execution of current test.
Therefore, I can't use the Configuration Admin Service from the @Before
method in my case.
The solution is to use the pax-exam-cm module which allows interacting with the Configuration Admin Service inside the configuration method as follows:
@Configuration
public static Option[] config() {
return options(
junitBundles(),
/* PAX Logging */
mavenBundle("org.ops4j.pax.logging", "pax-logging-api", "1.7.2"),
mavenBundle("org.ops4j.pax.logging", "pax-logging-service", "1.7.2"),
/* Apache Felix Config Admin */
mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.0"),
ConfigurationAdminOptions.newConfiguration("my.pid")
.put("prop1", "value1")
.put("prop2", "value2")
.asOption(),
/* Eclipse Gemini + dependencies */
mavenBundle().groupId("org.aopalliance").artifactId("com.springsource.org.aopalliance").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.aop").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.beans").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.context").versionAsInProject(),
mavenBundle().groupId("org.springframework").artifactId("org.springframework.core").versionAsInProject(),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-core", GEMINI_VERSION),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-extender", GEMINI_VERSION),
mavenBundle("org.eclipse.gemini.blueprint", "gemini-blueprint-io", GEMINI_VERSION),
/* Other bundles */
);
}
You also need to add the pax-exam-cm dependency to your POM (if you use Maven):
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-cm</artifactId>
<version>3.4.0</version>
<scope>test</scope>
</dependency>