Example 13.2 shows an example of how to write a test class for
Apache Karaf in the Pax-Exam testing framework. The FeaturesText
class
configures the Apache Karaf environment, installs the obr
and
wrapper
features, and then runs a test against the two features
(where the obr
and wrapper
features implement particular
sets of commands in the Apache Karaf command console).
Example 13.2. FeaturesText Class
// Java /* * Licensed to the Apache Software Foundation (ASF) * ... */ package org.apache.karaf.shell.itests; import org.apache.karaf.testing.AbstractIntegrationTest; import org.apache.karaf.testing.Helper; import org.junit.Test; import org.junit.runner.RunWith; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.Configuration; import org.ops4j.pax.exam.junit.JUnit4TestRunner; import org.osgi.service.blueprint.container.BlueprintContainer; import org.osgi.service.command.CommandProcessor; import org.osgi.service.command.CommandSession; import static org.junit.Assert.assertNotNull; import static org.ops4j.pax.exam.CoreOptions.equinox; import static org.ops4j.pax.exam.CoreOptions.felix; import static org.ops4j.pax.exam.CoreOptions.maven; import static org.ops4j.pax.exam.CoreOptions.systemProperty; import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup; import static org.ops4j.pax.exam.OptionUtils.combine; import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures; import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory; @RunWith(JUnit4TestRunner.class) public class FeaturesTest extends AbstractIntegrationTest { @Test public void testFeatures() throws Exception { // Make sure the command services are available assertNotNull(getOsgiService(BlueprintContainer.class, "osgi.blueprint.container.symbolicname=org.apache.karaf.shell.obr", 20000)); assertNotNull(getOsgiService(BlueprintContainer.class, "osgi.blueprint.container.symbolicname=org.apache.karaf.shell.wrapper", 20000)); // Run some commands to make sure they are installed properly CommandProcessor cp = getOsgiService(CommandProcessor.class); CommandSession cs = cp.createSession(System.in, System.out, System.err); cs.execute("obr:listUrl"); cs.execute("wrapper:install --help"); cs.close(); } @Configuration public static Option[] configuration() throws Exception{ return combine( // Default karaf environment Helper.getDefaultOptions( // this is how you set the default log level when using pax logging (logProfile) systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG")), // add two features scanFeatures( maven().groupId("org.apache.karaf").artifactId("apache-felix-karaf").type("xml").classifier("features").versionAsInProject(), "obr", "wrapper" ), workingDirectory("target/paxrunner/features/"), waitForFrameworkStartup(), // Test on both equinox and felix equinox(), felix() ); } }
The | |
In order to integrate this JUnit test properly with Apache Karaf, you are
required to derive this test class from
The | |
The | |
This line gives an example of how to use the | |
The | |
The | |
The If there are any Java system properties in the Apache Karaf environment that
you would like to customize, you can pass the properties as optional
arguments to the | |
The Pax-Exam framework supports the concept of Apache Karaf features (see
Deploying Features). You can use the
The location of the relevant features repository is
specified by passing a Pax URL as the first argument to
| |
The | |
The | |
The options, |