Search in sources :

Example 66 with FooService

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

the class TestPOJOCreation method testImmediateCreation.

/**
 * Check immediate creation.
 */
@Test
public void testImmediateCreation() {
    assertEquals("Check that one object is created ", 1, ((PrimitiveInstanceDescription) immeArch.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_immediate.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_immediate.getInstanceName() + " is available", ref);
    FooService fs = (FooService) osgiHelper.getServiceObject(ref);
    assertTrue("Check the FooService invocation", fs.foo());
    assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) immeArch.getInstanceDescription()).getCreatedObjects().length);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 67 with FooService

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

the class TestPOJOCreation method testLazyCreationSingletonM.

/**
 * Check creation through a factory method.
 * (lazy & singleton creation)
 */
@Test
public void testLazyCreationSingletonM() {
    assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSingM.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_singM.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_lazzy_singM.getInstanceName() + " is available", ref);
    FooService fs = (FooService) osgiHelper.getServiceObject(ref);
    FooService fs2 = (FooService) osgiHelper.getServiceObject(ref);
    assertTrue("Check the FooService invocation", fs.foo());
    assertTrue("Check the FooService invocation", fs2.foo());
    assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSingM.getInstanceDescription()).getCreatedObjects().length);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 68 with FooService

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

the class TestPOJOCreation method testLazyCreationSeveral.

/**
 * Check lazy and "several" creation.
 */
@Test
public void testLazyCreationSeveral() {
    assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSev.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sev.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_lazzy_sev.getInstanceName() + " is available", ref);
    FooService fs = (FooService) osgiHelper.getServiceObject(ref);
    FooService fs2 = (FooService) osgiHelper.getServiceObject(ref);
    assertTrue("Check the FooService invocation", fs.foo());
    assertTrue("Check the FooService invocation-2", fs2.foo());
    assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSev.getInstanceDescription()).getCreatedObjects().length);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Example 69 with FooService

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

the class TestManagedServiceConfigurableProperties method testDynamicInstance2.

@Test
public void testDynamicInstance2() {
    ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
    assertNotNull("Check FS availability", fooRef);
    String fooP = (String) fooRef.getProperty("foo");
    Integer barP = (Integer) fooRef.getProperty("bar");
    String bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality", fooP, "foo");
    assertEquals("Check bar equality", barP, new Integer(2));
    assertEquals("Check baz equality", bazP, "baz");
    ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance");
    assertNotNull("Check ManagedServiceFactory availability", msRef);
    // Configuration of baz
    Dictionary<String, Object> conf = new Hashtable<String, Object>();
    conf.put("baz", "zab");
    conf.put("foo", "oof");
    conf.put("bar", new Integer(0));
    ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
    try {
        ms.updated(conf);
    } catch (ConfigurationException e) {
        fail("Configuration Exception : " + e);
    }
    // Recheck props
    fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
    fooP = (String) fooRef.getProperty("foo");
    barP = (Integer) fooRef.getProperty("bar");
    bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality", fooP, "oof");
    assertEquals("Check bar equality", barP, new Integer(0));
    assertEquals("Check baz equality", bazP, "zab");
    // Check field value
    FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
    Properties p = fs.fooProps();
    fooP = (String) p.get("foo");
    barP = (Integer) p.get("bar");
    assertEquals("Check foo field equality", fooP, "oof");
    assertEquals("Check bar field equality", barP, new Integer(0));
    osgiHelper.getContext().ungetService(fooRef);
    osgiHelper.getContext().ungetService(msRef);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ManagedService(org.osgi.service.cm.ManagedService) ConfigurationException(org.osgi.service.cm.ConfigurationException) Hashtable(java.util.Hashtable) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 70 with FooService

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

the class TestManagedServiceConfigurableProperties method testDynamicStringInstance1.

@Test
public void testDynamicStringInstance1() {
    assertEquals("Check instance1 state", ComponentInstance.VALID, instance1.getState());
    ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());
    assertNotNull("Check FS availability", fooRef);
    String fooP = (String) fooRef.getProperty("foo");
    Integer barP = (Integer) fooRef.getProperty("bar");
    String bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality - 1", fooP, "foo");
    assertEquals("Check bar equality - 1", barP, new Integer(2));
    assertEquals("Check baz equality - 1", bazP, "baz");
    ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "FooProvider-3");
    assertNotNull("Check ManagedService availability", msRef);
    // Configuration of baz
    Dictionary<String, Object> conf = new Hashtable<String, Object>();
    conf.put("baz", "zab");
    conf.put("foo", "oof");
    conf.put("bar", "0");
    assertEquals("Check instance1 state (2)", ComponentInstance.VALID, instance1.getState());
    ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
    PrimitiveHandler ph = (PrimitiveHandler) ms;
    assertSame("Check the correct instance", ph.getInstanceManager(), instance1);
    try {
        ms.updated(conf);
    } catch (ConfigurationException e) {
        fail("Configuration Exception : " + e);
    }
    assertEquals("Check instance1 state (3)", ComponentInstance.VALID, instance1.getState());
    // Recheck props
    fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());
    fooP = (String) fooRef.getProperty("foo");
    barP = (Integer) fooRef.getProperty("bar");
    bazP = (String) fooRef.getProperty("baz");
    assertEquals("Check foo equality - 2", fooP, "oof");
    assertEquals("Check bar equality - 2", barP, new Integer(0));
    assertEquals("Check baz equality - 2", bazP, "zab");
    // Check field value
    FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
    Properties p = fs.fooProps();
    fooP = (String) p.get("foo");
    barP = (Integer) p.get("bar");
    assertEquals("Check foo field equality", fooP, "oof");
    assertEquals("Check bar field equality", barP, new Integer(0));
    osgiHelper.getContext().ungetService(fooRef);
    osgiHelper.getContext().ungetService(msRef);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) ManagedService(org.osgi.service.cm.ManagedService) ConfigurationException(org.osgi.service.cm.ConfigurationException) Hashtable(java.util.Hashtable) PrimitiveHandler(org.apache.felix.ipojo.PrimitiveHandler) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) 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