Search in sources :

Example 76 with CheckService

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

the class TestMethodProperties method testConfigurationObjNoValue.

@Test
public void testConfigurationObjNoValue() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.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, null);
    assertEquals("Check strings", ss, null);
    Integer upString = (Integer) props.get("upstring");
    Integer upStrings = (Integer) props.get("upstrings");
    assertEquals("Check upString", upString, new Integer(0));
    assertEquals("Check upStrings", upStrings, new Integer(0));
    reconfigure(instance3);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
    assertNotNull("Test check service availability", ref);
    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");
    upString = (Integer) props.get("upstring");
    upStrings = (Integer) props.get("upstrings");
    assertEquals("2) Check upString", upString, new Integer(1));
    assertEquals("2) Check upStrings", upStrings, new Integer(1));
}
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 77 with CheckService

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

the class TestMethodProperties method testConfigurationPrimitive2String.

@Test
public void testConfigurationPrimitive2String() {
    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("b");
    Short s = (Short) props.get("s");
    Integer i = (Integer) props.get("i");
    Long l = (Long) props.get("l");
    Double d = (Double) props.get("d");
    Float f = (Float) props.get("f");
    Character c = (Character) props.get("c");
    Boolean bool = (Boolean) props.get("bool");
    assertEquals("Check b", b, new Byte("1"));
    assertEquals("Check s", s, new Short("1"));
    assertEquals("Check i", i, new Integer("1"));
    assertEquals("Check l", l, new Long("1"));
    assertEquals("Check d", d, new Double("1"));
    assertEquals("Check f", f, new Float("1"));
    assertEquals("Check c", c, new Character('a'));
    assertEquals("Check bool", bool, new Boolean("true"));
    // Integer upb = (Integer) props.get("upb");
    // Integer ups = (Integer) props.get("ups");
    // Integer upi = (Integer) props.get("upi");
    // Integer upl = (Integer) props.get("upl");
    // Integer upd = (Integer) props.get("upd");
    // Integer upf = (Integer) props.get("upf");
    // Integer upc = (Integer) props.get("upc");
    // Integer upbool = (Integer) props.get("upbool");
    // 
    // assertEquals("Check upb", upb, new Integer(1));
    // assertEquals("Check ups", ups, new Integer(1));
    // assertEquals("Check upi", upi, new Integer(1));
    // assertEquals("Check upl", upl, new Integer(1));
    // assertEquals("Check upd", upd, new Integer(1));
    // assertEquals("Check upf", upf, new Integer(1));
    // assertEquals("Check upc", upc, new Integer(1));
    // assertEquals("Check upbool", upbool, new Integer(1));
    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("b");
    s = (Short) props.get("s");
    i = (Integer) props.get("i");
    l = (Long) props.get("l");
    d = (Double) props.get("d");
    f = (Float) props.get("f");
    c = (Character) props.get("c");
    bool = (Boolean) props.get("bool");
    assertEquals("2) Check b (" + b + ")", b, new Byte("2"));
    assertEquals("2) Check s", s, new Short("2"));
    assertEquals("2) Check i", i, new Integer("2"));
    assertEquals("2) Check l", l, new Long("2"));
    assertEquals("2) Check d", d, new Double("2"));
    assertEquals("2) Check f", f, new Float("2"));
    assertEquals("2) Check c", c, new Character('b'));
    assertEquals("2) Check bool", bool, new Boolean("false"));
// upb = (Integer) props.get("upb");
// ups = (Integer) props.get("ups");
// upi = (Integer) props.get("upi");
// upl = (Integer) props.get("upl");
// upd = (Integer) props.get("upd");
// upf = (Integer) props.get("upf");
// upc = (Integer) props.get("upc");
// upbool = (Integer) props.get("upbool");
// 
// assertEquals("2) Check upb", upb, new Integer(2));
// assertEquals("2) Check ups", ups, new Integer(2));
// assertEquals("2) Check upi", upi, new Integer(2));
// assertEquals("2) Check upl", upl, new Integer(2));
// assertEquals("2) Check upd", upd, new Integer(2));
// assertEquals("2) Check upf", upf, new Integer(2));
// assertEquals("2) Check upc", upc, new Integer(2));
// assertEquals("2) Check upbool", upbool, new Integer(2));
}
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 78 with CheckService

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

the class TestMethodProperties method testConfigurationObjStringNoValue.

@Test
public void testConfigurationObjStringNoValue() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.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, null);
    assertEquals("Check strings", ss, null);
    Integer upString = (Integer) props.get("upstring");
    Integer upStrings = (Integer) props.get("upstrings");
    assertEquals("Check upString", upString, new Integer(0));
    assertEquals("Check upStrings", upStrings, new Integer(0));
    reconfigureString(instance3);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance3.getInstanceName());
    assertNotNull("Test check service availability", ref);
    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");
    upString = (Integer) props.get("upstring");
    upStrings = (Integer) props.get("upstrings");
    assertEquals("2) Check upString", upString, new Integer(1));
    assertEquals("2) Check upStrings", upStrings, new Integer(1));
}
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 79 with CheckService

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

the class TestMethodProperties 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");
    // Integer upString = (Integer) props.get("upstring");
    // Integer upStrings = (Integer) props.get("upstrings");
    // 
    // assertEquals("Check upString", upString, new Integer(1));
    // assertEquals("Check upStrings", upStrings, new Integer(1));
    reconfigure(instance);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Test check service availability", ref);
    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");
// upString = (Integer) props.get("upstring");
// upStrings = (Integer) props.get("upstrings");
// 
// assertEquals("2) Check upString", upString, new Integer(2));
// assertEquals("2) Check upStrings", upStrings, new Integer(2));
}
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 80 with CheckService

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

the class TestMethodProperties method testConfigurationObj2String.

@Test
public void testConfigurationObj2String() {
    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();
    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");
    // Integer upString = (Integer) props.get("upstring");
    // Integer upStrings = (Integer) props.get("upstrings");
    // 
    // assertEquals("Check upString", upString, new Integer(1));
    // assertEquals("Check upStrings", upStrings, new Integer(1));
    reconfigureString(instance2);
    ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    assertNotNull("Test check service availability", ref);
    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");
// upString = (Integer) props.get("upstring");
// upStrings = (Integer) props.get("upstrings");
// 
// assertEquals("2) Check upString", upString, new Integer(2));
// assertEquals("2) Check upStrings", upStrings, new Integer(2));
}
Also used : CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) 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