use of org.apache.aries.blueprint.sample.DefaultRunnable in project aries by apache.
the class TestReferences method testDefaultReference.
@SuppressWarnings("rawtypes")
@Test
public void testDefaultReference() throws Exception {
BlueprintContainer blueprintContainer = Helper.getBlueprintContainerForBundle(context(), "org.apache.aries.blueprint.sample");
assertNotNull(blueprintContainer);
Runnable refRunnable = (Runnable) blueprintContainer.getComponentInstance("refWithDefault");
DefaultRunnable defaultRunnable = (DefaultRunnable) blueprintContainer.getComponentInstance("defaultRunnable");
refRunnable.run();
waitForAsynchronousHandling();
Thread.sleep(2000);
assertEquals("The default runnable was not called", 1, defaultRunnable.getCount());
final AtomicBoolean called = new AtomicBoolean(false);
Runnable mockService = new Runnable() {
public void run() {
called.set(true);
}
};
ServiceRegistration reg = bundleContext.registerService(Runnable.class.getName(), mockService, null);
waitForAsynchronousHandling();
Thread.sleep(2000);
refRunnable.run();
assertEquals("The default runnable was called when a service was bound", 1, defaultRunnable.getCount());
Assert.assertTrue("Service should have been called", called.get());
reg.unregister();
waitForAsynchronousHandling();
Thread.sleep(2000);
refRunnable.run();
assertEquals("The default runnable was not called", 2, defaultRunnable.getCount());
}
Aggregations