Chapter 3. Service Management Framework Runtime 63
Figure 3-13 Selecting the package to export
23.As in Figure 3-13, select the package com.itso.rentals and click OK.
24.Save the file.
The package will be exposed by this bundle and can now be used by other
bundles.
3.3.3 Creating a tester bundle
We have created our Customer bundle, but we have nothing to use it. If we
create another bundle we can test what we have so far.
In this section we will create another bundle that tests the Customer bundle using
the exposed Java package and class methods.
Repeat the steps in 3.3.2, “Procedure” on page 50 to create a test bundle. Use
the values in Table 3-2 on page 64 when creating the new bundle’s name, Java
package name, and Java class name.
64 WCTME: Application Development and Case Study
Table 3-2 Tester bundle values
1. In step 8 on page 54, click the Projects tab and select the
ITSOCustomerBundle check box. See Figure 3-14.
Figure 3-14 Adding the Customer bundle to the Tester bundle’s project path
2. In step 9 on page 54, select the check box next to Create Default Bundle
Activator and then click Finish. See Figure 3-15 on page 65.
Input Value
Bundle Project Name ITSORentalsTesterBundle
package name com.itso.rentals.test
class name ITSORentalsTester
Note: While we use the steps from 3.3.2, “Procedure” on page 50, make the
following changes to some of the steps to create your tester bundle.
Chapter 3. Service Management Framework Runtime 65
Figure 3-15 Creating the default BundleActivator
3. In step 15 on page 57, add the following code in Example 3-4 to the
ITSORentalsTester class:
Example 3-4 Tester bundle code
private BundleContext context;
public ITSORentalsTester(BundleContext context) {
super();
System.out.println("\nBundleTester V1.0");
this.context = context;
init();
}
private void init() {
//short delay to let things settle, since we are starting up the test
immediately
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
66 WCTME: Application Development and Case Study
//basic test of customer bundle
System.out.println("\nTesting Customer Bundle: creating a customer and
calling toString");
Customer c = new Customer("1", "374906", "Jeff", "Martin", "AA 174",
Customer.PENDING,"?");
System.out.println(c);// see toString()
}
4. Perform these extra steps for this project:
a. Open the MANIFEST.MF file (as in step 20 on page 60). Scroll down to
Import Packages.
b. Expand the section Import Packages and select Add...
c. Select the package com.itso.rentals and click OK.
This step creates a dependency between the test bundle and the
customer bundle.
d. Save the file.
e. Open the ExtensionServicesBundleActivator.java file (in the default
package) and add the following code at the end of the start() method:
System.out.println("Starting Bundle Tester");
ITSORentalsTester bt = new ITSORentalsTester(context);
f. Organize Imports and Save the file.
You should now be able to test the ITSOCustomerBundle with the
ITSORentalsTesterBundle. We are only doing a simple test of one bundle
accessing another bundle. We will build on this in the next few chapters.
Tip: To help remove unresolved compiler errors, right-click in the source and
select Source Organize Imports.
Note: The package com.itso.rentals might already have been added
automatically, or you can press the Compute button to fill in the list.
Note: It generally is not a good idea to include a large amount of code in the
start() method. If you have a lot of work to do to set up a service, then create a
separate thread to process that work.

Get IBM Workplace Client Technology Micro Edition Version 5.7.1: Application Development and Case Study now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.