Search in sources :

Example 46 with FooService

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();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Example 47 with FooService

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");
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Properties(java.util.Properties) Test(org.junit.Test)

Example 48 with FooService

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);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Test(org.junit.Test)

Example 49 with FooService

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);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Properties(java.util.Properties) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 50 with FooService

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);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ServiceReference(org.osgi.framework.ServiceReference) Before(org.junit.Before)

Aggregations

FooService (org.apache.felix.ipojo.runtime.core.services.FooService)123 Test (org.junit.Test)121 ServiceReference (org.osgi.framework.ServiceReference)110 Properties (java.util.Properties)68 Configuration (org.osgi.service.cm.Configuration)33 Hashtable (java.util.Hashtable)30 Dictionary (java.util.Dictionary)28 PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)25 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)24 ServiceContext (org.apache.felix.ipojo.ServiceContext)21 IOException (java.io.IOException)19 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)17 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)15 ConfigurationException (org.osgi.service.cm.ConfigurationException)13 ManagedService (org.osgi.service.cm.ManagedService)13 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)13 Architecture (org.apache.felix.ipojo.architecture.Architecture)11 Factory (org.apache.felix.ipojo.Factory)8 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)5 FooProviderType1 (org.apache.felix.ipojo.runtime.core.components.FooProviderType1)3