I'm developing integration tests for some OSGi bundles using Pax Exam 4.8, junit4, JBoss Fuse as OSGi container. Assume standard Maven setup.
The container starts, my bundles are deployed and correctly started.
Now in my test code I need to load a resource and write its content to a file. If I understand correctly, the unit test is automatically deployed as test probe bundle.
@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
}
}
How do I load a resource inside a Pax Exam test? How can I check that the resource is included in the test probe bundle?