Search in sources :

Example 21 with PrimitiveInstanceDescription

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

the class TestCallback method testCallback.

@Test
public void testCallback() {
    // Check instance is invalid
    ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
    assertNotNull("Check architecture availability", arch_ref);
    PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
    assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
    // Start fooprovider
    fooProvider.start();
    // Check instance validity
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
    // Check service providing
    ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check int property
    Integer index = (Integer) (cs.getProps().get("int"));
    assertEquals("Check int property - 1", index.intValue(), 1);
    assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
    fooProvider.stop();
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
    fooProvider.start();
    // Check instance validity
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
    // Check service providing
    cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check int property
    index = (Integer) (cs.getProps().get("int"));
    assertEquals("Check int property - 2 (" + index.intValue() + ")", index.intValue(), 3);
    assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 22 with PrimitiveInstanceDescription

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

the class TestImmediateCallback method testCallback.

@Test
public void testCallback() {
    // Check instance is invalid
    ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
    assertNotNull("Check architecture availability", arch_ref);
    PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
    assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
    // Start fooprovider
    fooProvider.start();
    // Check instance validity
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
    // Check service providing
    ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
    // Check int property
    Integer index = (Integer) (cs.getProps().get("int"));
    assertEquals("Check int property - 1 (" + index + ")", index.intValue(), 1);
    fooProvider.stop();
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
    fooProvider.start();
    // Check instance validity
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
    // Check service providing
    cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check int property
    index = (Integer) (cs.getProps().get("int"));
    assertEquals("Check int property - 2 (" + index + ")", index.intValue(), 3);
    assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 23 with PrimitiveInstanceDescription

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

the class TestImmediateCallbackSingletonFactory method testCallback.

@Test
public void testCallback() {
    // Check instance is invalid
    ServiceReference arch_ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
    assertNotNull("Check architecture availability", arch_ref);
    PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
    assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);
    // Start fooprovider
    fooProvider.start();
    // Check instance validity
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);
    // Check service providing
    ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);
    // Check int property
    Integer index = (Integer) (cs.getProps().get("int"));
    assertEquals("Check int property - 1 (" + index + ")", index.intValue(), 1);
    fooProvider.stop();
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);
    fooProvider.start();
    // Check instance validity
    // id_dep = ((Architecture) osgiHelper.getServiceObject(arch_ref)).getInstanceDescription();
    assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);
    // Check service providing
    cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check int property
    index = (Integer) (cs.getProps().get("int"));
    assertEquals("Check int property - 2 (" + index + ")", index.intValue(), 3);
    assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
}
Also used : Architecture(org.apache.felix.ipojo.architecture.Architecture) CallbackCheckService(org.apache.felix.ipojo.runtime.core.services.CallbackCheckService) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 24 with PrimitiveInstanceDescription

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

the class TestDependencyArchitecture method testOptionalDependency.

@Test
public void testOptionalDependency() {
    ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance2.getInstanceName());
    assertNotNull("Check architecture availability", arch_dep);
    PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.VALID);
    // Check dependency handler invalidity
    DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
    assertTrue("Check dependency handler invalidity", dhd.isValid());
    // Check dependency metadata
    assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
    assertEquals("Check dependency id", dhd.getDependencies()[0].getId(), "FooService");
    assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
    assertTrue("Check dependency optionality", dhd.getDependencies()[0].isOptional());
    assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
    fooProvider1.start();
    ServiceReference arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
    assertNotNull("Check architecture availability", arch_ps);
    PrimitiveInstanceDescription id_ps = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
    dhd = getDependencyDesc(id_dep);
    assertTrue("Check dependency handler validity", dhd.isValid());
    assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
    ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check object graph
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
    assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
    fooProvider1.stop();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
    dhd = getDependencyDesc(id_dep);
    assertTrue("Check dependency handler invalidity", dhd.isValid());
    fooProvider1.start();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
    assertNotNull("Check architecture availability", arch_ps);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
    psh = getPSDesc(id_ps);
    assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
    assertTrue("Check dependency handler validity", dhd.isValid());
    assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
    cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance2.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check object graph
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    psh = getPSDesc(id_ps);
    fooProvider1.stop();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.VALID);
    dhd = getDependencyDesc(id_dep);
    assertTrue("Check dependency handler invalidity", dhd.isValid());
    id_dep = null;
    cs = null;
    getContext().ungetService(arch_dep);
    getContext().ungetService(cs_ref);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 25 with PrimitiveInstanceDescription

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

the class TestDependencyArchitecture method testSimpleDependency.

@Test
public void testSimpleDependency() {
    ServiceReference arch_dep = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance1.getInstanceName());
    assertNotNull("Check architecture availability", arch_dep);
    PrimitiveInstanceDescription id_dep = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);
    // Check dependency handler invalidity
    DependencyHandlerDescription dhd = getDependencyDesc(id_dep);
    assertFalse("Check dependency handler invalidity", dhd.isValid());
    // Check dependency metadata
    assertEquals("Check dependency interface", dhd.getDependencies()[0].getInterface(), FooService.class.getName());
    assertEquals("Check dependency id", dhd.getDependencies()[0].getId(), FooService.class.getName());
    assertFalse("Check dependency cardinality", dhd.getDependencies()[0].isMultiple());
    assertFalse("Check dependency optionality", dhd.getDependencies()[0].isOptional());
    assertNull("Check dependency ref -1", dhd.getDependencies()[0].getServiceReferences());
    assertFalse("Check dependency proxy", dhd.getDependencies()[0].isProxy());
    fooProvider1.start();
    ServiceReference arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
    assertNotNull("Check architecture availability", arch_ps);
    PrimitiveInstanceDescription id_ps = (PrimitiveInstanceDescription) ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
    dhd = getDependencyDesc(id_dep);
    assertTrue("Check dependency handler validity", dhd.isValid());
    assertEquals("Check dependency ref - 2 ", dhd.getDependencies()[0].getServiceReferences().size(), 1);
    ServiceReference cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check object graph
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    ProvidedServiceHandlerDescription psh = getPSDesc(id_ps);
    assertEquals("Check POJO creation", id_ps.getCreatedObjects().length, 1);
    fooProvider1.stop();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    dhd = getDependencyDesc(id_dep);
    assertFalse("Check dependency handler invalidity", dhd.isValid());
    fooProvider1.start();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    arch_ps = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), fooProvider1.getInstanceName());
    assertNotNull("Check architecture availability", arch_ps);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    assertTrue("Check instance invalidity - 1", id_ps.getState() == ComponentInstance.VALID);
    psh = getPSDesc(id_ps);
    assertTrue("Check instance validity", id_dep.getState() == ComponentInstance.VALID);
    assertTrue("Check dependency handler validity", dhd.isValid());
    assertEquals("Check dependency ref -3", dhd.getDependencies()[0].getServiceReferences().size(), 1);
    cs_ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance1.getInstanceName());
    assertNotNull("Check CheckService availability", cs_ref);
    cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
    assertTrue("check CheckService invocation", cs.check());
    // Check object graph
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    dhd = getDependencyDesc(id_dep);
    // id_ps = ((Architecture) osgiHelper.getRawServiceObject(arch_ps)).getInstanceDescription();
    psh = getPSDesc(id_ps);
    fooProvider1.stop();
    // id_dep = ((Architecture) osgiHelper.getRawServiceObject(arch_dep)).getInstanceDescription();
    assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);
    dhd = getDependencyDesc(id_dep);
    assertFalse("Check dependency handler invalidity", dhd.isValid());
    id_dep = null;
    cs = null;
    getContext().ungetService(arch_dep);
    getContext().ungetService(cs_ref);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.test.services.FooService) DependencyHandlerDescription(org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription) Architecture(org.apache.felix.ipojo.architecture.Architecture) CheckService(org.apache.felix.ipojo.runtime.core.test.services.CheckService) ProvidedServiceHandlerDescription(org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

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