Search in sources :

Example 96 with ComponentInstance

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

the class TestContextInjectionFromAnnotations method testMethodInjectionOfInstanceBundleContext.

@Test
public void testMethodInjectionOfInstanceBundleContext() {
    BundleContext bc = osgiHelper.getBundle("org.apache.felix.ipojo").getBundleContext();
    Properties configuration = new Properties();
    configuration.put("instance.bundle.context", bc);
    ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.annotations.InstanceBundleContextInjectionInMethod", configuration);
    CheckService check = ipojoHelper.getServiceObjectByName(CheckService.class, instance.getInstanceName());
    assertNotNull(check);
    BundleContext context = (BundleContext) check.map().get("context");
    assertNotNull(context);
    assertEquals(bc, context);
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 97 with ComponentInstance

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

the class TestContextInjectionFromAnnotations method testMethodInjectionOfComponentBundleContext.

@Test
public void testMethodInjectionOfComponentBundleContext() {
    ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.annotations.ComponentBundleContextInjectionInMethod");
    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)

Example 98 with ComponentInstance

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

the class TestContextInjectionFromXML method testFieldInjectionOfInstanceBundleContextUsingXML.

@Test
public void testFieldInjectionOfInstanceBundleContextUsingXML() {
    BundleContext bc = osgiHelper.getBundle("org.apache.felix.ipojo").getBundleContext();
    Properties configuration = new Properties();
    configuration.put("instance.bundle.context", bc);
    ComponentInstance instance = ipojoHelper.createComponentInstance("CTX-Field-Instance", configuration);
    CheckService check = ipojoHelper.getServiceObjectByName(CheckService.class, instance.getInstanceName());
    assertNotNull(check);
    BundleContext context = (BundleContext) check.map().get("context");
    assertNotNull(context);
    assertEquals(bc, context);
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) CheckService(org.apache.felix.ipojo.runtime.core.services.CheckService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 99 with ComponentInstance

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

the class TestContextInjectionFromXML method testConstructorInjectionOfComponentBundleContextUsingXML.

@Test
public void testConstructorInjectionOfComponentBundleContextUsingXML() {
    ComponentInstance instance = ipojoHelper.createComponentInstance("CTX-Constructor-Component");
    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)

Example 100 with ComponentInstance

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

the class TestInjectingComponentAndInstanceContext method testConstructorInjectionOfThreeContext.

/**
 * Mix bundle context injection with the default bc injection (legacy).
 */
@Test
public void testConstructorInjectionOfThreeContext() {
    BundleContext bc = osgiHelper.getBundle("org.apache.felix.ipojo").getBundleContext();
    Properties configuration = new Properties();
    configuration.put("instance.bundle.context", bc);
    ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.annotations.ComponentWithThreeConstructorParams", configuration);
    CheckService check = ipojoHelper.getServiceObjectByName(CheckService.class, instance.getInstanceName());
    assertNotNull(check);
    BundleContext context = (BundleContext) check.map().get("component");
    assertNotNull(context);
    assertEquals(getTestBundle().getSymbolicName(), context.getBundle().getSymbolicName());
    context = (BundleContext) check.map().get("instance");
    assertNotNull(context);
    assertEquals(bc, context);
    context = (BundleContext) check.map().get("bc");
    assertNotNull(context);
    assertEquals(getTestBundle().getSymbolicName(), context.getBundle().getSymbolicName());
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) 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