Search in sources :

Example 56 with CheckService

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

the class TestFieldProperties method testConfigurationPrimitiveArraysString.

@Test
public void testConfigurationPrimitiveArraysString() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Test check service availability", ref);
    CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = check.getProps();
    byte[] b = (byte[]) props.get("bs");
    short[] s = (short[]) props.get("ss");
    int[] i = (int[]) props.get("is");
    long[] l = (long[]) props.get("ls");
    double[] d = (double[]) props.get("ds");
    float[] f = (float[]) props.get("fs");
    char[] c = (char[]) props.get("cs");
    boolean[] bool = (boolean[]) props.get("bools");
    assertEquals("Check b 0", b[0], 1);
    assertEquals("Check b 1", b[1], 2);
    assertEquals("Check b 2", b[2], 3);
    assertEquals("Check s 0", s[0], 1);
    assertEquals("Check s 1", s[1], 2);
    assertEquals("Check s 2", s[2], 3);
    assertEquals("Check i 0", i[0], 1);
    assertEquals("Check i 1", i[1], 2);
    assertEquals("Check i 2", i[2], 3);
    assertEquals("Check l 0", l[0], 1);
    assertEquals("Check l 1", l[1], 2);
    assertEquals("Check l 2", l[2], 3);
    assertEquals("Check d 0", d[0], 1, 0);
    assertEquals("Check d 1", d[1], 2, 0);
    assertEquals("Check d 2", d[2], 3, 0);
    assertEquals("Check f 0", f[0], 1, 0);
    assertEquals("Check f 1", f[1], 2, 0);
    assertEquals("Check f 2", f[2], 3, 0);
    assertEquals("Check c 0", c[0], 'a');
    assertEquals("Check c 1", c[1], 'b');
    assertEquals("Check c 2", c[2], 'c');
    assertTrue("Check bool 0", bool[0]);
    assertTrue("Check bool 1", bool[0]);
    assertTrue("Check bool 2", bool[0]);
    reconfigureString(instance);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Test check service availability", ref);
    check = (CheckService) osgiHelper.getRawServiceObject(ref);
    props = check.getProps();
    b = (byte[]) props.get("bs");
    s = (short[]) props.get("ss");
    i = (int[]) props.get("is");
    l = (long[]) props.get("ls");
    d = (double[]) props.get("ds");
    f = (float[]) props.get("fs");
    c = (char[]) props.get("cs");
    bool = (boolean[]) props.get("bools");
    assertEquals("2) Check b 0", b[0], 3);
    assertEquals("2) Check b 1", b[1], 2);
    assertEquals("2) Check b 2", b[2], 1);
    assertEquals("2) Check s 0", s[0], 3);
    assertEquals("2) Check s 1", s[1], 2);
    assertEquals("2) Check s 2", s[2], 1);
    assertEquals("2) Check i 0", i[0], 3);
    assertEquals("2) Check i 1", i[1], 2);
    assertEquals("2) Check i 2", i[2], 1);
    assertEquals("2) Check l 0", l[0], 3);
    assertEquals("2) Check l 1", l[1], 2);
    assertEquals("2) Check l 2", l[2], 1);
    assertEquals("2) Check d 0", d[0], 3, 0);
    assertEquals("2) Check d 1", d[1], 2, 0);
    assertEquals("2) Check d 2", d[2], 1, 0);
    assertEquals("2) Check f 0", f[0], 3, 0);
    assertEquals("2) Check f 1", f[1], 2, 0);
    assertEquals("2) Check f 2", f[2], 1, 0);
    assertEquals("2) Check c 0", c[0], 'c');
    assertEquals("2) Check c 1", c[1], 'b');
    assertEquals("2) Check c 2", c[2], 'a');
    assertFalse("2) Check bool 0", bool[0]);
    assertFalse("2) Check bool 1", bool[0]);
    assertFalse("2) Check bool 2", bool[0]);
}
Also used : CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 57 with CheckService

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

the class TestFieldProperties method testConfigurationPrimitiveArraysStringNoValue.

@Test
public void testConfigurationPrimitiveArraysStringNoValue() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    assertNotNull("Test check service availability", ref);
    CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = check.getProps();
    byte[] b = (byte[]) props.get("bs");
    short[] s = (short[]) props.get("ss");
    int[] i = (int[]) props.get("is");
    long[] l = (long[]) props.get("ls");
    double[] d = (double[]) props.get("ds");
    float[] f = (float[]) props.get("fs");
    char[] c = (char[]) props.get("cs");
    boolean[] bool = (boolean[]) props.get("bools");
    assertNull("Check b nullity", b);
    assertNull("Check s nullity", s);
    assertNull("Check i nullity", i);
    assertNull("Check l nullity", l);
    assertNull("Check d nullity", d);
    assertNull("Check f nullity", f);
    assertNull("Check c nullity", c);
    assertNull("Check bool nullity", bool);
    reconfigureString(instance2);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    assertNotNull("Test check service availability", ref);
    check = (CheckService) osgiHelper.getRawServiceObject(ref);
    props = check.getProps();
    b = (byte[]) props.get("bs");
    s = (short[]) props.get("ss");
    i = (int[]) props.get("is");
    l = (long[]) props.get("ls");
    d = (double[]) props.get("ds");
    f = (float[]) props.get("fs");
    c = (char[]) props.get("cs");
    bool = (boolean[]) props.get("bools");
    assertEquals("2) Check b 0", b[0], 3);
    assertEquals("2) Check b 1", b[1], 2);
    assertEquals("2) Check b 2", b[2], 1);
    assertEquals("2) Check s 0", s[0], 3);
    assertEquals("2) Check s 1", s[1], 2);
    assertEquals("2) Check s 2", s[2], 1);
    assertEquals("2) Check i 0", i[0], 3);
    assertEquals("2) Check i 1", i[1], 2);
    assertEquals("2) Check i 2", i[2], 1);
    assertEquals("2) Check l 0", l[0], 3);
    assertEquals("2) Check l 1", l[1], 2);
    assertEquals("2) Check l 2", l[2], 1);
    assertEquals("2) Check d 0", d[0], 3, 0);
    assertEquals("2) Check d 1", d[1], 2, 0);
    assertEquals("2) Check d 2", d[2], 1, 0);
    assertEquals("2) Check f 0", f[0], 3, 0);
    assertEquals("2) Check f 1", f[1], 2, 0);
    assertEquals("2) Check f 2", f[2], 1, 0);
    assertEquals("2) Check c 0", c[0], 'c');
    assertEquals("2) Check c 1", c[1], 'b');
    assertEquals("2) Check c 2", c[2], 'a');
    assertFalse("2) Check bool 0", bool[0]);
    assertFalse("2) Check bool 1", bool[0]);
    assertFalse("2) Check bool 2", bool[0]);
}
Also used : CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 58 with CheckService

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

the class TestFieldProperties method testConfigurationObj.

@Test
public void testConfigurationObj() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Test check service availability", ref);
    CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = check.getProps();
    String s = (String) props.get("string");
    String[] ss = (String[]) props.get("strings");
    assertEquals("Check string", s, "foo");
    assertEquals("Check strings 0", ss[0], "foo");
    assertEquals("Check strings 1", ss[1], "bar");
    assertEquals("Check strings 2", ss[2], "baz");
    reconfigure(instance);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    check = (CheckService) osgiHelper.getRawServiceObject(ref);
    props = check.getProps();
    s = (String) props.get("string");
    ss = (String[]) props.get("strings");
    assertEquals("2) Check string", s, "bar");
    assertEquals("2) Check strings 0", ss[0], "baz");
    assertEquals("2) Check strings 1", ss[1], "bar");
    assertEquals("2) Check strings 2", ss[2], "foo");
}
Also used : CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 59 with CheckService

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

the class TestFieldProperties method testConfigurationObjNoValue.

@Test
public void testConfigurationObjNoValue() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
    Properties props = check.getProps();
    String s = (String) props.get("string");
    String[] ss = (String[]) props.get("strings");
    assertEquals("Check string", s, null);
    assertEquals("Check strings", ss, null);
    reconfigure(instance2);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    check = (CheckService) osgiHelper.getRawServiceObject(ref);
    props = check.getProps();
    s = (String) props.get("string");
    ss = (String[]) props.get("strings");
    assertEquals("2) Check string", s, "bar");
    assertEquals("2) Check strings 0", ss[0], "baz");
    assertEquals("2) Check strings 1", ss[1], "bar");
    assertEquals("2) Check strings 2", ss[2], "foo");
}
Also used : CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 60 with CheckService

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

the class TestCompositeAPI method testAPI2.

@Test
public void testAPI2() {
    Factory fact1 = ipojoHelper.getFactory("composite.empty");
    Properties p = new Properties();
    p.put("instance.name", "empty-2");
    ComponentInstance empty = null;
    try {
        empty = fact1.createComponentInstance(p);
    } catch (Exception e) {
        e.printStackTrace();
    }
    ServiceContext sc = getServiceContext(empty);
    Factory fact2 = ipojoHelper.getFactory(sc, "composite.test.2");
    Properties props2 = new Properties();
    props2.put("instance.name", "4");
    Factory fact3 = ipojoHelper.getFactory(sc, "composite.test.3");
    Properties props3 = new Properties();
    props3.put("instance.name", "5");
    ComponentInstance comp2 = null;
    ComponentInstance comp3 = null;
    try {
        comp2 = fact2.createComponentInstance(props2, sc);
        comp3 = fact3.createComponentInstance(props3, sc);
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
    assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
    ServiceReference ref = null;
    ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "4");
    assertNotNull("Check ref", ref);
    CheckService cs = (CheckService) sc.getService(ref);
    assertTrue("Check invoke", cs.check());
    comp3.dispose();
    comp2.dispose();
    empty.dispose();
}
Also used : ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)124 Test (org.junit.Test)122 ServiceReference (org.osgi.framework.ServiceReference)90 Properties (java.util.Properties)87 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)50 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)25 BundleContext (org.osgi.framework.BundleContext)20 Factory (org.apache.felix.ipojo.Factory)11 ServiceContext (org.apache.felix.ipojo.ServiceContext)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)6 Architecture (org.apache.felix.ipojo.architecture.Architecture)6 Hashtable (java.util.Hashtable)5 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)4 ProvidedServiceDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription)2 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)2 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)2 CallbackCheckService (org.apache.felix.ipojo.runtime.core.services.CallbackCheckService)2 Before (org.junit.Before)2 List (java.util.List)1