You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Alex Parvulescu <al...@gmail.com> on 2011/08/04 10:12:48 UTC

unit testing felix scr components with pax-exam 2.1

hi guys,

I want to write some unit tests for a scr component I'm working on. It seems
the best option for osgi related testing is the pax-exam library, with
tiny-bundles.
I'm using paxexam version 2.1.0.

The problem appears when I try to test a component that is built using
annotations:

@Component(immediate = true)
@Service(classOf[ScriptEngineFactory])
class ScalaScriptEngineFactory extends ScriptEngineFactory {
//...
}

Now, for the test init part:

  @Configuration()
  def config() =
    options(
      junitBundles(), felix(),
      mavenBundle("com.weiglewilczek.scala-lang-osgi", "scala-library",
"2.8.1"),
      mavenBundle("com.weiglewilczek.scala-lang-osgi", "scala-compiler",
"2.8.1"),
      mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.4.0"),
      provision(
        TinyBundles.bundle
          .set(Constants.IMPORT_PACKAGE,
"javax.jcr.*;resolution:=optional,scala.*,*")
          .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
          .add(classOf[ScriptEngineFactory])
          .add(classOf[ScalaScriptEngineFactory])
          .build(TinyBundles.withBnd)));

(excuse the scala code :)

Running the test like this throws out the error:
ERROR: Bundle BuildByTinyBundles577e8d0c-cd97-400e-817c-dc6514303084 [4]
Error starting
file:bundles/BuildByTinyBundles577e8d0c-cd97-400e-817c-dc6514303084_0.jar
(org.osgi.framework.BundleException: Unresolved constraint in bundle
BuildByTinyBundles577e8d0c-cd97-400e-817c-dc6514303084 [4]: Unable to
resolve 4.0: missing requirement [4.0] package;
(package=org.apache.felix.scr.annotations))
org.osgi.framework.BundleException: Unresolved constraint in bundle
BuildByTinyBundles577e8d0c-cd97-400e-817c-dc6514303084 [4]: Unable to
resolve 4.0: missing requirement [4.0] package;
(package=org.apache.felix.scr.annotations)
at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3518)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1750)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1179)
at org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
at java.lang.Thread.run(Thread.java:662)

So it cannot resolve "org.apache.felix.scr.annotations", which makes sense,
as it is not present in the container.
I'm not sure if it should be, though.

But, if I try to add it to the options: mavenBundle("org.apache.felix",
"org.apache.felix.scr.annotations", "1.4.0"), then all fails with another
nice error about org.apache.felix.scr.annotations not being a bundle.
Caused by: org.ops4j.pax.runner.platform.PlatformException:
[mvn:org.apache.felix/org.apache.felix.scr.annotations/1.4.0] is not a valid
bundle


Any ideas on how I can get this to work? or any ideas on how to unit test
scr components in general?

thanks for your time,
alex