Java Reference
In-Depth Information
junit.framework —We need this package because we have some tests to exe-
cute in the Felix service platform. More on this later in the chapter.
com.manning.junitbook.ch16.service —We use the service that's already
installed, so we need to specify its package here.
The one thing that's left is to navigate on the command line to the ch16-osgi/calcula-
tor-client folder from the source code of the topic and invoke the appropriate Ant or
Maven script. You do this the exact same way we already showed—no matter what
script you use, the result should be identical.
Get the JAR file that's generated from the build and copy it to the FELIX_HOME /
bundle folder. Go to the Felix command-line tool and invoke the two commands for
installing and starting the bundle:
-> install file:bundle/calculator-client.jar
-> start [BundleID]
Again, you need to remember the assigned BundleID for this bundle and specify it
when starting the bundle. If you don't remember it, use the ps command to find it.
Once the bundle is started, you will be asked to enter an operation and numbers
separated by spaces.
Our client application implementation is so simple that we skipped data validation
and exception handling. What happens if we were to enter a blank line or a random
string? An exception would be raised, something we don't want to happen.
How do we test that the client application behaves in the expected way? We need
to have some kind of integration tests that we execute inside the service platform (just
like in chapter 14 where we executed Cactus tests inside the servlet container). That's
exactly what we do next. In the next section, we introduce an OSG i testing framework
called JU nit4 OSG i; we also write some tests with that framework and include them in a
separate test bundle.
16.3
Testing OSGi services
When it comes to testing OSG i services, we can apply the same categorization that
we made in the second part of the topic. The normal JU nit tests that you already
know how to write would exercise each of your services on its own. Our attention is
mainly focused on the integration tests that test the interaction between the differ-
ent services. So for implementing integration tests there are different approaches
that you might take; we already covered those different approaches in the second
part of the topic, and they include black box testing, using mock objects, and in-
container testing.
As for black box testing, there isn't much you can do. A form of black box testing
would be to get an OSG i container, install your services there, and hand it to someone
to start playing around and test it “in the black.”
We take a closer look at the other two approaches in the next sections.
 
 
Search WWH ::




Custom Search