我正在开发使用Pax Exam 4.8,junit4,JBoss Fuse作为OSGi容器的一些OSGi bundle的集成测试。假设标准的Maven设置。如何访问Pax Exam考试测试套件中的资源?
容器启动,我的包已部署并正确启动。
现在在我的测试代码中,我需要加载资源并将其内容写入文件。 如果我理解正确,单元测试会自动部署为测试探针包。
@RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class ExampleTest {
@javax.inject.Inject
BundleContext bundleContext;
@Configuration
public Option[] config() throws Exception {
// container setup
}
@Test
public void testThatApplicationProcessesThisFile() {
InputStream is1 = getClass().getResourceAsStream("myResource"); // returns null
Bundle probeBundle = bundleContext.getBundle("local");
InputStream is2 = probeBundle.getResource("myResource").openStream();
// getResource() returns null
// write the resource as a file
}
}
如何在Pax Exam考试中加载资源?如何检查资源是否包含在测试探针包中?