use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestInjectingContextAndProperties method testWhenPropertyIsFirst.
@Test
public void testWhenPropertyIsFirst() {
BundleContext bc = osgiHelper.getBundle("org.apache.felix.ipojo").getBundleContext();
Properties configuration = new Properties();
configuration.put("instance.bundle.context", bc);
configuration.put("message", "hello");
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" + ".components.mix.MixWithProperties1", configuration);
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());
assertEquals("hello", check.map().get("message"));
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestImmediateCallbackSeveralFactories 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) getContext().getService(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"));
Integer count = (Integer) (cs.getProps().get("count"));
assertEquals("Check int property - 1 (" + index + ")", index.intValue(), 1);
assertEquals("Check count property - 1 (" + count + ")", count.intValue(), 1);
fooProvider.stop();
// id_dep = ((Architecture) getContext().getService(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) getContext().getService(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"));
count = (Integer) (cs.getProps().get("count"));
assertEquals("Check int property - 2 (" + index + ")", index.intValue(), 3);
assertEquals("Check count property - 2 (" + count + ")", count.intValue(), 1);
assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestParentCallback 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);
// 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);
// Check int property
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);
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);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(cs_ref);
assertTrue("check CheckService invocation", cs.check());
// Clean up
bc.ungetService(arch_ref);
bc.ungetService(cs_ref);
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestConfigurableLifeCycleController method testInValidThenValid.
@Test
public void testInValidThenValid() throws Exception {
Properties props = new Properties();
props.put("instance.name", "under1");
props.put("state", "false");
under = factory.createComponentInstance(props);
// The instance should now be invalid
assertFalse("Check service availability -2", ipojoHelper.isServiceAvailableByName(CheckService.class.getName(), "under1"));
// Reconfigure the instance
// Bar is a bad conf
props.put("state", "true");
try {
factory.reconfigure(props);
} catch (Exception e) {
fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
}
// Object[] objects = Utils.getServiceObjects(context, Architecture.class.getName(), null);
// for (int i = 0; i < objects.length; i++) {
// Architecture a = (Architecture) objects[i];
// System.out.println(a.getInstanceDescription().getDescription());
// }
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
assertNotNull("Check service availability -1", ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
assertTrue("Check state 1", cs.check());
bc.ungetService(ref);
// Reconfigure the instance
// Bar is a bad conf
props.put("state", "false");
try {
factory.reconfigure(props);
} catch (Exception e) {
fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
}
// The instance should now be invalid
assertFalse("Check service availability -2", ipojoHelper.isServiceAvailableByName(CheckService.class.getName(), "under1"));
// Reconfigure the instance with a valid configuration
props.put("state", "true");
try {
factory.reconfigure(props);
} catch (Exception e) {
fail("The reconfiguration is not unacceptable and seems unacceptable (2) : " + props);
}
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
assertNotNull("Check service availability -3", ref);
cs = (CheckService) osgiHelper.getRawServiceObject(ref);
assertTrue("Check state 2", cs.check());
bc.ungetService(ref);
under.dispose();
}
use of org.apache.felix.ipojo.runtime.core.services.CheckService in project felix by apache.
the class TestConfigurableLifeCycleController method testValidThenInvalid.
@Test
public void testValidThenInvalid() throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
Properties props = new Properties();
props.put("instance.name", "under1");
props.put("state", "true");
under = factory.createComponentInstance(props);
// The conf is correct, the PS must be provided
ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
assertNotNull("Check service availability -1", ref);
CheckService cs = (CheckService) osgiHelper.getRawServiceObject(ref);
assertTrue("Check state 1", cs.check());
bc.ungetService(ref);
// Reconfigure the instance
// Bar is a bad conf
props.put("state", "false");
try {
factory.reconfigure(props);
} catch (Exception e) {
fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);
}
// The instance should now be invalid
assertFalse("Check service availability -2", ipojoHelper.isServiceAvailableByName(CheckService.class.getName(), "under1"));
// Reconfigure the instance with a valid configuration
props.put("state", "true");
try {
factory.reconfigure(props);
} catch (Exception e) {
fail("The reconfiguration is not unacceptable and seems unacceptable (2) : " + props);
}
ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(), "under1");
assertNotNull("Check service availability -3", ref);
cs = (CheckService) osgiHelper.getRawServiceObject(ref);
assertTrue("Check state 2", cs.check());
bc.ungetService(ref);
under.dispose();
}
Aggregations