Search in sources :

Example 6 with CheckService

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

the class TestServiceController method testComponentWithTwoControllersUsingBothSpecificationsTrueTrue.

@Test
public void testComponentWithTwoControllersUsingBothSpecificationsTrueTrue() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec2");
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    osgiHelper.waitForService(FooService.class.getName(), null, 5000);
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    check.check();
    // CheckService not available
    assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
    assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
    fs.foo();
    assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    ci.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Example 7 with CheckService

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

the class TestServiceController method testComponentWithAControllerSetToFalse.

@Test
public void testComponentWithAControllerSetToFalse() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-false");
    // Controller set to false.
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    assertTrue(check.check());
    assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
    assertFalse(check.check());
    // FooService should not be there anymore
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    ci.dispose();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Example 8 with CheckService

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

the class TestServiceController method testComponentWithTwoControllersSetToTrueAndFalse.

@Test
public void testComponentWithTwoControllersSetToTrueAndFalse() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-truefalse");
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    assertFalse(osgiHelper.isServiceAvailable(FooService.class.getName()));
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    check.getProps();
    assertFalse(osgiHelper.isServiceAvailable(CheckService.class.getName()));
    assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
    fs.fooProps();
    assertTrue(osgiHelper.isServiceAvailable(CheckService.class.getName()));
    assertTrue(osgiHelper.isServiceAvailable(FooService.class.getName()));
    ci.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Example 9 with CheckService

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

the class TestServiceController method testComponentWithTwoControllersUsingSpecificationAndAllTrueTrue.

@Test
public void testComponentWithTwoControllersUsingSpecificationAndAllTrueTrue() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec3");
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    osgiHelper.waitForService(FooService.class.getName(), null, 5000);
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    check.check();
    // CheckService not available
    assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
    assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), null);
    fs.foo();
    assertNull(osgiHelper.getServiceReference(CheckService.class.getName()));
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    ci.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Example 10 with CheckService

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

the class CustomStrategy2Test method testOneService.

@Test
public void testOneService() {
    prov.start();
    cons2.stop();
    cons1.stop();
    assertEquals("Prov valid", ComponentInstance.VALID, prov.getState());
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), prov.getInstanceName());
    assertNotNull("Service available", ref);
    checkCreatedObjects(prov, 0);
    // Step 1 : create start one consumer
    cons1.start();
    ServiceReference refcons1 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons1.getInstanceName());
    assertNotNull("Cons1 Service available", refcons1);
    CheckService cs_cons1 = (CheckService) osgiHelper.getRawServiceObject(refcons1);
    Properties props = cs_cons1.getProps();
    Long id = (Long) props.get("id");
    FooService fscons1 = (FooService) props.get("object");
    assertEquals("id 1", 1, id.intValue());
    checkCreatedObjects(prov, 1);
    // Step 2 : create a second consumer
    cons2.start();
    ServiceReference refcons2 = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), cons2.getInstanceName());
    assertNotNull("Cons2 Service available", refcons2);
    CheckService cs_cons2 = (CheckService) osgiHelper.getRawServiceObject(refcons2);
    Properties props2 = cs_cons2.getProps();
    Long id2 = (Long) props2.get("id");
    FooService fscons2 = (FooService) props2.get("object");
    assertEquals("id 2", 2, id2.intValue());
    checkCreatedObjects(prov, 2);
    assertNotSame("Two objects", fscons1, fscons2);
    // Step 3 : stop the second provider
    System.out.println("cons2 stopping");
    cons2.stop();
    System.out.println("cons2 stopped");
    checkCreatedObjects(prov, 1);
    // Step 4 : stop the first consumer
    cons1.stop();
    checkCreatedObjects(prov, 0);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) 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