Search in sources :

Example 36 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project felix by apache.

the class TestUpdatedMethodAndConfigAdmin method testStaticNoValue.

@Test
public void testStaticNoValue() 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("bar", new Integer(2));
    conf.put("foo", "foo");
    // 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 -2", fooP, "foo");
    assertEquals("Check bar equality -2", barP, new Integer(2));
    assertEquals("Check baz equality -2", bazP, "zab");
    // Get Service
    FooService fs = (FooService) osgiHelper.getRawServiceObject(fooRef);
    Integer updated = (Integer) fs.fooProps().get("updated");
    Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
    assertEquals("Check updated", 1, updated.intValue());
    assertEquals("Check last updated", 3, dict.size());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 37 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project felix by apache.

the class TestUpdatedMethodAndConfigAdmin method testDynamicString.

@Test
public void testDynamicString() throws IOException, InterruptedException {
    ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertNotNull("Check FS availability", fooRef);
    String fooP = (String) fooRef.getProperty("foo");
    Integer barP = (Integer) fooRef.getProperty("bar");
    String bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality", fooP, "foo");
    assertEquals("Check bar equality", barP, new Integer(2));
    assertEquals("Check baz equality", bazP, "baz");
    ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
    assertNotNull("Check Configuration Admin availability", admin);
    Configuration configuration = admin.getConfiguration(instance.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(), instance.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, new Integer(0));
    assertEquals("Check baz equality", bazP, "zab");
    // Check field value
    FooService fs = (FooService) osgiHelper.getRawServiceObject(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, new Integer(0));
    Integer updated = (Integer) fs.fooProps().get("updated");
    Dictionary dict = (Dictionary) fs.fooProps().get("lastupdated");
    assertEquals("Check updated", 1, updated.intValue());
    assertEquals("Check last updated", 3, dict.size());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) 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 38 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project felix by apache.

the class TestUpdatedNoArgMethodAndConfigAdmin method testStaticNoValue.

@Test
public void testStaticNoValue() throws InterruptedException, IOException {
    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 ad = 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("bar", new Integer(2));
    conf.put("foo", "foo");
    // 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 -2", fooP, "foo");
    assertEquals("Check bar equality -2", barP, new Integer(2));
    assertEquals("Check baz equality -2", bazP, "zab");
    // Get Service
    FooService fs = (FooService) osgiHelper.getRawServiceObject(fooRef);
    Integer updated = (Integer) fs.fooProps().get("updated");
    assertEquals("Check updated", 1, updated.intValue());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 39 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project felix by apache.

the class TestUpdatedNoArgMethodAndConfigAdmin method testDynamic.

@Test
public void testDynamic() throws InterruptedException, IOException {
    ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertNotNull("Check FS availability", fooRef);
    String fooP = (String) fooRef.getProperty("foo");
    Integer barP = (Integer) fooRef.getProperty("bar");
    String bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality", fooP, "foo");
    assertEquals("Check bar equality", barP, new Integer(2));
    assertEquals("Check baz equality", bazP, "baz");
    ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
    assertNotNull("Check Configuration Admin availability", admin);
    Configuration configuration = admin.getConfiguration(instance.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", new Integer(0));
    // Asynchronous dispatching of the configuration
    configuration.update(conf);
    grace();
    // Recheck props
    fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.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, new Integer(0));
    assertEquals("Check baz equality", bazP, "zab");
    // Check field value
    FooService fs = (FooService) osgiHelper.getRawServiceObject(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, new Integer(0));
    Integer updated = (Integer) fs.fooProps().get("updated");
    assertEquals("Check updated", 1, updated.intValue());
}
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 40 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project felix by apache.

the class TestUpdatedNoArgMethodAndConfigAdmin method testStatic.

@Test
public void testStatic() throws IOException, InterruptedException {
    ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertNotNull("Check FS availability", fooRef);
    String fooP = (String) fooRef.getProperty("foo");
    Integer barP = (Integer) fooRef.getProperty("bar");
    String bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality -1", fooP, "foo");
    assertEquals("Check bar equality -1", barP, new Integer(2));
    assertEquals("Check baz equality -1", bazP, "baz");
    ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
    assertNotNull("Check Configuration Admin availability", admin);
    Configuration configuration = admin.getConfiguration(instance.getInstanceName(), getTestBundle().getLocation());
    // Configuration of baz
    Dictionary<String, Object> conf = new Hashtable<String, Object>();
    conf.put("baz", "zab");
    conf.put("bar", new Integer(2));
    conf.put("foo", "foo");
    // Asynchronous dispatching of the configuration
    configuration.update(conf);
    grace();
    // Recheck props
    fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    fooP = (String) fooRef.getProperty("foo");
    barP = (Integer) fooRef.getProperty("bar");
    bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality -2", fooP, "foo");
    assertEquals("Check bar equality -2", barP, new Integer(2));
    assertEquals("Check baz equality -2", bazP, "zab");
    // Get Service
    FooService fs = (FooService) osgiHelper.getRawServiceObject(fooRef);
    Integer updated = (Integer) fs.fooProps().get("updated");
    assertEquals("Check updated", 1, updated.intValue());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)211 Configuration (org.osgi.service.cm.Configuration)114 Test (org.junit.Test)65 Hashtable (java.util.Hashtable)57 ServiceReference (org.osgi.framework.ServiceReference)52 IOException (java.io.IOException)44 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)25 BundleContext (org.osgi.framework.BundleContext)25 Subject (javax.security.auth.Subject)24 Dictionary (java.util.Dictionary)23 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)21 Bundle (org.osgi.framework.Bundle)16 Properties (java.util.Properties)15 File (java.io.File)8 HashSet (java.util.HashSet)7 BundleException (org.osgi.framework.BundleException)7 Method (java.lang.reflect.Method)6 ObjectName (javax.management.ObjectName)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4