import org.osgi.framework.ServiceReference;
public class NullCheck extends OSGiTestCase {
public void testNull() {
IPOJOHelper helper = new IPOJOHelper(this);
String factName = "PS-Null";
String compName = "NullCheck";
ServiceReference ref = null;
// Check that no Foo Service are available
ref = getServiceReference(FooService.class.getName());
assertNull("FS already available", ref);
// Get the factory to create a component instance
Factory fact = helper.getFactory(factName);
assertNotNull("Cannot find the factory FooProvider-1", fact);
// Don't give any configuration so, properties are null.
helper.createComponentInstance(factName, compName);
// Get a FooService provider
ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
assertNotNull("FS not available", ref);
// Check service properties
assertNull(ref.getProperty("prop1"));
assertNotNull(ref.getProperty("prop2"));
// Test foo invocation
FooService fs = (FooService) getServiceObject(ref);
assertTrue("FooService invocation failed", fs.foo());
ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
// Check service properties
assertNotNull(ref.getProperty("prop1"));
assertNull(ref.getProperty("prop2"));
helper.dispose();
// Check that there is no more FooService
ref = getServiceReference(FooService.class.getName(), null);