Search in sources :

Example 1 with CheckService

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

the class HandlerTest method testConfiguration3.

@Test
public void testConfiguration3() {
    // Check the availability of CheckService
    String name = "HandlerTest-2-empty";
    ServiceReference sr = null;
    ServiceReference[] refs = null;
    String filter = "(" + "instance.name" + "=" + name + ")";
    refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
    if (refs != null) {
        sr = refs[0];
    }
    assertNotNull("Check the check service availability", sr);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(sr);
    Dictionary<String, Object> p = cs.getProps();
    assertEquals("Assert 'simple' equality", p.get("Simple"), "Simple");
    // instance name, simple and changes.
    assertEquals("Size of p", 3, p.size());
    cs = null;
}
Also used : CheckService(org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with CheckService

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

the class HandlerTest method testConfiguration2.

@Test
public void testConfiguration2() {
    // Check the availability of CheckService
    String name = "HandlerTest-2";
    ServiceReference sr = null;
    ServiceReference[] refs = null;
    String filter = "(" + "instance.name" + "=" + name + ")";
    refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
    if (refs != null) {
        sr = refs[0];
    }
    assertNotNull("Check the check service availability", sr);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(sr);
    Dictionary<String, Object> p = cs.getProps();
    assertEquals("Assert 'simple' equality", p.get("Simple"), "Simple");
    assertEquals("Assert 'a' equality", p.get("Map1"), "a");
    assertEquals("Assert 'b' equality", p.get("Map2"), "b");
    assertEquals("Assert 'c' equality", p.get("Map3"), "c");
}
Also used : CheckService(org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with CheckService

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

the class HandlerTest method testConfiguration1.

@Test
public void testConfiguration1() {
    // Check the availability of CheckService
    String name = "HandlerTest-1";
    ServiceReference sr = null;
    ServiceReference[] refs = null;
    String filter = "(" + "instance.name" + "=" + name + ")";
    refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
    if (refs != null) {
        sr = refs[0];
    }
    assertNotNull("Check the check service availability", sr);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(sr);
    Dictionary<String, Object> p = cs.getProps();
    assertEquals("Assert 'simple' equality", p.get("Simple"), "simple");
    assertEquals("Assert 'a' equality", p.get("Map1"), "a");
    assertEquals("Assert 'b' equality", p.get("Map2"), "b");
    assertEquals("Assert 'c' equality", p.get("Map3"), "c");
}
Also used : CheckService(org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 4 with CheckService

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

the class HandlerWithFieldInterceptorTest method testFieldInterception.

@Test
public void testFieldInterception() {
    // Check the availability of CheckService
    String name = "HandlerTest-1";
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), name);
    assertNotNull("Check the check service availability", ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
    Dictionary<String, Object> p = cs.getProps();
    assertEquals("Assert 'simple' equality", p.get("Simple"), "simple");
    assertEquals("Assert 'a' equality", p.get("Map1"), "a");
    assertEquals("Assert 'b' equality", p.get("Map2"), "b");
    assertEquals("Assert 'c' equality", p.get("Map3"), "c");
    assertEquals("check foo value", FooService.VALUE, cs.getProps().get("foo"));
    // Change value.
    ServiceReference ref2 = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), name);
    assertNotNull("Check the foo service availability", ref2);
    FooService fs = (FooService) osgiHelper.getRawServiceObject(ref2);
    // This trigger the changes.
    fs.foo();
    assertEquals("check foo value", FooService.VALUE_2, cs.getProps().get("foo"));
}
Also used : FooService(org.apache.felix.ipojo.runtime.externalhandlers.services.FooService) CheckService(org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 5 with CheckService

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

the class HandlerTest method testLifecycle.

@Test
public void testLifecycle() {
    // Check the availability of CheckService
    String name = "HandlerTest-1";
    ServiceReference sr = null;
    ServiceReference[] refs = null;
    String filter = "(" + "instance.name" + "=" + name + ")";
    refs = osgiHelper.getServiceReferences(CheckService.class.getName(), filter);
    if (refs != null) {
        sr = refs[0];
    }
    assertNotNull("Check the check service availability", sr);
    ServiceReference sr_arch = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "HandlerTest-1");
    Architecture arch = (Architecture) osgiHelper.getRawServiceObject(sr_arch);
    System.out.println("===");
    Dumps.dumpArchitectures(context);
    assertEquals("Check instance validity - 0", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(sr);
    Dictionary<String, Object> p = cs.getProps();
    Integer changes = (Integer) p.get("changes");
    assertNotNull("Check changes no null", changes);
    assertEquals("Changes changes 1 (" + changes + ")", changes.intValue(), 1);
    assertEquals("Check instance validity - 1", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
    cs.check();
    p = cs.getProps();
    changes = (Integer) p.get("changes");
    assertEquals("Changes changes 2 (" + changes + ")", changes.intValue(), 2);
    assertEquals("Check instance validity - 2", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
    cs.check();
    p = cs.getProps();
    changes = (Integer) p.get("changes");
    assertEquals("Changes changes 3 (" + changes + ")", changes.intValue(), 3);
    assertEquals("Check instance validity - 3", arch.getInstanceDescription().getState(), ComponentInstance.VALID);
    cs.check();
    p = cs.getProps();
    changes = (Integer) p.get("changes");
    assertEquals("Changes changes 4 (" + changes + ")", changes.intValue(), 4);
    assertEquals("Check instance validity - 4", arch.getInstanceDescription().getState(), ComponentInstance.INVALID);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) CheckService(org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

CheckService (org.apache.felix.ipojo.runtime.externalhandlers.services.CheckService)5 Test (org.junit.Test)5 ServiceReference (org.osgi.framework.ServiceReference)5 Architecture (org.apache.felix.ipojo.architecture.Architecture)1 FooService (org.apache.felix.ipojo.runtime.externalhandlers.services.FooService)1