Example test suite: OSGi
In the jet-example-osgi directory, there is an example test suite for how to start OSGi bundles on machines that run JAG.
The example uses the Apache Felix OSGi framework, but the code is OSGi generic, and should work with any OSGi framework (just put another framework than Apache Felix in the ts_dir/lib/test directory).
To run this example, after you have built jet, do:
cd jet/example-osgi/jet-example-osgi-test ./run.sh
Test infrastructure code
The OSGi example test code in the jet-example-osgi/jet-example-osgi-test/ directory has a good example of a client, which doesn't exist in other example test suites.
OSGi Client
The OSGiClient is the client side (runs in JET) code that talks JMXRemote with the server side OSGiFramework{,MBean}. The client is created by the OSGiClientFactory class. The clients lets you start and stop OSGi frameworks on a given host (inside JAG), install and uninstall bundles into these frameworks, and start and stop these bundles.
OSGiClient only has responsibility for communicating with the MBean on JAG, and for handling communication errors etc, the actual work is done inside JAG by the OSGiFramework class. This class only imports classes from org.osgi.framework, so it is OSGi framework neutral.
OSGiSetup
OSGiSetup uses OSGIClient to start a new OSGi framework on the first server or client machine (of there are no server machines). in tearDown() it stops the OSGiFramework.
The OSGi Bundle
The supplied example OSGi bundle in jet-example-osgi/jet-example-osgi-bundle was created by following the instructions in Sonatype Maven Handbook to create a OGSi Project and then a OSGi Bundle (which lives in jet-example-osgi/jet-example-osgi-bundle/jet-example-osgi-bundle-instance (puh)).
The example isn't very fancy, but the ExampleActivator class resgisters, starts and stops a service, which is implemented in ExampleServiceImpl. The implementation reads a setting from OSGi (which port number to listen to, set from the OSGiSetUp, and starts a simple socket EchoServer, which will write everything it reads back to the socket it reads from.
Test Case
The OSGiTestCase is a simple example that uses the OSGiClient to install and start a bundle, then tests the EchoServer, and then shuts down the bundle that it has tested.





