FAQ 1.x

Pax Exam FAQ

Exception: Cannot get the remote bundle context

If you get an exception looking like this:

org.ops4j.pax.exam.spi.container.TestContainerException: Cannot get the remote bundle context
       at org.ops4j.pax.exam.rbc.client.RemoteBundleContextClient.getRemoteBundleContext(RemoteBundleContextClient.java:256)
       at org.ops4j.pax.exam.rbc.client.RemoteBundleContextClient.stop(RemoteBundleContextClient.java:201)
       at org.ops4j.pax.exam.container.def.internal.PaxRunnerTestContainer.stop(PaxRunnerTestContainer.java:158)
       at org.ops4j.pax.exam.junit.internal.JUnit4TestMethod.invoke(JUnit4TestMethod.java:120)
       at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
       at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
       at org.ops4j.pax.exam.junit.internal.JUnit4MethodRoadie.runBeforesThenTestThenAfters(JUnit4MethodRoadie.java:60)
       at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
       at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
       at org.ops4j.pax.exam.junit.JUnit4TestRunner.invokeTestMethod(JUnit4TestRunner.java:221)
       at org.ops4j.pax.exam.junit.JUnit4TestRunner.runMethods(JUnit4TestRunner.java:171)
       at org.ops4j.pax.exam.junit.JUnit4TestRunner$1.run(JUnit4TestRunner.java:161)
       at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
       at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
       at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:157)
       at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
       at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

first you should check is, if you have running local firewalls or virusscanners blocking localhost to localhost communication.
Infact, Pax Exam spawns a new JVM and communicates with it via RMI.

Best is, to convince your firewall to not block those activities.

How can i control the amount of log in pax exam ?

We use Comons Logging with Log4J backend inside Pax Exam-
Therefor, controlling the output is just a matter of placing a log4j.properties file flat into you classpath.
In Maven based projects, this is most of the time src/test/resources.
Such content can be (for example):
1. A lot of output

log4j.rootCategory=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=[%30.30c{1}] - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

2. Very few output

log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout.ConversionPattern=[%30.30c{1}] - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

Can i change the manifest of my test probe bundle ?

Very short answer
No

Short answer
No, by design. You don't control the test probe. Use TinyBundles for intermediate bundles.*

Longer answer
Pax Exam's Test Bundles (we call them test probes) are - as of 1.0 - fully auto mantained by pax exam. This means, you are not in control of the manifest.

This has been stated often on mailinglists and is not really a shortcoming but a definition of tests you can do with pax exam:
You test probe is just "orchestrating" the real bundles.
This also ensures you never come to the idea to really use the probe to contain real logic you better want to have in a bundle you mantain yourself.

Every bundle that is more than this orchestration (or see it as a test starting point, the test activation bundle, if you want another terminology) should be fully in your control. This means: treat that as a real bundle.

However, sometimes you really need "tiny bundles" that fill a gap, that just exist to test a very certain concern - in cxf and can really think of this very well.

Given this, you don't want to set up a full maven-bundle-plugin project for each of those tiny bundles, .. well there is a project called TinyBundles that has been started for exactly this concern.

Why should i not put my exam tests inside my bundle project / implementation

With Pax Exam you tests your system in an integration test kind of environment.
This means, you

  • load your real components (bundles)
  • into a real osgi environment
  • and orchestrate the behaviour from a 3rd persons point of view: your tests resides in its own bundle (called test probe)

This is basically a design principle that is there since Exam started.
If you want to do unit testing, you are encouraged to do so using just JUnit or TestNG or whatever directly.
At that point you do not need osgi dynamics or even semantics.

If you would embedd your test into your real production bundles, you also will get a build- logic cycle when using stock maven. Your test will require a bundle that has not been built at that point in time because the tests are running before the packaging phase.
So, this test phase in your bundlebuild lifecycle is meant for unit testing not for tests that requires the whole component (Integration Tests)

In Pax Exam, we really want to play the 3rd persons role and watch the whole dynamics from within (we are a bundle) but still from outside of any implementation component (we are a separate bundle you don't have to mantain yourself)

However!
You don't want to set up a full maven-bundle-plugin project for each of those tiny bundles, .. well there is a project called TinyBundles that has been started for exactly this concern.
This allows you to create bundles easily by composing them like you want from classpath resources (or any other url). You also get BND Support to create the meta data.

Conclusion: put tests into its own project (pom in maven).

I get an Exception when running with Pax Exam on IBM JDK

Running exam on an IBM JDK i get this exception:

java.lang.TypeNotPresentException: Type
org.ops4j.pax.exam.junit.Configuration not present
..

Solution:
That is a "known" bug in IBM JDK and it was also present in earlier java 5 versions. The problem is that IBM should not fail if there is he encounters an unknown annotation. But it does.

Workaround:
Add pax-exam-junit to your configuration like so:

wrappedBundle(maven("org.ops4j.pax.exam", "pax-exam-junit")))