import org.osgi.framework.ServiceReference;
public class OSGiPropertiesTest extends OSGiTestCase {
public void testOSGiProperties() {
IPOJOHelper helper = new IPOJOHelper(this);
String factName = "PS-FooProviderType-1";
String compName = "FooProvider-1";
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);
Dictionary conf = new Properties();
conf.put(Constants.SERVICE_DESCRIPTION, "description");
conf.put(Constants.SERVICE_RANKING, "10");
conf.put(Constants.SERVICE_VENDOR, "ASF");
conf.put(Constants.SERVICE_PID, "my.pid");
helper.createComponentInstance(factName, compName, conf);
// Get a FooService provider
ref = getServiceReference(FooService.class.getName(), "(" + "instance.name" + "=" + compName + ")");
assertNotNull("FS not available", ref);
// Check properties
assertEquals("description", ref.getProperty(Constants.SERVICE_DESCRIPTION));
assertEquals(new Integer(10), ref.getProperty(Constants.SERVICE_RANKING));
assertEquals("ASF", ref.getProperty(Constants.SERVICE_VENDOR));
assertEquals("my.pid", ref.getProperty(Constants.SERVICE_PID));
// Test foo invocation
FooService fs = (FooService) getServiceObject(ref);
assertTrue("FooService invocation failed", fs.foo());
helper.dispose();
// Check that there is no more FooService
ref = getServiceReference(FooService.class.getName(), null);