Search in sources :

Example 91 with ComponentInstance

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

the class TestServiceController method testComponentWithAControllerSetToFalse.

@Test
public void testComponentWithAControllerSetToFalse() {
    ComponentInstance ci = ipojoHelper.createComponentInstance("PS-Controller-1-false");
    // Controller set to false.
    osgiHelper.waitForService(CheckService.class.getName(), null, 5000);
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    CheckService check = (CheckService) osgiHelper.getServiceObject(CheckService.class.getName(), null);
    assertNotNull(check);
    assertTrue(check.check());
    assertNotNull(osgiHelper.getServiceReference(FooService.class.getName()));
    assertFalse(check.check());
    // FooService should not be there anymore
    assertNull(osgiHelper.getServiceReference(FooService.class.getName()));
    ci.dispose();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) Test(org.junit.Test)

Example 92 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance 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 93 with ComponentInstance

use of org.apache.felix.ipojo.ComponentInstance 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)

Example 94 with ComponentInstance

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

the class TestSimplePS method testWhenNoInterface.

@Test
public void testWhenNoInterface() {
    String factoryName = "org.apache.felix.ipojo.runtime.core.components.SimpleClass";
    ComponentInstance ci = ipojoHelper.createComponentInstance(factoryName);
    osgiHelper.waitForService(SimpleClass.class.getName(), null, 5000);
    SimpleClass simple = (SimpleClass) osgiHelper.getServiceObject(SimpleClass.class.getName(), null);
    assertEquals("Hello", simple.hello());
    ci.dispose();
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) SimpleClass(org.apache.felix.ipojo.runtime.core.components.SimpleClass) Test(org.junit.Test)

Example 95 with ComponentInstance

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

the class TestContextInjectionFromAnnotations method testFieldInjectionOfComponentBundleContext.

@Test
public void testFieldInjectionOfComponentBundleContext() {
    ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.annotations.ComponentBundleContextInjectionInField");
    CheckService check = ipojoHelper.getServiceObjectByName(CheckService.class, instance.getInstanceName());
    assertNotNull(check);
    BundleContext context = (BundleContext) check.map().get("context");
    assertNotNull(context);
    assertEquals(getTestBundle().getSymbolicName(), context.getBundle().getSymbolicName());
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

ComponentInstance (org.apache.felix.ipojo.ComponentInstance)373 Test (org.junit.Test)360 ServiceReference (org.osgi.framework.ServiceReference)215 Properties (java.util.Properties)142 CheckService (org.apache.felix.ipojo.handler.temporal.services.CheckService)70 FooService (org.apache.felix.ipojo.handler.temporal.services.FooService)70 CheckService (org.apache.felix.ipojo.handler.transaction.services.CheckService)65 Factory (org.apache.felix.ipojo.Factory)53 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)50 ServiceContext (org.apache.felix.ipojo.ServiceContext)47 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)39 IOException (java.io.IOException)29 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)22 BundleContext (org.osgi.framework.BundleContext)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 Dictionary (java.util.Dictionary)12 Hashtable (java.util.Hashtable)12 BarService (org.apache.felix.ipojo.runtime.core.services.BarService)10 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)9