Search in sources :

Example 61 with CheckService

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

the class TestCompositeAPI method testAPI.

@Test
public void testAPI() {
    Factory fact1 = ipojoHelper.getFactory("composite.empty");
    Properties p = new Properties();
    p.put("instance.name", "empty-1");
    ComponentInstance empty = null;
    try {
        empty = fact1.createComponentInstance(p);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    ServiceContext sc = getServiceContext(empty);
    Factory fact2 = ipojoHelper.getFactory("composite.test.2");
    Properties props2 = new Properties();
    // 2
    props2.put("instance.name", "2");
    Factory fact3 = ipojoHelper.getFactory("composite.test.3");
    Properties props3 = new Properties();
    props3.put("instance.name", "3");
    ComponentInstance comp2 = null;
    ComponentInstance comp3 = null;
    try {
        comp2 = fact2.createComponentInstance(props2, sc);
        comp3 = fact3.createComponentInstance(props3, sc);
    } catch (Throwable e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
    assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
    ServiceReference ref = null;
    // 2
    ref = ipojoHelper.getServiceReferenceByName(sc, CheckService.class.getName(), "2");
    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)

Example 62 with CheckService

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

the class TestGenericList method testTypedList.

@Test
public void testTypedList() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), checker.getInstanceName());
    CheckService check = (CheckService) osgiHelper.getServiceObject(ref);
    assertNotNull("Checker availability", check);
    // Check without providers
    assertFalse("Empty list", check.check());
    // Start the first provider
    foo1.start();
    assertTrue("List with one element", check.check());
    Properties props = check.getProps();
    List<FooService> list = (List<FooService>) props.get("list");
    assertEquals("Check size - 1", 1, list.size());
    // Start the second provider
    foo2.start();
    assertTrue("List with two element", check.check());
    props = check.getProps();
    list = (List<FooService>) props.get("list");
    assertEquals("Check size - 2", 2, list.size());
    // Stop the first one
    foo1.stop();
    assertTrue("List with one element (2)", check.check());
    props = check.getProps();
    list = (List<FooService>) props.get("list");
    assertEquals("Check size - 3", 1, list.size());
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) List(java.util.List) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 63 with CheckService

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

the class TestNestedClasses method setUp.

@Before
public void setUp() {
    Properties map = new Properties();
    map.put("publicObject", "publicObject");
    map.put("publicInt", new Integer(0));
    map.put("packageObject", "packageObject");
    map.put("packageInt", new Integer(1));
    map.put("protectedObject", "protectedObject");
    map.put("protectedInt", new Integer(2));
    map.put("privateObject", "privateObject");
    map.put("privateInt", new Integer(3));
    map.put("nonObject", "nonObject");
    map.put("nonInt", new Integer(4));
    instance = ipojoHelper.createComponentInstance("inners", map);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check service availability", ref);
    service = (CheckService) osgiHelper.getServiceObject(ref);
}
Also used : Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Before(org.junit.Before)

Example 64 with CheckService

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

the class TestInstanceScope method testScope.

@Test
public void testScope() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
    assertNotNull("Check architecture availability", ref);
    Architecture arch = (Architecture) getContext().getService(ref);
    assertTrue("Validity", arch.getInstanceDescription().getState() == ComponentInstance.VALID);
    // Get internal service
    ServiceContext sc = getServiceContext(instance);
    ServiceReference ref2 = ipojoHelper.getServiceReference(sc, CheckService.class.getName(), null);
    assertNotNull("Check CheckService availability", ref2);
    CheckService svc = (CheckService) sc.getService(ref2);
    Properties props = svc.getProps();
    assertEquals("Check props - 1", 1, ((Integer) props.get("1")).intValue());
    assertEquals("Check props - 2", 2, ((Integer) props.get("2")).intValue());
    assertEquals("Check props - 3", 3, ((Integer) props.get("3")).intValue());
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) ServiceContext(org.apache.felix.ipojo.ServiceContext) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 65 with CheckService

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

the class FactoryManagementTest method testInvocation.

@Test
public void testInvocation() {
    ServiceContext sc1 = getServiceContext(empty);
    Factory fact = ipojoHelper.getFactory(sc1, "composite.empty");
    Properties p = new Properties();
    p.put("instance.name", "empty2");
    ComponentInstance empty2 = null;
    try {
        empty2 = fact.createComponentInstance(p);
    } catch (Exception e) {
        fail("Cannot instantiate empty2 instance : " + e.getMessage());
    }
    ServiceContext sc2 = getServiceContext(empty2);
    Factory fact1 = ipojoHelper.getFactory(sc2, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name", "client");
    ComponentInstance client = null;
    try {
        client = fact1.createComponentInstance(props);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Cannot instantiate the client : " + e.getMessage());
    }
    Factory fact2 = ipojoHelper.getFactory(sc2, "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name", "provider");
    ComponentInstance provider = null;
    try {
        provider = fact2.createComponentInstance(props2);
    } catch (Exception e) {
        fail("Cannot instantiate the provider : " + e.getMessage());
    }
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    assertNotNull("Check ref existency", ref);
    CheckService check = (CheckService) sc2.getService(ref);
    assertTrue("Check invocation", check.check());
    client.dispose();
    provider.dispose();
    empty2.dispose();
}
Also used : Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) 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