use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.
the class InheritanceTest method getDependency.
private DependencyDescription getDependency(Architecture arch, String id) {
DependencyHandlerDescription hd = (DependencyHandlerDescription) arch.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
Assert.assertNotNull(hd);
for (DependencyDescription dd : hd.getDependencies()) {
if (dd.getId().equals(id)) {
return dd;
}
}
Assert.fail("Dependency " + id + " not found");
return null;
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.
the class TestContextualFilters method testContextualFilterAndInstanceReconfiguration.
/**
* This test check filter set using instance properties.
* However the instance is reconfigured a couple of times to illustrate the different case:
* - unset property
* - property updated
* - reconfiguration that does not impact the filter
*/
@Test
public void testContextualFilterAndInstanceReconfiguration() {
Properties configuration = new Properties();
Properties filters = new Properties();
filters.put("foo", "(id=${instance.id})");
configuration.put("requires.filters", filters);
configuration.put("instance.id", 2);
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components.context.ContextualFilterConsumer", configuration);
assertTrue(instance.getState() == ComponentInstance.VALID);
DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
DependencyDescription dependency = desc.getDependencies()[0];
assertEquals("(id=2)", dependency.getFilter());
// Reconfigure the instance.
Properties newProps = new Properties();
newProps.put("instance.id", "3");
instance.reconfigure(newProps);
assertTrue(instance.getState() == ComponentInstance.INVALID);
desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
dependency = desc.getDependencies()[0];
assertEquals("(id=3)", dependency.getFilter());
// Another reconfiguration (that does not affect the filters)
newProps = new Properties();
newProps.put("instance.id", "3");
newProps.put("stuff", "stuff");
instance.reconfigure(newProps);
assertTrue(instance.getState() == ComponentInstance.INVALID);
desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
dependency = desc.getDependencies()[0];
assertEquals("(id=3)", dependency.getFilter());
// Yet another reconfiguration, un-setting instance.id
newProps = new Properties();
newProps.put("stuff", "stuff");
instance.reconfigure(newProps);
assertTrue(instance.getState() == ComponentInstance.INVALID);
desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
dependency = desc.getDependencies()[0];
assertEquals("(id=${instance.id})", dependency.getFilter());
// Finally another reconfiguration to build a fulfilled filter
newProps = new Properties();
newProps.put("instance.id", "1");
newProps.put("stuff", "stuff");
instance.reconfigure(newProps);
assertTrue(instance.getState() == ComponentInstance.VALID);
desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
dependency = desc.getDependencies()[0];
assertEquals("(id=1)", dependency.getFilter());
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.
the class TestContextualFilters method testContextualFilterWithUnsetSystemProperty.
@Test
public void testContextualFilterWithUnsetSystemProperty() {
// Just to be sure.
System.clearProperty("env.id");
Properties configuration = new Properties();
Properties filters = new Properties();
filters.put("foo", "(id=${env.id})");
configuration.put("requires.filters", filters);
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components.context.ContextualFilterConsumer", configuration);
assertTrue(instance.getState() == ComponentInstance.INVALID);
DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
DependencyDescription dependency = desc.getDependencies()[0];
assertEquals("(id=${env.id})", dependency.getFilter());
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.
the class TestContextualFiltersAndExternalSources method testContextualFilterUsingOneSourceAppearingLater.
@Test
public void testContextualFilterUsingOneSourceAppearingLater() {
MyContextSource source = new MyContextSource();
source.set("source.id", 2);
Properties configuration = new Properties();
Properties filters = new Properties();
filters.put("foo", "(id=${source.id})");
configuration.put("requires.filters", filters);
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components.context.ContextualFilterConsumer", configuration);
assertTrue(instance.getState() == ComponentInstance.INVALID);
DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
DependencyDescription dependency = desc.getDependencies()[0];
assertEquals("(id=${source.id})", dependency.getFilter());
registration = context.registerService(ContextSource.class.getName(), source, null);
assertTrue(instance.getState() == ComponentInstance.VALID);
desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix" + ".ipojo:requires");
// Only one dependency.
dependency = desc.getDependencies()[0];
assertEquals("(id=2)", dependency.getFilter());
}
use of org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription in project felix by apache.
the class TestContextualFiltersAndExternalSources method testContextualFilterUsingOneSourceWithReconfiguration.
@Test
public void testContextualFilterUsingOneSourceWithReconfiguration() {
MyContextSource source = new MyContextSource();
source.set("source.id", 2);
registration = context.registerService(ContextSource.class.getName(), source, null);
Properties configuration = new Properties();
Properties filters = new Properties();
filters.put("foo", "(id=${source.id})");
configuration.put("requires.filters", filters);
ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" + ".components.context.ContextualFilterConsumer", configuration);
assertTrue(instance.getState() == ComponentInstance.VALID);
// Set id to 3 => INVALID
source.set("source.id", 3);
assertTrue(instance.getState() == ComponentInstance.INVALID);
// Set id to null
source.set("source.id", null);
assertTrue(instance.getState() == ComponentInstance.INVALID);
DependencyHandlerDescription desc = (DependencyHandlerDescription) instance.getInstanceDescription().getHandlerDescription("org.apache.felix.ipojo:requires");
DependencyDescription dependency = desc.getDependencies()[0];
assertEquals("(id=${source.id})", dependency.getFilter());
// Register a new source.
MyContextSource source2 = new MyContextSource();
source2.set("source.id", 2);
registration2 = context.registerService(ContextSource.class.getName(), source2, null);
assertTrue(instance.getState() == ComponentInstance.VALID);
// This new source disappear
registration2.unregister();
registration2 = null;
assertTrue(instance.getState() == ComponentInstance.INVALID);
source.set("source.id", 1);
assertTrue(instance.getState() == ComponentInstance.VALID);
}
Aggregations