我想知道是否有人尝试过使用原生容器在pax-exam中通过blueprint.xml测试beans/服务。
我有一个包含两个包的项目: a)配置-接口类b)配置-实施-包含实现,并将bean公开为blueprint.xml中定义的服务。
我希望测试类中的@Inject应该自动设置@Inject变量中的实例值,但似乎不起作用。类似于前面提到的@ https://ops4j1.jira.com/wiki/display/PAXEXAM3/Getting+Started+with+OSGi+Tests。
下面粘贴了发送到pax- sent的选项。有没有可能会有更多的包需要加载,这样pax-exam才能开始识别blueprint.xml并启动服务?
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));发布于 2013-07-13 05:49:35
我使用以下系统包:
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 ) );
}加上我自己的捆绑包,所以我的完整配置看起来像这样:
@Configuration
Option[] config( ) {
return options(
javaFxPackages(),
systemBundles(),
mavenBundle( "org.codehaus.groovy", "groovy-all", "2.1.1" ) );
}我的所有服务都被正确注入。例如,我可以像这样获得BundleContext服务:
@Inject BundleContext context;希望这也适用于您:)
发布于 2013-07-10 00:50:04
Pax Exam不关心如何注册OSGi服务,您可以使用蓝图、声明性服务或手动进行注册。
当测试似乎不起作用时,有两件事需要检查:
Pax Exam自己的集成测试可以作为设置测试环境的示例。
https://stackoverflow.com/questions/17546196
复制相似问题