Search in sources :

Example 1 with PrimitiveInstanceDescription

use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.

the class TestPOJOCreation method testLazyCreationSeveralM.

/**
 * Check creation through a factory method.
 * (lazy & several creation)
 */
@Test
public void testLazyCreationSeveralM() {
    assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSevM.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sevM.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_lazzy_sevM.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) lazzyArchSevM.getInstanceDescription()).getCreatedObjects().length);
    FooService fs2 = (FooService) osgiHelper.getServiceObject(ref);
    assertTrue("Check the FooService invocation-2", fs2.foo());
    // Only one object as the getService method is called only once (service factory) despite the policy="method".
    assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArchSevM.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 2 with PrimitiveInstanceDescription

use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.

the class TestPOJOCreation method testImmediateSingletonCreation.

/**
 * Test immediate singleton creation.
 */
@Test
public void testImmediateSingletonCreation() {
    assertEquals("Check that one object is created ", 1, ((PrimitiveInstanceDescription) immeArchSing.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_immediate_singleton.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_immediate_singleton.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) immeArchSing.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 3 with PrimitiveInstanceDescription

use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.

the class TestPOJOCreation method testLazyCreation.

/**
 * Check lazy creation.
 */
@Test
public void testLazyCreation() {
    assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArch.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_lazzy.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) lazzyArch.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 4 with PrimitiveInstanceDescription

use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.

the class TestPOJOCreation method testLazyCreationSingleton.

/**
 * Check lazy and singleton creation.
 */
@Test
public void testLazyCreationSingleton() {
    assertEquals("Check that no objects are created ", 0, ((PrimitiveInstanceDescription) lazzyArchSing.getInstanceDescription()).getCreatedObjects().length);
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy_sing.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_lazzy_sing.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) lazzyArchSing.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 5 with PrimitiveInstanceDescription

use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.

the class TestPOJOCreation method testBundleContext.

/**
 * Check bundle context injection.
 */
@Test
public void testBundleContext() {
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), ci_lazzy.getInstanceName());
    assertNotNull("Check that a FooService from " + ci_lazzy.getInstanceName() + " is available", ref);
    FooService fs = (FooService) osgiHelper.getServiceObject(ref);
    Properties p = fs.fooProps();
    assertNotNull("Check the bundle context", p.get("context"));
    assertEquals("Check the creation of 1 object", 1, ((PrimitiveInstanceDescription) lazzyArch.getInstanceDescription()).getCreatedObjects().length);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Properties(java.util.Properties) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test) BaseTest(org.ow2.chameleon.testing.helpers.BaseTest)

Aggregations

PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)40 Test (org.junit.Test)36 ServiceReference (org.osgi.framework.ServiceReference)36 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)25 Architecture (org.apache.felix.ipojo.architecture.Architecture)20 Properties (java.util.Properties)18 IOException (java.io.IOException)16 Dictionary (java.util.Dictionary)16 Configuration (org.osgi.service.cm.Configuration)16 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)9 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)8 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)6 DependencyHandlerDescription (org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription)5 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)5 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)5 FooService (org.apache.felix.ipojo.runtime.core.test.services.FooService)5 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)2 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)2 ProvidedServiceDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription)2 CallbackCheckService (org.apache.felix.ipojo.runtime.core.services.CallbackCheckService)2