I have created an OSGi example project and want to improve the provisioning of the bundles needed for the integration test.
Right now the bundles are statically references by file name, utilizing CoreOptions.bundle("reference:file:" + <path>)
, the problem thereby is that the test will fail at some time in the future, when the name of the jars changes (due to version change for example).
Is there a better way to deploy the needed dependencies? Maybe with the use of a symbolic name, or group/artifact id?
@RunWith(PaxExam.class)
public class ServiceTestCase {
@Inject
private Service service;
@Configuration
public Option[] config() {
return CoreOptions.options(
/* needed for ds annotations */
CoreOptions.mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.8.2"),
CoreOptions.bundle("reference:file:../service/target/service-0.0.1-SNAPSHOT.jar"),
CoreOptions.bundle("reference:file:../service.impl/target/service.impl-0.0.1-SNAPSHOT.jar"),
CoreOptions.junitBundles());
}
@Test
public void testInjections() {
Assert.assertNotNull(service);
}
}
shortened version of ServiceTestCase.java
Your project is a maven project and bundles maven artifact. It's better then to use mavenBundle
references:
Use the depends-maven-plugin
to generate a property file with the version of the dependencies:
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>generate-depends-file</id>
<phase>generate-resources</phase>
<goals>
<goal>generate-depends-file</goal>
</goals>
</execution>
</executions>
</plugin>
Use a mavenBundle
reference :
mavenBundle().groupId("org.beyene.mode")
.artifactId("service.consumer").versionAsInProject()