Search in sources :

Example 91 with Ensure

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

the class ComponentStateListenerTest method testComponentStateListingLifeCycle.

public void testComponentStateListingLifeCycle() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a simple service component
    ComponentStateListeningInstance implementation = new ComponentStateListeningInstance(e);
    Component s = m.createComponent().setInterface(MyInterface.class.getName(), null).setImplementation(implementation);
    // add the state listener
    s.add(implementation);
    // 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);
    // remove the state listener
    s.remove(implementation);
    // ensure we executed all steps inside the component instance
    e.step(10);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 92 with Ensure

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

the class CompositionTest method testComposition.

public void testComposition() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a service provider and consumer
    Component sp = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
    Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).setComposition("getComposition").add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", null));
    m.add(sp);
    m.add(sc);
    // ensure we executed all steps inside the component instance
    e.step(6);
    m.clear();
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 93 with Ensure

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

the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationAndCallbackInstanceWithComponentArgAndServicePropertyPropagation.

public void testComponentWithRequiredConfigurationAndCallbackInstanceWithComponentArgAndServicePropertyPropagation() {
    Ensure e = new Ensure();
    ConfigurationConsumerCallbackInstanceWithComponentArg callbackInstance = new ConfigurationConsumerCallbackInstanceWithComponentArg(e);
    testComponentWithRequiredConfigurationAndCallbackInstanceAndServicePropertyPropagation(callbackInstance, "updateConfiguration", e);
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure)

Example 94 with Ensure

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

the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationAndCallbackInstanceAndServicePropertyPropagation.

public void testComponentWithRequiredConfigurationAndCallbackInstanceAndServicePropertyPropagation() {
    Ensure e = new Ensure();
    ConfigurationConsumerCallbackInstance callbackInstance = new ConfigurationConsumerCallbackInstance(e);
    testComponentWithRequiredConfigurationAndCallbackInstanceAndServicePropertyPropagation(callbackInstance, "updateConfiguration", e);
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure)

Example 95 with Ensure

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

the class ConfigurationDependencyTest method testComponentWithRequiredConfigurationAndServicePropertyPropagation.

public void 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 ConfigurationConsumer(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)

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