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);
}
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());
}
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);
}
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());
}
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());
}
Aggregations