Search in sources :

Example 6 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.

the class TestDynamicProps method testProperties3.

@Test
public void testProperties3() {
    ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    Integer intProp = (Integer) sr.getProperty("int");
    Boolean boolProp = (Boolean) sr.getProperty("boolean");
    String strProp = (String) sr.getProperty("string");
    String[] strAProp = (String[]) sr.getProperty("strAProp");
    int[] intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(0));
    assertEquals("Check longProp equality", boolProp, new Boolean(true));
    assertEquals("Check strProp equality", strProp, new String(""));
    assertNotNull("Check strAProp not nullity", strAProp);
    String[] v = new String[0];
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    int[] v2 = new int[0];
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
    // Invoke
    FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(2));
    assertEquals("Check longProp equality", boolProp, new Boolean(true));
    assertEquals("Check strProp equality", strProp, new String("foo"));
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNull("Check intAProp hidding (no value)", intAProp);
    fs = null;
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 7 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.

the class TestDynamicProps method testProperties1.

@Test
public void testProperties1() {
    ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-1");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    Integer intProp = (Integer) sr.getProperty("int");
    Boolean boolProp = (Boolean) sr.getProperty("boolean");
    String strProp = (String) sr.getProperty("string");
    String[] strAProp = (String[]) sr.getProperty("strAProp");
    int[] intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality (1)", intProp, new Integer(2));
    assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
    assertEquals("Check strProp equality (1)", strProp, new String("foo"));
    assertNotNull("Check strAProp not nullity (1)", strAProp);
    String[] v = new String[] { "foo", "bar" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality (1)");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    int[] v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality (1)");
        }
    }
    // Invoke
    FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality (2)", intProp, new Integer(3));
    assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
    assertEquals("Check strProp equality (2)", strProp, new String("bar"));
    assertNotNull("Check strAProp not nullity (2)", strAProp);
    v = new String[] { "foo", "bar", "baz" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality (2)");
        }
    }
    assertNotNull("Check intAProp not nullity (2)", intAProp);
    v2 = new int[] { 3, 2, 1 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality (2)");
        }
    }
    fs = null;
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 8 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.

the class TestDynamicProps method testProperties4.

@Test
public void testProperties4() {
    ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-4");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    Integer intProp = (Integer) sr.getProperty("int");
    Object boolProp = sr.getProperty("boolean");
    Object strProp = sr.getProperty("string");
    Object strAProp = sr.getProperty("strAProp");
    int[] intAProp = (int[]) sr.getProperty("intAProp");
    // Set by the component type.
    assertEquals("Check intProp equality", intProp, new Integer(4));
    assertEquals("Check boolProp equality", boolProp, null);
    assertEquals("Check strProp equality", strProp, null);
    assertNull("Check strAProp  nullity", strAProp);
    // Set by the component type.
    assertNotNull("Check intAProp not nullity", intAProp);
    assertNotNull("Check intAProp not nullity", intAProp);
    int[] v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
    // Invoke
    FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(2));
    assertEquals("Check longProp equality", boolProp, new Boolean(true));
    assertEquals("Check strProp equality", strProp, new String("foo"));
    assertNotNull("Check strAProp not nullity", strAProp);
    String[] v = new String[] { "foo", "bar" };
    for (int i = 0; i < ((String[]) strAProp).length; i++) {
        if (!((String[]) strAProp)[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNull("Check intAProp hidding (no value)", intAProp);
    fs = null;
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 9 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.

the class TestDynamicPropsReconfiguration method testReconfigurationUsingManagedService.

@Test
public void testReconfigurationUsingManagedService() throws IOException, InterruptedException {
    ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    Integer intProp = (Integer) sr.getProperty("int");
    Boolean boolProp = (Boolean) sr.getProperty("boolean");
    String strProp = (String) sr.getProperty("string");
    String[] strAProp = (String[]) sr.getProperty("strAProp");
    int[] intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(0));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "");
    assertNotNull("Check strAProp not nullity", strAProp);
    String[] v = new String[0];
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    int[] v2 = new int[0];
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
    // Reconfiguration
    ConfigurationAdmin admin = osgiHelper.getServiceObject(ConfigurationAdmin.class);
    Configuration configuration = admin.getConfiguration("FooProvider-3", "?");
    Dictionary<String, Object> p3 = new Hashtable<String, Object>();
    p3.put("int", 1);
    p3.put("boolean", true);
    p3.put("string", "foo");
    p3.put("strAProp", new String[] { "foo", "bar", "baz" });
    p3.put("intAProp", new int[] { 1, 2, 3 });
    configuration.update(p3);
    TimeUtils.grace(200);
    sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(1));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "foo");
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar", "baz" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
    // Invoke
    FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(2));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "foo");
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNull("Check intAProp hiding (no value)", intAProp);
    // Reconfiguration
    p3 = new Hashtable<String, Object>();
    p3.put("int", 1);
    p3.put("boolean", true);
    p3.put("string", "foo");
    p3.put("strAProp", new String[] { "foo", "bar", "baz" });
    p3.put("intAProp", new int[] { 1, 2, 3 });
    configuration.update(p3);
    TimeUtils.grace(200);
    sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(1));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "foo");
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar", "baz" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ServiceReference(org.osgi.framework.ServiceReference) FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 10 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService in project felix by apache.

the class TestDynamicPropsReconfiguration method testFactoryReconf.

@Test
public void testFactoryReconf() {
    ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    Integer intProp = (Integer) sr.getProperty("int");
    Boolean boolProp = (Boolean) sr.getProperty("boolean");
    String strProp = (String) sr.getProperty("string");
    String[] strAProp = (String[]) sr.getProperty("strAProp");
    int[] intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(0));
    assertEquals("Check longProp equality", boolProp, new Boolean(true));
    assertEquals("Check strProp equality", strProp, new String(""));
    assertNotNull("Check strAProp not nullity", strAProp);
    String[] v = new String[0];
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    int[] v2 = new int[0];
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
    // Reconfiguration
    ServiceReference fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-Dyn2");
    Factory fact = (Factory) osgiHelper.getRawServiceObject(fact_ref);
    Properties p3 = new Properties();
    p3.put("instance.name", "FooProvider-3");
    p3.put("int", 1);
    p3.put("boolean", true);
    p3.put("string", "foo");
    p3.put("strAProp", new String[] { "foo", "bar", "baz" });
    p3.put("intAProp", new int[] { 1, 2, 3 });
    try {
        fact.reconfigure(p3);
    } catch (Exception e) {
        fail("Unable to reconfigure the instance with : " + p3);
    }
    sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(1));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "foo");
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar", "baz" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
    // Invoke
    FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(2));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "foo");
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNull("Check intAProp hidding (no value)", intAProp);
    // Reconfiguration
    fact_ref = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "PS-FooProviderType-Dyn2");
    fact = (Factory) osgiHelper.getRawServiceObject(fact_ref);
    p3 = new Properties();
    p3.put("instance.name", "FooProvider-3");
    p3.put("int", 1);
    p3.put("boolean", true);
    p3.put("string", "foo");
    p3.put("strAProp", new String[] { "foo", "bar", "baz" });
    p3.put("intAProp", new int[] { 1, 2, 3 });
    try {
        fact.reconfigure(p3);
    } catch (Exception e) {
        fail("Unable to reconfigure the instance with : " + p3);
    }
    sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProvider-3");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality", intProp, new Integer(1));
    assertEquals("Check longProp equality", boolProp, Boolean.TRUE);
    assertEquals("Check strProp equality", strProp, "foo");
    assertNotNull("Check strAProp not nullity", strAProp);
    v = new String[] { "foo", "bar", "baz" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality");
        }
    }
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

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