user1991839
user1991839

Reputation: 2313

Loading ipojo Maven Bundle in Pax Exam Test

I am trying to create a test using Pax Exam, where some of the bundles that I am loading for the test depend on the package "org.apache.felix.ipojo".

If I were to leave out a line loading this bundle in the Pax Exam configuration, e.g:

@Configuration
public Option[] config() throws MalformedURLException{
    return options(
            junitBundles(),
            BUNDLES OTHER THAN(org.apache.felix.ipojo),
            ...

Then I get an error indicating that this package is a missing dependency:

ERROR: Bundle com.N.A [35] Error starting mvn:com.N/com.N.A (org.osgi.framework.BundleException: Unresolved constraint in bundle com.N.A [35]: Unable to resolve 35.0: missing requirement [35.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.ipojo)(version>=1.8.0)))
org.osgi.framework.BundleException: Unresolved constraint in bundle com.N.A [35]: Unable to resolve 35.0: missing requirement [35.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.ipojo)(version>=1.8.0))
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1868)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
        at java.lang.Thread.run(Thread.java:662)

However, if I add a line that includes it:

@Configuration
public Option[] config() throws MalformedURLException{
    return options(
            junitBundles(),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.ipojo")
            ...

I get a message indicating a ClassCastException, which I presume is due to the ipojo bundle being built into Felix.

ERROR: Bundle org.apache.felix.ipojo [34] Error starting mvn:org.apache.felix/org.apache.felix.ipojo (org.osgi.framework.BundleException: Activator start error in bundle org.apache.felix.ipojo [34].)
java.lang.ClassCastException: org.apache.felix.ipojo.Extender cannot be cast to org.osgi.framework.BundleActivator
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4177)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1972)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
        at java.lang.Thread.run(Thread.java:662)

I am using Felix and JUint4TestRunner as a runner.

How can I get access to this dependency without the conflict?

Upvotes: 1

Views: 584

Answers (2)

Harald Wellmann
Harald Wellmann

Reputation: 12885

The ClassCastException most likely indicates that you have another copy of the OSGi APIs on your classpath. If you have a Maven dependency on org.osgi:org.osgi.core, make sure the scope is provided and not compile or test.

Upvotes: 1

Clement
Clement

Reputation: 3222

Here it's what I use:

public CompositeOption ipojoBundles() {
    return new DefaultCompositeOption(
            mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
            mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject());
}

With the following versions: iPOJO 1.8.6 and osgi-helpers 0.6.0

The helpers are methods reducing the burden when writing OSGi tests.

Upvotes: 0

Related Questions