BindingListener listener = (BindingListener) blueprintContainer.getComponentInstance("bindingListener");
assertNull(listener.getA());
assertNull(listener.getReference());
InterfaceA a = (InterfaceA) blueprintContainer.getComponentInstance("ref2");
try {
a.hello("world");
fail("A ServiceUnavailableException should have been thrown");
} catch (ServiceUnavailableException e) {
// Ignore, expected
}
ServiceRegistration reg1 = bundleContext.registerService(InterfaceA.class.getName(), new InterfaceA() {
public String hello(String msg) {
return "Hello " + msg + "!";
}
}, null);
waitForAsynchronousHandling();
assertNotNull(listener.getA());
assertNotNull(listener.getReference());
assertEquals("Hello world!", a.hello("world"));
Hashtable props = new Hashtable();
props.put(Constants.SERVICE_RANKING, Integer.valueOf(1));
ServiceRegistration reg2 = bundleContext.registerService(InterfaceA.class.getName(), new InterfaceA() {
public String hello(String msg) {
return "Good morning " + msg + "!";
}
}, props);
waitForAsynchronousHandling();
assertNotNull(listener.getA());
assertNotNull(listener.getReference());
assertEquals("Hello world!", a.hello("world"));
reg1.unregister();
waitForAsynchronousHandling();
assertNotNull(listener.getA());
assertNotNull(listener.getReference());
assertEquals("Good morning world!", a.hello("world"));
reg2.unregister();
waitForAsynchronousHandling();
assertNull(listener.getA());
assertNull(listener.getReference());
try {
a.hello("world");
fail("A ServiceUnavailableException should have been thrown");
} catch (ServiceUnavailableException e) {
// Ignore, expected
}
}