use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestUpdated method testNumberOfUpdatedCalls.
@Test
public void testNumberOfUpdatedCalls() throws IOException {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("message", "message");
props.put("propagated", "propagated");
props.put(".private", "wow");
Configuration configuration = admin.createFactoryConfiguration(factoryName, "?");
configuration.update(props);
FooService fs = osgiHelper.waitForService(FooService.class, "(instance.name=" + configuration.getPid() + ")", 1000);
assertEquals(fs.getInt(), 1);
// Update the property
props.put("message", "message2");
props.put("propagated", "propagated2");
props.put(".private", "wow2");
configuration.update(props);
grace();
assertEquals(fs.getInt(), 2);
// Remove a property
props.remove("propagated");
configuration.update(props);
grace();
assertEquals(fs.getInt(), 3);
configuration.delete();
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestComplexConfigurations method testConfiguration.
@Test
public void testConfiguration() {
if (isKnopflerfish()) {
// Test disabled on KF
return;
}
TimeUtils.grace(500);
osgiHelper.waitForService(FooService.class, null, 10000);
FooService fs1 = ipojoHelper.getServiceObjectByName(FooService.class, "complex1");
Properties props1 = fs1.fooProps();
Assert.assertTrue(((String) props1.get("content")).contains("I'm file 1"));
Assert.assertEquals(((Bean) props1.get("bean")).getMessage(), "I'm 1");
Assert.assertEquals(((Bean) props1.get("bean")).getCount(), 1);
Assert.assertEquals(((Map<String, String>) props1.get("map")).get("a"), "b");
FooService fs2 = ipojoHelper.getServiceObjectByName(FooService.class, "complex2");
Assert.assertNotNull(fs2);
Properties props2 = fs2.fooProps();
Assert.assertTrue(((String) props2.get("content")).contains("I'm file 2"));
Assert.assertEquals(((Bean) props2.get("bean")).getMessage(), "I'm 2");
Assert.assertEquals(((Bean) props2.get("bean")).getCount(), 2);
Assert.assertEquals(((Map<String, String>) props2.get("map")).get("a"), "b2");
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestConfigurationOfMyComponent method testConfiguration.
@Test
public void testConfiguration() throws IOException {
if (isKnopflerfish()) {
// Test disabled on KF
return;
}
TimeUtils.grace(500);
osgiHelper.waitForService(FooService.class, null, 10000);
// Check configuration
FooService fs = osgiHelper.getServiceObject(FooService.class);
Assert.assertTrue(fs.foo());
Assert.assertEquals(fs.getDouble(), 1.0, 0);
Assert.assertEquals(fs.getInt(), 1);
Assert.assertEquals(fs.getLong(), 1l);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestDynamicallyConfigurablePropertiesUsingConfigAdmin method testDynamicNoValue.
@Test
public void testDynamicNoValue() throws IOException, InterruptedException {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
Object fooP = fooRef.getProperty("foo");
Object barP = fooRef.getProperty("bar");
Object bazP = fooRef.getProperty("baz");
assertEquals("Check foo equality -1", fooP, null);
assertEquals("Check bar equality -1", barP, null);
assertEquals("Check baz equality -1", bazP, null);
ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
assertNotNull("Check Configuration Admin availability", admin);
Configuration configuration = admin.getConfiguration(instance2.getInstanceName(), getTestBundle().getLocation());
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", 0);
// Asynchronous dispatching of the configuration
configuration.update(conf);
grace();
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, 0);
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, 0);
osgiHelper.getContext().ungetService(fooRef);
}
use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.
the class TestListeners method setUp.
@Before
public void setUp() {
Properties p = new Properties();
p.put("instance.name", "FooProvider-42");
p.put("int", 4);
p.put("boolean", false);
p.put("string", "bar");
p.put("strAProp", new String[] { "bar", "foo" });
p.put("intAProp", new int[] { 1, 2, 3 });
fooProvider = ipojoHelper.createComponentInstance("CONFIG-FooProviderType-ConfUpdated", p);
fooConfig = (ConfigurationHandlerDescription) fooProvider.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:properties");
// Get the service
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-42");
foo = (FooService) osgiHelper.getRawServiceObject(ref);
}
Aggregations