0

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

mike
  • 4,929
  • 4
  • 40
  • 80

1 Answers1

2

Your project is a maven project and bundles maven artifact. It's better then to use mavenBundle references:

  1. Reference these dependencies in the pom of your test
  2. 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>
    


  3. Use a mavenBundle reference :

    mavenBundle().groupId("org.beyene.mode")
      .artifactId("service.consumer").versionAsInProject() 
    
Jérémie B
  • 10,611
  • 1
  • 26
  • 43
  • Thx for your answer. What scope should I use for the dependencies in the test pom? Provided? – mike Mar 05 '16 at 17:49
  • 1
    the test scope, but honestly, it doesn't matter. pax-exam will provide a new container, the classpath of the test will not be used. – Jérémie B Mar 05 '16 at 17:52
  • Thank you. Everything is working fine from the command line. Eclipse is complaining, though: `Plugin execution not covered by lifecycle configuration: org.apache.servicemix.tooling:depends-maven-plugin:1.2:generate-depends-file (execution: generate-depends-file, phase: generate-resources)` Do you know sth. about that? – mike Mar 05 '16 at 17:56
  • that's just eclipse which doesn't know anything about the `depends-maven-plugin` and doesn't know what to do. You can tell it to ignore this plugin. – Jérémie B Mar 05 '16 at 17:58