Java Reference
In-Depth Information
Option bootPackages = bootDelegationPackages(
"javax.transaction", "javax.transaction.*");
String f = "*-*.jar";
DirScannerProvisionOption unfiltered =
Option ariesAsembly = unfiltered.filter(f);
Option osgiFramework = equinox().version("3.5.0");
return options(bootPackages, ariesAsembly, junitBundles(),
Only include JARs
with “-” in name
Here $[aries.assembly] should be replaced with a path—there's no clever variable sub-
stitution going on!
will install all the bundles in the scanned directory into an OSG i framework.
Because the scanned directory contains its own OSG i framework bundle, this
means you may getting slightly more than you bargained for. Installing one
OSG i framework into another is possible, but the classloading gets complicated!
To avoid installing multiple frameworks, you can either copy all your server
bundles except for the OSG i framework itself to another directory, or rename
the OSG i bundle so that it's not captured by your filter. For example, if you
rename the bundle to osgi.jar (no dash) and then specify the filter "*-*.jar") ,
Pax Exam will install every JAR except for your framework JAR (assuming all the
other JAR s have dashes before the version number).
All this setup might seem like a lot of work, and it is. Luckily, once you've done it for
one test, writing all your other tests will be much easier.
What kind of things should you be doing in your tests? The first thing to establish is
that your bundles are present, and that they're started. (And if not, why not!) Bundles
that haven't started are a common cause of problems in OSG i applications, and if any-
thing, these problems are even more common with Pax Exam because of the com-
plexity of setting up the environment. Despite this, checking bundle states isn't a first-
class Pax Exam diagnostic feature. It's worth adding some utility methods in your tests
that try to start the bundles in your framework to make sure everything is started, and
fail the test if any bundles can't start.
After this setup verification, what you test will depend on the exact design of your
application. Verifying that all your services, including Blueprint ones, are present in
the Service Registry is a good next step—and the final step is to make sure your ser-
vices all behave as expected, for a variety of inputs. The following listing shows a test
for the cheese bundle.
Listing 8.8
A Pax Exam integration test
public void testOfferReturnsCorrectFood(BundleContext ctx) {
Search WWH ::

Custom Search