use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class ConfigurationDependencyTest method testFELIX4907_updated_with_null_dictionary_called_when_configuration_is_lost.
public void testFELIX4907_updated_with_null_dictionary_called_when_configuration_is_lost() {
DependencyManager m = getDM();
Ensure e = new Ensure();
Component s1 = m.createComponent().setImplementation(new ConfigurationConsumer4(e)).add(m.createConfigurationDependency().setPid(PID));
Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
m.add(s1);
m.add(s2);
// component configured and started.
e.waitForStep(3, 5000);
// configuration will be removed
m.remove(s2);
// configuration creator destroyed
e.waitForStep(4, 5000);
// consumer called in updated(null)
e.waitForStep(5, 5000);
// consumer des
e.waitForStep(6, 5000);
m.remove(s1);
// ensure we executed all steps inside the component instance
e.step(7);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationWithComponentArgAndServicePropertyPropagation.
public void testComponentWithRequiredConfigurationWithComponentArgAndServicePropertyPropagation() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service provider and consumer
Component s1 = m.createComponent().setImplementation(new ConfigurationConsumerWithComponentArg(e)).setInterface(Runnable.class.getName(), null).add(m.createConfigurationDependency().setPid(PID).setPropagate(true));
Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
Component s3 = m.createComponent().setImplementation(new ConfiguredServiceConsumer(e)).add(m.createServiceDependency().setService(Runnable.class, ("(testkey=testvalue)")).setRequired(true));
m.add(s1);
m.add(s2);
m.add(s3);
e.waitForStep(4, 50000000);
m.remove(s1);
m.remove(s2);
m.remove(s3);
// ensure we executed all steps inside the component instance
e.step(6);
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2344_ExtraDependencyWithAutoConfigTest method testExtraDependencyWithAutoConfig.
/**
* Test if an auto config extra dependency is injected in the expected order.
*/
public void testExtraDependencyWithAutoConfig() {
DependencyManager m = getDM();
// Helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// Create a service provider
Component sp = m.createComponent().setInterface(ProviderInterface.class.getName(), null).setImplementation(ProviderImpl.class);
// Create a service consumer with a required/autoconfig dependency over the service provider.
Client c1;
Component sc1 = m.createComponent().setImplementation((c1 = new Client(e, true, 1)));
// Create a second service consumer with an optional/autoconfig dependency over the service provider.
Client c2;
Component sc2 = m.createComponent().setImplementation(c2 = new Client(e, false, 3));
// Add service provider and consumer sc1 (required dependency over provider)
m.add(sc1);
m.add(sp);
e.waitForStep(2, 5000);
// Remove provider and consumer
m.remove(sc1);
m.remove(sp);
// Add consumer sc2 (optional dependency over provider)
m.add(sc2);
e.waitForStep(4, 5000);
m.clear();
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2344_ExtraDependencyWithCallbackTest method testExtraDependencyWithCallback.
/**
* Checks if an extra optional/required dependency is properly injected into a consumer, using callbacks.
*/
public void testExtraDependencyWithCallback() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service consumer and provider
Component sp = m.createComponent().setInterface(ProviderInterface.class.getName(), null).setImplementation(ProviderImpl.class);
Component sc = m.createComponent().setImplementation(new Client(e, false, 1));
Component sc2 = m.createComponent().setImplementation(new Client(e, true, 5));
Component sc3 = m.createComponent().setImplementation(new Client(e, true, 9));
// add the provider first, then add the consumer which initially will have no dependencies
// but via the init() method an optional dependency with a callback method will be added
m.add(sp);
m.add(sc);
// remove the consumer again
m.remove(sc);
e.waitForStep(4, 5000);
// next up, add a second consumer, identical to the first, but with a required dependency
// with a callback method which will be added in the init() method
m.add(sc2);
// remove the consumer again
m.remove(sc2);
e.waitForStep(8, 5000);
// now remove the provider, add a third consumer, identical to the second, and after the
// consumer has started, add the provider again
m.remove(sp);
m.add(sc3);
m.add(sp);
e.waitForStep(12, 5000);
m.clear();
}
use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.
the class FELIX2369_ExtraDependencyTest method testExtraDependencies.
public void testExtraDependencies() {
DependencyManager m = getDM();
// helper class that ensures certain steps get executed in sequence
Ensure e = new Ensure();
// create a service consumer and provider
Component sp1 = m.createComponent().setInterface(MyService1.class.getName(), null).setImplementation(new MyService1Impl());
Component sc = m.createComponent().setImplementation(new MyClient(e, 1));
// provides the MyService1 service (but not the MyService2, which is required by MyClient).
m.add(sp1);
// add MyClient (it should not be invoked in its start() method because MyService2 is not there
m.add(sc);
// remove MyClient (it should not be invoked in its stop() method because it should not be active, since MyService2 is not there.
m.remove(sc);
e.waitForStep(2, 5000);
m.clear();
}
Aggregations