osgimaven-3pax-exam

How to start test container for Pax-Exam?


I might be asking a trivial question. Just started to learn OSGi with Pax-Exam.

What I did is a mvn archetype:generate for Hello World. I changed the AppTest.java with importing PaxExam related imports and other stuffs. Changed pom.xml accordingly as well to include proper dependencies.

When I do mvn dependency:analyze it says,

[WARNING] Unused declared dependencies found: [WARNING] org.ops4j.pax.exam:pax-exam-container-native:jar:3.4.0:test

And when I do mvn test, I am getting the following error

Tests in error: initializationError(com.test.maven.AppTest): No service org.osgi.framework.launch.FrameworkFactory found in META-INF/services on classpath

Can anyone please help on how to resolve this? I don't know how to proceed here.

Or Am I trying to make Apple look like an Orange? Meaning, Pax Exam can only work with jar's in src/test/resources/META-INF/services/ ? Like installation in Apache Felix or similar.


Solution

  • THe first thing you should do is create a separate test project often called itests. Pax exam does not work well when you directly integrate it into the project where you have your sources to test.

    So create a structure like this: /mymodule1 ... /mymodulen /itests

    In the mymodule projects you typically create your bunddles with the maven bundle plugin. You should be able to install them into your OSGi framework.

    Then in the itests directory you put the pax exam dependencies into the pom file. Also put dependencies to your own modules you need as well as their dependencies.

    THen in your pax exam test you define the modules you need in the @Comnfiguration annotated method. I have created a pax exam example for the apache karaf container here.

    So you see that in the test I setup the karaf container and add pax-exam-sample8-ds which is the module I want to test.

    The getting started section in the user doc guides you through the example project:

    Unfortunately I did not yet setup such a simple example for the simple felix and equinox containers. So it might be a good idea to start with the karaf example even if you plan to use the plain containers as it might get you started faster.

    As soon as I got some free time I plan to also add such a simple example test project for the plain OSGi container tests.