Java Reference
In-Depth Information
probably run on the same base platform (or platforms), so it's worth pulling out com-
mon configuration code into a configuration utility, PaxConfigurer in this case. If you
do this, you can use OptionUtils.combine() to merge the core option array and
Option varargs parameter into one big array.
Using Maven
Pax Exam is well integrated with Maven, so one of the most convenient ways of specify-
ing bundles to install is using their Maven coordinates and the CoreOptions.maven-
Bundle() method. Versions can be explicitly specified, pulled from a pom.xml using
versionAsInProject() , or left implicit to default to the latest version.
Using an existing server install
As well as your application bundles themselves, you'll need to list all the other bundles
in your target runtime environment. If you think about using mavenBundle() calls to
specify every bundle in your server runtime, you may start to feel uneasy. Do you really
need to list out the Maven coordinates of every bundle in your Aries assembly—or
worse yet, every bundle in your full-fledged application server?
Luckily, the answer is no —Pax Exam does provide alternate ways of specifying what
should get installed into your runtime. You can install Pax Runner or Karaf features if
any exist for your server, or point Pax Exam at a directory that contains your server. For
testing applications intended to run on a server, this is the most convenient option—
you probably don't need to test your application with several different OSG i frameworks
or see what happens with different Blueprint implementations, because your applica-
tion server environment will be well defined. Listing 8.7 shows how to configure a Pax
Exam environment based on the Aries assembly you've been using for testing.
Using profiles
Pax Exam also provides some methods to reference convenient sets of bundles, such
as a webProfile() and a set of junitBundles() . Remember that Pax Exam installs
only the bundles you tell it to install—your server probably doesn't ship JU nit, so if
you point Pax Exam at your server directory, you'll need to add in your test class's
JU nit dependencies separately. Because it can be complex, even with profiles, we find
it can be convenient to share the code for setting up the test environment. The follow-
ing listing shows a utility class for setting up a test environment that reproduces the
Aries assembly we've been using throughout.
Listing 8.7
A class that provides options that can be shared between tests
package fancyfoods.department.cheese.test;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.options.extra.DirScannerProvisionOption;
import static org.ops4j.pax.exam.CoreOptions.*;
public class PaxConfigurer {
Path to Aries
assembly
public static Option[] getServerPlatform() {
String ariesAssemblyDir = "$[aries.assembly]/target";
 
Search WWH ::




Custom Search