Skip to content

Instantly share code, notes, and snippets.

@leadVisionary
Created August 21, 2012 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leadVisionary/3417239 to your computer and use it in GitHub Desktop.
Save leadVisionary/3417239 to your computer and use it in GitHub Desktop.
Karaf Testing with Pax Exam
@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"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment