Search in sources :

Example 1 with CheckService

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

the class TestSeveralConstructor method testNoEmptyConstructor.

@Test
public void testNoEmptyConstructor() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), ci2.getInstanceName());
    CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
    assertFalse("Check assignation", cs.check());
    String name = (String) cs.getProps().get("name");
    assertEquals("Check message", "NULL", 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)

Example 2 with CheckService

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

the class TestCallbacks method testWithPostUnregistrationOnly.

@Test
public void testWithPostUnregistrationOnly() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-unreg-only");
    // Controller set to true.
    osgiHelper.waitForService(FooService.class.getName(), null, 5000);
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    Integer reg = (Integer) check.getProps().get("registered");
    Integer unreg = (Integer) check.getProps().get("unregistered");
    assertNotNull(reg);
    assertNotNull(unreg);
    assertEquals(new Integer(0), reg);
    assertEquals(new Integer(0), unreg);
    ci.stop();
    reg = (Integer) check.getProps().get("registered");
    unreg = (Integer) check.getProps().get("unregistered");
    assertNotNull(reg);
    assertNotNull(unreg);
    assertEquals(new Integer(0), reg);
    assertEquals(new Integer(1), unreg);
}
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 3 with CheckService

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

the class TestCallbacks method testWithTwoPairsOfCallbacks.

@Test
public void testWithTwoPairsOfCallbacks() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-both-2");
    // Controller set to true.
    osgiHelper.waitForService(FooService.class.getName(), null, 5000);
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    Integer reg = (Integer) check.getProps().get("registered");
    Integer unreg = (Integer) check.getProps().get("unregistered");
    Integer reg2 = (Integer) check.getProps().get("registered2");
    Integer unreg2 = (Integer) check.getProps().get("unregistered2");
    assertNotNull(reg);
    assertNotNull(unreg);
    assertNotNull(reg2);
    assertNotNull(unreg2);
    assertEquals(new Integer(1), reg);
    assertEquals(new Integer(0), unreg);
    assertEquals(new Integer(1), reg2);
    assertEquals(new Integer(0), unreg2);
    ci.stop();
    reg = (Integer) check.getProps().get("registered");
    unreg = (Integer) check.getProps().get("unregistered");
    reg2 = (Integer) check.getProps().get("registered2");
    unreg2 = (Integer) check.getProps().get("unregistered2");
    assertNotNull(reg2);
    assertNotNull(unreg2);
    assertEquals(new Integer(1), reg);
    assertEquals(new Integer(1), unreg);
    assertEquals(new Integer(1), reg2);
    assertEquals(new Integer(1), unreg2);
}
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 4 with CheckService

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

the class TestCallbacks method testWithOnePairForTwoService.

@Test
public void testWithOnePairForTwoService() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Callbacks-both-1");
    // Controller set to true.
    osgiHelper.waitForService(FooService.class.getName(), null, 5000);
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    Integer reg = (Integer) check.getProps().get("registered");
    Integer unreg = (Integer) check.getProps().get("unregistered");
    assertNotNull(reg);
    assertNotNull(unreg);
    assertEquals(new Integer(2), reg);
    assertEquals(new Integer(0), unreg);
    ci.stop();
    reg = (Integer) check.getProps().get("registered");
    unreg = (Integer) check.getProps().get("unregistered");
    assertEquals(new Integer(2), reg);
    assertEquals(new Integer(2), unreg);
}
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 5 with CheckService

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

the class TestServiceController method testComponentWithTwoControllersUsingBothSpecificationsTrueFalse.

@Test
public void testComponentWithTwoControllersUsingBothSpecificationsTrueFalse() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-2-spec1");
    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)

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