Search in sources :

Example 16 with FooService

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

the class TestPropertiesInAnonymousClass method testRunnable.

@Test
public void testRunnable() {
    ServiceReference sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProviderAno-1");
    assertNotNull("Check the availability of the FS service", sr);
    // Check service properties
    Integer intProp = (Integer) sr.getProperty("int");
    Boolean boolProp = (Boolean) sr.getProperty("boolean");
    String strProp = (String) sr.getProperty("string");
    String[] strAProp = (String[]) sr.getProperty("strAProp");
    int[] intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality (1)", intProp, new Integer(2));
    assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
    assertEquals("Check strProp equality (1)", strProp, new String("foo"));
    assertNotNull("Check strAProp not nullity (1)", strAProp);
    String[] v = new String[] { "foo", "bar" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality (1)");
        }
    }
    assertNotNull("Check intAProp not nullity", intAProp);
    int[] v2 = new int[] { 1, 2, 3 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality (1)");
        }
    }
    // Invoke
    FooService fs = (FooService) osgiHelper.getRawServiceObject(sr);
    assertTrue("invoke fs", fs.foo());
    sr = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), "FooProviderAno-1");
    // Re-check the property (change)
    intProp = (Integer) sr.getProperty("int");
    boolProp = (Boolean) sr.getProperty("boolean");
    strProp = (String) sr.getProperty("string");
    strAProp = (String[]) sr.getProperty("strAProp");
    intAProp = (int[]) sr.getProperty("intAProp");
    assertEquals("Check intProp equality (2)", intProp, new Integer(3));
    assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
    assertEquals("Check strProp equality (2)", strProp, new String("bar"));
    assertNotNull("Check strAProp not nullity (2)", strAProp);
    v = new String[] { "foo", "bar", "baz" };
    for (int i = 0; i < strAProp.length; i++) {
        if (!strAProp[i].equals(v[i])) {
            fail("Check the strAProp Equality (2)");
        }
    }
    assertNotNull("Check intAProp not nullity (2)", intAProp);
    v2 = new int[] { 3, 2, 1 };
    for (int i = 0; i < intAProp.length; i++) {
        if (intAProp[i] != v2[i]) {
            fail("Check the intAProp Equality (2)");
        }
    }
    fs = null;
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 17 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService 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)

Example 18 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService 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 19 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService 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 20 with FooService

use of org.apache.felix.ipojo.runtime.core.services.FooService 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)

Aggregations

FooService (org.apache.felix.ipojo.runtime.core.services.FooService)123 Test (org.junit.Test)121 ServiceReference (org.osgi.framework.ServiceReference)110 Properties (java.util.Properties)68 Configuration (org.osgi.service.cm.Configuration)33 Hashtable (java.util.Hashtable)30 Dictionary (java.util.Dictionary)28 PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)25 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)24 ServiceContext (org.apache.felix.ipojo.ServiceContext)21 IOException (java.io.IOException)19 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)17 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)15 ConfigurationException (org.osgi.service.cm.ConfigurationException)13 ManagedService (org.osgi.service.cm.ManagedService)13 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)13 Architecture (org.apache.felix.ipojo.architecture.Architecture)11 Factory (org.apache.felix.ipojo.Factory)8 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)5 FooProviderType1 (org.apache.felix.ipojo.runtime.core.components.FooProviderType1)3