Search in sources :

Example 76 with DependencyManager

use of org.apache.felix.dm.DependencyManager in project felix by apache.

the class BundleAdapterWithCallbacksNotAutoConfiguredTest method testBundleAdapterWithCallbacksNotAutoConfigured.

public void testBundleAdapterWithCallbacksNotAutoConfigured() {
    DependencyManager m = getDM();
    // create a bundle adapter service (one is created for each bundle)
    BundleAdapterWithCallback baWithCb = new BundleAdapterWithCallback();
    String bsn = "org.apache.felix.dependencymanager";
    String filter = "(Bundle-SymbolicName=" + bsn + ")";
    Component adapter = m.createBundleAdapterService(Bundle.ACTIVE, filter, false, null, "add", null, null).setImplementation(baWithCb);
    // add the bundle adapter
    m.add(adapter);
    // Check if adapter has not been auto configured (because it has callbacks defined).
    m_e.waitForStep(1, 3000);
    Assert.assertNull("bundle adapter must not be auto configured", baWithCb.getBundle());
    // remove the bundle adapters
    m.remove(adapter);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component)

Example 77 with DependencyManager

use of org.apache.felix.dm.DependencyManager in project felix by apache.

the class BundleDependencyTest method testRequiredBundleDependency.

public void testRequiredBundleDependency() {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    Component consumerWithFilter = m.createComponent().setImplementation(new FilteredConsumerRequired(e)).add(m.createBundleDependency().setRequired(true).setFilter("(Bundle-SymbolicName=" + BSN + ")").setCallbacks("add", "remove"));
    // add a consumer with a filter
    m.add(consumerWithFilter);
    e.waitForStep(1, 5000);
    // remove the consumer again
    m.remove(consumerWithFilter);
    e.waitForStep(2, 5000);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 78 with DependencyManager

use of org.apache.felix.dm.DependencyManager in project felix by apache.

the class ComponentStateListenerTest method testDynamicComponentStateListingLifeCycle.

public void testDynamicComponentStateListingLifeCycle() {
    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().setInterface(MyInterface.class.getName(), null).setImplementation(new DynamicComponentStateListeningInstance(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(10);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 79 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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 80 with DependencyManager

use of org.apache.felix.dm.DependencyManager 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)

Aggregations

DependencyManager (org.apache.felix.dm.DependencyManager)255 Component (org.apache.felix.dm.Component)226 Ensure (org.apache.felix.dm.itest.util.Ensure)91 DependencyManagerActivator.component (org.apache.felix.dm.lambda.DependencyManagerActivator.component)70 Hashtable (java.util.Hashtable)56 Assert (org.junit.Assert)50 Dictionary (java.util.Dictionary)28 Map (java.util.Map)27 ServiceReference (org.osgi.framework.ServiceReference)24 DependencyManagerActivator.aspect (org.apache.felix.dm.lambda.DependencyManagerActivator.aspect)21 ServiceRegistration (org.osgi.framework.ServiceRegistration)18 DependencyManagerActivator.adapter (org.apache.felix.dm.lambda.DependencyManagerActivator.adapter)15 Bundle (org.osgi.framework.Bundle)15 HashMap (java.util.HashMap)13 ArrayList (java.util.ArrayList)12 ComponentDeclaration (org.apache.felix.dm.ComponentDeclaration)12 ServiceDependency (org.apache.felix.dm.ServiceDependency)11 Properties (java.util.Properties)10 List (java.util.List)9 DependencyGraph (org.apache.felix.dm.diagnostics.DependencyGraph)9