OSGi Test Stubs 1.0.0.M1
I'm pleased to announce the 1.0.0.M1 release of SpringSource's OSGi Test Stubs. These stubs offer a way to unit test complex OSGi Framework interactions without needing a full OSGi container.
The Problem
As the dm Server team has been developing, we found that one of the biggest problem areas for testing for us was in BundleActivators. Our BundleActivators do quite a bit of publishing services to the service registry as well as consuming services using ServiceTrackers. These kinds of tasks involve many interwoven calls to BundleContexts, Bundles, ServiceRegistrations, and ServiceReferences. In the beginning, these activators were simple enough that not much unit testing was done on them, and we depended on integration tests to catch any bugs that were introduced. As time went on though, the activators became more complex and unit testing became a more pressing need. We started using EasyMock for these tests, but found that they were very complex, hard to maintain, and most importantly hard to understand.@Test
public void startAndStop() throws Exception {
BundleActivator bundleActivator = new DumpBundleActivator();
BundleContext context = createMock(BundleContext.class);
Filter filter = createMock(Filter.class);
String filterString = "(objectClass=" + DumpContributor.class.getName() + ")";
expect(context.createFilter(filterString)).andReturn(filter);
context…