public
Created

Karaf Testing with Pax Exam

  • Download Gist
KarafTest.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class KarafTest {
 
@Inject
CommandProcessor commandProcessor;
 
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE,
"*,org.apache.felix.service.*;status=provisional");
return probe;
}
 
@Configuration
public static Option[] karafConfig(){
return options(
karafDistributionConfiguration().frameworkUrl(maven()
.groupId("org.apache.karaf")
.artifactId("apache-karaf")
.type("zip")
.versionAsInProject())
.karafVersion("2.2.7")
.name("Apache Karaf"),
keepRuntimeFolder(),
felix()
);
}
 
@Test
public void testStartKarafAndListBundles() throws Exception {
ByteArrayOutputStream result = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(result);
CommandSession cs = commandProcessor.createSession(System.in, ps, System.err);
cs.execute("osgi:list");
cs.close();
ps.flush();
String output = result.toString();
System.out.println(output);
Assert.assertTrue(output.contains("PAXEXAM"));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.