Java Reference
In-Depth Information
We'll show you how OSG i and Pax Exam can help with management testing. The cur-
rent test example exercises the latest Configuration Admin Service implementation
from Apache Felix. But what if you have an application that uses an earlier version?
Can you upgrade to the latest version without losing any configuration data? Why not
write a quick test to find out?
You can find the example upgrade test under mt/upgrade_configadmin_bundle.
It's based on the listConfiguration test from the existing Apache Felix integration
test suite. Listing 7.6 shows the custom configuration for the upgrade test. You want to
reuse the helper classes from the earlier tests, so you explicitly deploy the integration
test bundle alongside your management test. You also deploy the old Configuration
Admin Service bundle and store the location of the new bundle in a system property
so you can use it later to upgrade Configuration Admin Service during the manage-
ment test. You use a system property because the configuration and test methods are
executed by different processes, and system properties are a cheap way to communi-
cate between processes.
Listing 7.6 Configuring the upgrade management test
private static String toFileURI(String path) {
return new File(path).toURI().toString();
}
@org.ops4j.pax.exam.junit.Configuration
public static Option[] configuration() {
return options(
provision(
bundle(toFileURI("bundles/integration_tests-1.0.jar")),
bundle(toFileURI("bundles/old.configadmin.jar")),
mavenBundle("org.osgi", "org.osgi.compendium", "4.2.0"),
mavenBundle("org.ops4j.pax.swissbox", "pax-swissbox-tinybundles",
"1.0.0")
),
systemProperty("new.configadmin.uri").
value(toFileURI("bundles/configadmin.jar"))
);
}
The rest of the test follows the same script as the original listConfiguration test with
three key differences. First, you make sure the installed Configuration Admin Service
bundle is indeed the older 1.0.0 release, by checking the OSG i metadata:
Dictionary headers = getCmBundle().getHeaders();
TestCase.assertEquals("org.apache.felix.configadmin",
headers.get(Constants.BUNDLE_SYMBOLICNAME));
TestCase.assertEquals("1.0.0",
headers.get(Constants.BUNDLE_VERSION));
Second, you do an in-place update of the Configuration Admin Service bundle to the
new edition:
cmBundle.update(new URL(
System.getProperty("new.configadmin.uri")).openStream());
 
Search WWH ::




Custom Search