use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestPropertyModifier method testPropertyModifier.
@Test
public void testPropertyModifier() {
ComponentInstance ci = null;
Factory factory = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.PropertyModifier");
Properties props = new Properties();
props.put("cls", new String[] { FooService.class.getName() });
try {
ci = factory.createComponentInstance(props);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), ci.getInstanceName());
assertNotNull("Check ref", ref);
// Check the service property
// Not exposed here:
assertNull("Classes -0", ref.getProperty("classes"));
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
assertTrue(check.check());
// Property exposed now.
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), ci.getInstanceName());
Class[] str = (Class[]) ref.getProperty("classes");
assertEquals("Classes size", 1, str.length);
assertEquals("Classes[0]", FooService.class.getName(), str[0].getName());
Properties p = check.getProps();
Class[] str2 = (Class[]) p.get("classes");
assertEquals("Classes size -2", 1, str2.length);
assertEquals("Classes[0] -2", FooService.class.getName(), str2[0].getName());
Properties props2 = new Properties();
props2.put("cls", new String[] { FooService.class.getName(), CheckService.class.getName() });
try {
ci.reconfigure(props2);
} catch (Exception e) {
fail(e.getMessage());
}
// Check the service property
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), ci.getInstanceName());
assertNotNull("Check ref", ref);
str = (Class[]) ref.getProperty("classes");
assertEquals("Classes size -3", 2, str.length);
assertEquals("Classes[0] -3", FooService.class.getName(), str[0].getName());
assertEquals("Classes[1] -3", CheckService.class.getName(), str[1].getName());
check = (CheckService) osgiHelper.getRawServiceObject(ref);
p = check.getProps();
str2 = (Class[]) p.get("classes");
assertEquals("Classes size -4", 2, str2.length);
assertEquals("Classes[0] -4", FooService.class.getName(), str2[0].getName());
assertEquals("Classes[1] -4", CheckService.class.getName(), str2[1].getName());
ci.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestSuperMethodProperties method testConfigurationObj.
@Test
public void testConfigurationObj() {
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Test check service availability", ref);
CheckService check = (CheckService) osgiHelper.getRawServiceObject(ref);
Properties props = check.getProps();
String s = (String) props.get("string");
String[] ss = (String[]) props.get("strings");
assertEquals("Check string", s, "foo");
assertEquals("Check strings 0", ss[0], "foo");
assertEquals("Check strings 1", ss[1], "bar");
assertEquals("Check strings 2", ss[2], "baz");
// Integer upString = (Integer) props.get("upstring");
// Integer upStrings = (Integer) props.get("upstrings");
//
// assertEquals("Check upString", upString, new Integer(1));
// assertEquals("Check upStrings", upStrings, new Integer(1));
reconfigure();
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), instance.getInstanceName());
assertNotNull("Test check service availability", ref);
check = (CheckService) osgiHelper.getRawServiceObject(ref);
props = check.getProps();
s = (String) props.get("string");
ss = (String[]) props.get("strings");
assertEquals("2) Check string", s, "bar");
assertEquals("2) Check strings 0", ss[0], "baz");
assertEquals("2) Check strings 1", ss[1], "bar");
assertEquals("2) Check strings 2", ss[2], "foo");
// upString = (Integer) props.get("upstring");
// upStrings = (Integer) props.get("upstrings");
//
// assertEquals("2) Check upString", upString, new Integer(2));
// assertEquals("2) Check upStrings", upStrings, new Integer(2));
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestContextInjectionFromAnnotations method testInstanceCreatedFromConfiguration.
@Test
public void testInstanceCreatedFromConfiguration() {
CheckService check = ipojoHelper.getServiceObjectByName(CheckService.class, "from.configuration");
assertNotNull(check);
BundleContext context = (BundleContext) check.map().get("context");
assertNotNull(context);
assertNotSame(bc, context);
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestContextInjectionFromAnnotations method testConstructorInjectionOfComponentBundleContext.
@Test
public void testConstructorInjectionOfComponentBundleContext() {
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.annotations.ComponentBundleContextInjectionInConstructor");
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.runtime.core.services.CheckService in project felix by apache.
the class TestContextInjectionFromAnnotations method testFieldInjectionOfInstanceBundleContext.
@Test
public void testFieldInjectionOfInstanceBundleContext() {
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.InstanceBundleContextInjectionInField", configuration);
CheckService check = ipojoHelper.getServiceObjectByName(CheckService.class, instance.getInstanceName());
assertNotNull(check);
BundleContext context = (BundleContext) check.map().get("context");
assertNotNull(context);
assertEquals(bc, context);
}
Aggregations