use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceTestForImmediate method testCreationAndReconfiguration2.
@Test
public void testCreationAndReconfiguration2() {
// The configuration exists before the instance creation.
// Update
Configuration configuration = null;
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message2");
configuration.update(prc);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
Properties props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
ComponentInstance instance = null;
try {
instance = factImm.createComponentInstance(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
FooService fs = (FooService) bc.getService(ref);
Properties p = fs.fooProps();
String mes = p.getProperty("message");
// int count1 = ((Integer) p.get("count")).intValue();
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
// Already reconfigured.
assertEquals("Check message - 1 (" + mes + ")", "message2", mes);
// assertEquals("Check count", 2, count); // Two : 1) "message" on immediate, "message2" on the reconfiguration,
// not necessary as the property can be set before the immediate instance creation
instance.dispose();
// Reconfiguration
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message3");
configuration.update(prc);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// Recreation of the instance.
props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
instance = null;
try {
instance = factImm.createComponentInstance(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
// int count = ((Integer) p.get("count")).intValue();
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
// Already reconfigured.
assertEquals("Check message already reconfigured", "message3", mes);
// assertEquals("Check count", count1 + 1, count); // message before the reconfiguration, message3 after the reconfiguration
instance.dispose();
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceTestForService method testCreationUsingMSFAndReconfigurationUsingManagedService.
@Test
public void testCreationUsingMSFAndReconfigurationUsingManagedService() {
Configuration conf = null;
try {
conf = admin.createFactoryConfiguration(factNameSvc, getTestBundle().getLocation());
Dictionary props = conf.getProperties();
if (props == null) {
props = new Properties();
}
props.put("managed.service.pid", msp);
props.put("message", "message");
conf.update(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
Architecture arch = (Architecture) osgiHelper.getServiceObject(org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
// arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
FooService fs = (FooService) bc.getService(ref);
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
assertEquals("Check message", "message", mes);
assertEquals("Check count", 1, count);
// Update
Configuration configuration;
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message2");
configuration.update(prc);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
// arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
if (mes.equals("message")) {
System.out.println("Warning, configuration not yet applied");
assertEquals("Check count - W", 1, count);
} else {
assertEquals("Check message", "message2", mes);
assertEquals("Check count", 2, count);
}
try {
conf.delete();
} catch (IOException e) {
fail(e.getMessage());
}
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceTestForService method testCreationUsingFactoryAndReconfigurationUsingManagedService.
@Test
public void testCreationUsingFactoryAndReconfigurationUsingManagedService() {
Properties props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
ComponentInstance instance = null;
try {
instance = factSvc.createComponentInstance(props);
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
FooService fs = (FooService) bc.getService(ref);
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertEquals("Check message", "message", mes);
assertEquals("Check count", 1, count);
// Update
Configuration configuration;
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message2");
configuration.update(prc);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
if (mes.equals("message")) {
System.out.println("Warning, configuration not yet applied");
assertEquals("Check count - W", 1, count);
} else {
assertEquals("Check message", "message2", mes);
assertEquals("Check count", 2, count);
}
instance.dispose();
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestManagedServiceTestForService method testConfigurationPushedBeforeInstantiationUsingFactory.
@Test
public void testConfigurationPushedBeforeInstantiationUsingFactory() {
// The configuration exists before the instance creation.
// Update
Configuration configuration;
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message2");
configuration.update(prc);
// listener.waitForEvent(msp, "1");
grace();
} catch (Exception e) {
fail(e.getMessage());
}
Properties props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
ComponentInstance instance = null;
try {
instance = factSvc.createComponentInstance(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
FooService fs = (FooService) bc.getService(ref);
Properties p = fs.fooProps();
String mes = p.getProperty("message");
int count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
// Already reconfigured.
assertEquals("Check message", "message2", mes);
assertEquals("Check count", 1, count);
instance.dispose();
// Reconfiguration
try {
configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
Dictionary prc = configuration.getProperties();
if (prc == null) {
prc = new Properties();
}
prc.put("message", "message3");
configuration.update(prc);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
// Recreation of the instance.
props = new Properties();
props.put("managed.service.pid", msp);
props.put("message", "message");
instance = null;
try {
instance = factSvc.createComponentInstance(props);
grace();
} catch (Exception e) {
fail(e.getMessage());
}
ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
assertNotNull("FS availability", ref);
fs = (FooService) bc.getService(ref);
p = fs.fooProps();
mes = p.getProperty("message");
count = (Integer) p.get("count");
assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
// Already reconfigured.
assertEquals("Check message", "message3", mes);
assertEquals("Check count", 1, count);
instance.dispose();
}
use of org.apache.felix.ipojo.PrimitiveInstanceDescription in project felix by apache.
the class TestArchitecture method testIntrospection.
/**
* Checks the introspection possibilities before and after object creation.
* Especially check the 'unvalued' case.
*/
@Test
public void testIntrospection() {
Dictionary<String, String> configuration = new Hashtable<String, String>();
configuration.put("p5", "v5i");
configuration.put("p7", "v7i");
configuration.put("p9", "v9i");
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.components.arch.MyComponentToIntrospect", configuration);
// We don't get the service object until we finished the pre-instantiation tests.
ServiceReference reference = osgiHelper.waitForService(CheckService.class.getName(), "(instance.name=" + instance.getInstanceName() + ")", 1000);
assertNotNull(reference);
PropertyDescription[] properties = ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getProperties();
assertNotNull(properties);
// Check the properties.
assertEquals(getProperty(properties, "p1").getValue(), Property.UNVALUED);
assertEquals(getProperty(properties, "p2").getValue(), Property.UNVALUED);
// Default value
assertEquals(getProperty(properties, "p3").getValue(), "v3");
// Default value
assertEquals(getProperty(properties, "p4").getValue(), "v4");
// Instance value
assertEquals(getProperty(properties, "p5").getValue(), "v5i");
assertEquals(getProperty(properties, "p6").getValue(), Property.UNVALUED);
assertEquals(getProperty(properties, "p6").getValue(), Property.UNVALUED);
// Instance value
assertEquals(getProperty(properties, "p7").getValue(), "v7i");
assertEquals(getProperty(properties, "p8").getValue(), Property.UNVALUED);
// Instance value
assertEquals(getProperty(properties, "p9").getValue(), "v9i");
// Check the propagation
assertNull(reference.getProperty("p1"));
assertNull(reference.getProperty("p2"));
assertEquals(reference.getProperty("p3"), "v3");
assertEquals(reference.getProperty("p4"), "v4");
assertEquals(reference.getProperty("p5"), "v5i");
assertNull(reference.getProperty("p6"));
assertNull(reference.getProperty("p62"));
assertEquals(reference.getProperty("p7"), "v7i");
assertNull(reference.getProperty("p8"));
assertEquals(reference.getProperty("p9"), "v9i");
// Trigger instantiation
assertTrue(((CheckService) context.getService(reference)).check());
// Check new value.
assertEquals(getProperty(properties, "p1").getValue(), "v1");
assertEquals(getProperty(properties, "p2").getValue(), "v2");
// Default value
assertEquals(getProperty(properties, "p3").getValue(), "v3");
// Default value
assertEquals(getProperty(properties, "p4").getValue(), "v42");
// Field value
assertEquals(getProperty(properties, "p5").getValue(), "v52");
// Specific value used for null
assertEquals(getProperty(properties, "p6").getValue(), Property.UNVALUED);
// Specific value used for null
assertEquals(getProperty(properties, "p62").getValue(), "null");
// Instance value
assertEquals(getProperty(properties, "p7").getValue(), "v7i");
assertEquals(getProperty(properties, "p8").getValue(), Property.UNVALUED);
// Instance value
assertEquals(getProperty(properties, "p9").getValue(), "v9i");
// New valued properties are not propagated.
// It avoids having fluctuation ins the service registrations
// To enable this propagation use @ServiceProperty
}
Aggregations