3

I'm working on PAX integration tests for our project and I'm facing few issues with regards to class loading.

I have deployed few bundles in PAX (used karaf container). Once the karaf is up, I could see my bundles and services are up and active. However, in my test cases, I've referred to a Class (not a service nor a component) which will used to during my test execution. The class is resided in the bundle and bundle is up and running successfully, but I'm getting ClassnotFoundError while accessing the class in test case executionas below,

**java.lang.ClassNotFoundException: com.myproject.sample.bundle.DatabaseConfig
        at** org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
        at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
        at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at com.integrationtest.testcases.internal.development.LaunchContainerTest.populateDBProfiles(LaunchContainerTest.java:189)
        at com.integrationtest.testcases.internal.development.LaunchContainerTest.testLaunchOSGiContainerWithDefualtSettingsAndSleep(LaunchContainerTest.java:152)
Failed tests:  
LaunchContainerTest.testLaunchOSGiContainerWithDefualtSettingsAndSleep:152->populateDBProfiles:189
▒ ClassNotFound

Is it something to do with the container?

Regular Jo
  • 5,190
  • 3
  • 25
  • 47
Rajasekar
  • 31
  • 1

1 Answers1

1

As your test itself will also run within the OSGi context you need to adapt your test. The dynamically generated test bundle needs to know that it needs to import the class in question. For this you can add a specialized probe configuration method. Like the following below:

@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
    //make sure the needed imports are there. 
    probe.setHeader(Constants.IMPORT_PACKAGE, "*,com.myproject.sample.bundle.*");
    return probe;
}
Achim Nierbeck
  • 5,265
  • 2
  • 14
  • 22