Arquillian support for OSGi
thomas.diesler Jun 24, 2010 5:52 AMFolks,
I took a look at Arquillian to see how our OSGi effort would fit with the Arquillian testing strategy. Writing OSGi test cases that interact with the framework infrastructure and services provided by other (bundle) deployments is very simmilar to the "in-container" testing notion of Arquillian.
First of all I'd like to say that, the API design, the documentation and last but not least the quality of the code base is really impressive - so it was very easy for me to do the first cut. Well done!
In JBoss OSGi we have the Husky Test Framework for embedded and remote OSGi bundle testing. Many of the concepts in Husky are mirrored in Arquillian. To provide good support for OSGi in Arquillian would essentially mean to port the Husky implementation to the Arquillian API/SPI.
The first cut of this effort provides OSGi bundle testing in an embedded framework.
A sample test case would look like this:
@RunWith(Arquillian.class) public class OSGiEmbeddedIntegrationTestCase { @Deployment public static JavaArchive createdeployment() { final JavaArchive archive = ShrinkWrap.create("test.jar", JavaArchive.class); archive.setManifest(new Asset() { public InputStream openStream() { OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance(); builder.addBundleSymbolicName(archive.getName()); builder.addBundleManifestVersion(2); return builder.openStream(); } }); return archive.addClasses(OSGiEmbeddedIntegrationTestCase.class); } @Inject Framework framework; @Test public void testFrameworkInjection() throws Exception { assertNotNull("Framework injected", framework); } @Inject Bundle bundle; @Test public void testBundleInjection() throws Exception { assertNotNull("Bundle injected", bundle); assertEquals("Bundle INSTALLED", Bundle.INSTALLED, bundle.getState()); bundle.start(); assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState()); bundle.stop(); assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundle.getState()); } }
The OSGiEmbeddedContainer bootstraps the Framework and deployes the Bundle. The OSGiTestEnricher injects the Framework and Bundle instances if required.
Stuff that still needs to be done would include
#1 install the test runner as a bundle, so that types (i.e. services) can be accessed from the test case
#2 support remote target containers
#3 support multiple bundle deployments
#4 support bundle deployment during test method execution
#5 ... other?
In case you agree, I could merge my github osgi branch to Arquillion svn/trunk - just in time for you to talk about it @JBW
Initial support for OSGi bundle testing
https://jira.jboss.org/browse/ARQ-188
cheers
-thomas