我创建了一个OSGi example project并希望改进集成测试所需的 bundle 的配置。
现在,这些包是通过文件名静态引用的,利用 CoreOptions.bundle("reference:file:" + <path>)
,因此问题是,当 jar 的名称发生更改(例如由于版本更改)时,测试将在将来的某个时间失败。
是否有更好的方法来部署所需的依赖项?也许使用符号名称或组/Artifact ID?
@RunWith(PaxExam.class)
public class ServiceTestCase {
@Inject
private Service service;
@Configuration
public Option[] config() {
return CoreOptions.options(
/* needed for ds annotations */
CoreOptions.mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.8.2"),
CoreOptions.bundle("reference:file:../service/target/service-0.0.1-SNAPSHOT.jar"),
CoreOptions.bundle("reference:file:../service.impl/target/service.impl-0.0.1-SNAPSHOT.jar"),
CoreOptions.junitBundles());
}
@Test
public void testInjections() {
Assert.assertNotNull(service);
}
}
ServiceTestCase.java 的缩写版本
最佳答案
您的项目是一个 Maven 项目并捆绑了 Maven Artifact 。最好使用 mavenBundle
引用:
- 在测试的 pom 中引用这些依赖项
使用
depends-maven-plugin
生成包含依赖项版本的属性文件:<plugin> <groupId>org.apache.servicemix.tooling</groupId> <artifactId>depends-maven-plugin</artifactId> <version>1.2</version> <executions> <execution> <id>generate-depends-file</id> <phase>generate-resources</phase> <goals> <goal>generate-depends-file</goal> </goals> </execution> </executions> </plugin>
使用
mavenBundle
引用:mavenBundle().groupId("org.beyene.mode") .artifactId("service.consumer").versionAsInProject()
关于java - 动态引用 bundle ,用于与 Pax Exam 进行集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35817348/