Java Reference
In-Depth Information
public static Option[] configure() {
return options(
mavenBundle("org.osgi", "org.osgi.compendium", "4.2.0")
);
}
Deploys
compendium bundle B
@Test
public void testContainer(BundleContext ctx) {
System.out.println(
format(ctx, FRAMEWORK_VENDOR) +
format(ctx, FRAMEWORK_VERSION) +
format(ctx, FRAMEWORK_LANGUAGE) +
format(ctx, FRAMEWORK_OS_NAME) +
format(ctx, FRAMEWORK_OS_VERSION) +
format(ctx, FRAMEWORK_PROCESSOR) +
"\nTest Bundle is " +
ctx.getBundle().getSymbolicName());
}
C
Prints symbolic
name
private static String format(
BundleContext ctx, String key) {
return String.format("%-32s = %s\n",
key, ctx.getProperty(key));
}
}
You begin by annotating your test class with @RunWith . This tells JU nit to use the named
test runner instead of the standard JU nit one. The Pax Exam JUnit4TestRunner class
is responsible for starting the relevant framework, deploying bundles, and running the
tests. The @Configuration annotation identifies the method that provides the Pax
Exam configuration. Right now, you ask it to deploy the standard OSG i compendium
bundle B from Maven central in to the default framework. The actual test method is
annotated with the usual JU nit 4 annotation, @Test . It accepts a BundleContext argu-
ment that's supplied by Pax Exam at execution time. You use this bundle context to print
out various properties, including the symbolic name of the test bundle C .
To run this test, type the following:
$ cd chapter07/testing-example
$ ant test.container
You should see something like the following, but with properties that match your system.
Listing 7.3 Using Pax Exam to run tests on an OSGi framework
[junit] Running org.foo.test.ContainerTest
[junit] __________ ___________
[junit] \______ \_____ ___ ___ \_ _____/__ ________ _____
[junit] | ___/\__ \ \ \/ / | __)_\ \/ /\__ \ / \
[junit] | | / __ \_> < | \> < / __ \| Y Y \
[junit] |____| (____ /__/\_ \ /_______ /__/\_ \(____ /__|_| /
[junit] \/ \/ \/ \/ \/ \/
[junit]
 
Search WWH ::




Custom Search