Reputation: 41
I want to know if anyone has tried to test beans/services exposed through blueprint.xml working in pax-exam using native container.
I have a project with two bundles - a) config - interface classes b) config-impl - contains implementation and exposes bean as service defined in blueprint.xml.
I was hoping that @Inject in the test class similar to approach mentioned @ https://ops4j1.jira.com/wiki/display/PAXEXAM3/Getting+Started+with+OSGi+Tests should automatically set the instance value in @Inject'ed variable but it doesn't seem to be working.
The options sent to pax-exam are pasted below. By any chance, would there be more bundles to load so that pax-exam starts recognizing blueprint.xml and boot up the service?
return options(
systemProperty("osgi.console").value("6666"),
junitBundles(),
provision(
mavenBundle("org.osgilab.testing", "commons", "1.0.0"),
mavenBundle("org.apache.commons", "com.springsource.org.apache.commons.codec", "1.3.0"),
mavenBundle("org.codehaus.jackson", "jackson-core-asl", "1.9.12"),
mavenBundle("org.codehaus.jackson", "jackson-mapper-asl", "1.9.12"),
mavenBundle("com.umum.container", "container-config", "1.0.0"),
mavenBundle("com.umum.container", "container-config-impl", "1.0.0").start()),
systemProperty("pax.exam.service.timeout").value("160000"), systemTimeout(160000));
Upvotes: 2
Views: 2002
Reputation: 13690
I use the following system bundles:
static Option systemBundles() {
return composite(
mavenBundle( "org.apache.aries.blueprint", "org.apache.aries.blueprint", "1.0.0" ),
mavenBundle( "org.apache.aries", "org.apache.aries.util", "1.0.0" ),
mavenBundle( "org.apache.aries.proxy", "org.apache.aries.proxy", "1.0.0" ),
junitBundles(),
cleanCaches( true ) );
}
Plus my own bundles, so my complete Config looks similar to this:
@Configuration
Option[] config( ) {
return options(
javaFxPackages(),
systemBundles(),
mavenBundle( "org.codehaus.groovy", "groovy-all", "2.1.1" ) );
}
All my services get injected correctly. For example, I can get the BundleContext service like this:
@Inject BundleContext context;
Hope this works for you too :)
Upvotes: 5
Reputation: 12855
Pax Exam doesn't care how OSGi services get registered, you can use Blueprint, Declarative Services or do it manually.
When a test doesn't seem to work, there's two things to check:
Pax Exam's own integration tests can serve as an example for setting up a test environment.
Upvotes: -1