Search in sources :

Example 36 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class ComponentStateListenerTest method testCustomComponentLifeCycleCallbacks.

public void testCustomComponentLifeCycleCallbacks() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a simple service component
    Component s = m.createComponent().setImplementation(new CustomComponentInstance(e)).setCallbacks("a", "b", "c", "d");
    // add it, and since it has no dependencies, it should be activated immediately
    m.add(s);
    // remove it so it gets destroyed
    m.remove(s);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 37 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class ComponentStateListenerTest method testComponentLifeCycleCallbacks.

public void testComponentLifeCycleCallbacks() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a simple service component
    Component s = m.createComponent().setImplementation(new ComponentInstance(e));
    // add it, and since it has no dependencies, it should be activated immediately
    m.add(s);
    // remove it so it gets destroyed
    m.remove(s);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 38 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class ConfigurationDependencyTest method testFELIX2987.

public void testFELIX2987() {
    // mimics testComponentWithRequiredConfigurationAndServicePropertyPropagation
    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 ConfigurationConsumer2(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, 5000);
    m.remove(s1);
    m.remove(s2);
    m.remove(s3);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 39 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class ConfigurationDependencyTest method testFELIX4907.

public void testFELIX4907() {
    // This test validates updated(null) is not invoked when a component that have a configuration dependency is stopped.
    DependencyManager m = getDM();
    Ensure e = new Ensure();
    Component s1 = m.createComponent().setImplementation(new ConfigurationConsumer3(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);
    e.waitForStep(3, 5000);
    m.remove(s1);
    e.waitForStep(4, 5000);
    m.remove(s2);
    // ensure we executed all steps inside the component instance
    e.step(6);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 40 with Ensure

use of org.apache.felix.dm.itest.util.Ensure in project felix by apache.

the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationWithTypeSafeConfiguration.

/**
 * Tests that we can provision a type-safe configuration to a component.
 */
public void testComponentWithRequiredConfigurationWithTypeSafeConfiguration() {
    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 ConfigurationConsumerWithTypeSafeConfiguration(e)).add(m.createConfigurationDependency().setCallback(null, "updated", MyConfig.class).setPid(PID).setPropagate(true));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e, PID)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    m.add(s1);
    m.add(s2);
    // s2 called in init
    e.waitForStep(1, 5000);
    // s1 called in updated(), then in init()
    e.waitForStep(3, 5000);
    // remove conf
    m.remove(s2);
    // s2 destroyed, s1 called in updated(null), s1 called in destroy()
    e.waitForStep(6, 5000);
    m.remove(s1);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Aggregations

Ensure (org.apache.felix.dm.itest.util.Ensure)135 Component (org.apache.felix.dm.Component)90 DependencyManager (org.apache.felix.dm.DependencyManager)90 ServiceRegistration (org.osgi.framework.ServiceRegistration)42 Hashtable (java.util.Hashtable)32 Dictionary (java.util.Dictionary)8 URL (java.net.URL)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ResourceHandler (org.apache.felix.dm.ResourceHandler)5 IOException (java.io.IOException)4 Dependency (org.apache.felix.dm.Dependency)4 ServiceDependency (org.apache.felix.dm.ServiceDependency)4 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)4 ArrayList (java.util.ArrayList)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 TimeUnit (java.util.concurrent.TimeUnit)2 ComponentStateListener (org.apache.felix.dm.ComponentStateListener)2 TestBase (org.apache.felix.dm.itest.util.TestBase)2 Bundle (org.osgi.framework.Bundle)2