Search in sources :

Example 66 with CheckService

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

the class ServiceRangeTest method testLevelOne2.

@Test
public void testLevelOne2() {
    ServiceContext sc2 = getServiceContext(empty);
    Factory fact1 = ipojoHelper.getFactory(sc2, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name", "client");
    ComponentInstance client = null;
    try {
        client = fact1.createComponentInstance(props, sc2);
    } catch (Exception e) {
        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, sc2);
    } catch (Exception e) {
        fail("Cannot instantiate the provider : " + e.getMessage());
    }
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
    assertTrue("Check invocation", check.check());
    sc2.ungetService(ref);
    // Check visibility
    assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
    client.dispose();
    provider.dispose();
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
}
Also used : ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) 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 67 with CheckService

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

the class ServiceRangeTest method testLevelTwo1.

@Test
public void testLevelTwo1() {
    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) {
        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());
    CheckService check = (CheckService) sc2.getService(ref);
    assertTrue("Check invocation", check.check());
    sc2.ungetService(ref);
    // Check visibility
    assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
    client.dispose();
    provider.dispose();
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
    empty2.dispose();
}
Also used : ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) 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 68 with CheckService

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

the class ServiceRangeTest method testLevelTwo2.

@Test
public void testLevelTwo2() {
    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(sc1, "COMPO-SimpleCheckServiceProvider");
    Properties props = new Properties();
    props.put("instance.name", "client");
    ComponentInstance client = null;
    try {
        client = fact1.createComponentInstance(props, sc2);
    } catch (Exception e) {
        fail("Cannot instantiate the client : " + e.getMessage());
    }
    Factory fact2 = ipojoHelper.getFactory(sc1, "COMPO-FooProviderType-1");
    Properties props2 = new Properties();
    props2.put("instance.name", "provider");
    ComponentInstance provider = null;
    try {
        provider = fact2.createComponentInstance(props2, sc2);
    } catch (Exception e) {
        fail("Cannot instantiate the provider : " + e.getMessage());
    }
    ServiceReference ref = sc2.getServiceReference(CheckService.class.getName());
    CheckService check = (CheckService) sc2.getService(ref);
    assertTrue("Check invocation", check.check());
    sc2.ungetService(ref);
    // Check visibility
    assertNotNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
    client.dispose();
    provider.dispose();
    assertNull("Check foo service visible inside the composite 2", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service visible inside the composite 2", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the composite 1", sc1.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite 1", sc1.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible inside the global", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
    empty2.dispose();
}
Also used : ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) 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 69 with CheckService

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

the class ServiceRangeTest method testLevelOne1.

@Test
public void testLevelOne1() {
    ServiceContext sc2 = getServiceContext(empty);
    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) {
        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());
    CheckService check = (CheckService) sc2.getService(ref);
    assertTrue("Check invocation", check.check());
    sc2.ungetService(ref);
    // Check visibility
    assertNotNull("Check foo service visible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNotNull("Check check service visible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    // Check invisibilty
    assertNull("Check foo service invisible inside the context", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
    provider.dispose();
    client.dispose();
    assertNull("Check foo service invisible inside the composite", sc2.getServiceReference(FooService.class.getName()));
    assertNull("Check check service invisible inside the composite", sc2.getServiceReference(CheckService.class.getName()));
    assertNull("Check foo service invisible from the context", getContext().getServiceReference(FooService.class.getName()));
    try {
        assertNull("Check check service invisible inside the context", getContext().getServiceReferences(CheckService.class.getName(), "(instance.name=client)"));
    } catch (InvalidSyntaxException e) {
        fail("Invalid filter : " + e);
    }
}
Also used : ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) 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 70 with CheckService

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

the class TestSeveralConstructor method testNoEmptyConstructorWithAParentClass.

@Test
public void testNoEmptyConstructorWithAParentClass() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), ci3.getInstanceName());
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
    // super set name to "hello"
    assertTrue("Check assignation", cs.check());
    String name = (String) cs.getProps().get("name");
    assertEquals("Check message", "hello", name);
}
Also used : CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

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