Search in sources :

Example 96 with DependencyManager

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

the class FELIX2696_ConfigurationAndServiceDependencyTest 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)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true)).add(m.createConfigurationDependency().setPid(PID));
    Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e)).add(m.createServiceDependency().setService(ConfigurationAdmin.class).setRequired(true));
    Component s3 = m.createComponent().setInterface(ServiceInterface.class.getName(), null).setImplementation(DependentServiceProvider.class);
    m.add(s1);
    m.add(s2);
    m.add(s3);
    e.waitForStep(2, 5000);
    warn("removing s3");
    m.remove(s3);
    warn("readding s3");
    m.add(s3);
    // after adding the required dependency again, the issue in FELIX-2696 means that the
    // updated() method is not invoked for the new instance, and init() is, so our step
    // count will only go up to 3 (not 4) causing this test to fail
    e.waitForStep(4, 5000);
    m.remove(s3);
    m.remove(s2);
    m.remove(s1);
    e.waitForStep(5, 5000);
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) Ensure(org.apache.felix.dm.itest.util.Ensure) Component(org.apache.felix.dm.Component)

Example 97 with DependencyManager

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

the class FELIX4158_DependencyDeclarationTest method testResourceDependencyDeclarationWithFilter.

public void testResourceDependencyDeclarationWithFilter() {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createResourceDependency().setFilter("(&(path=/path/to/*.txt)(host=localhost))"));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), ("(&(path=/path/to/*.txt)(host=localhost))"));
    Assert.assertNull(cdds[0].getSimpleName());
    Assert.assertNotNull(cdds[0].getFilter());
    Assert.assertEquals(cdds[0].getFilter(), "(&(path=/path/to/*.txt)(host=localhost))");
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component)

Example 98 with DependencyManager

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

the class FELIX4158_DependencyDeclarationTest method testBundleDependencyDeclarationWithFilter.

public void testBundleDependencyDeclarationWithFilter() throws MalformedURLException {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createBundleDependency().setStateMask(Bundle.ACTIVE).setFilter("(DependencyManager-Component=*)"));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), "active (DependencyManager-Component=*)");
    Assert.assertNotNull(cdds[0].getSimpleName());
    Assert.assertEquals(cdds[0].getSimpleName(), "active");
    Assert.assertNotNull(cdds[0].getFilter());
    Assert.assertEquals(cdds[0].getFilter(), "(DependencyManager-Component=*)");
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component)

Example 99 with DependencyManager

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

the class FELIX4158_DependencyDeclarationTest method testBundleDependencyDeclaration.

public void testBundleDependencyDeclaration() throws MalformedURLException {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createBundleDependency());
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), "active installed resolved");
    Assert.assertNotNull(cdds[0].getSimpleName());
    Assert.assertEquals(cdds[0].getSimpleName(), "active installed resolved");
    Assert.assertNull(cdds[0].getFilter());
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) Component(org.apache.felix.dm.Component)

Example 100 with DependencyManager

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

the class FELIX4158_DependencyDeclarationTest method testBundleDependencyDeclarationWithMask.

public void testBundleDependencyDeclarationWithMask() throws MalformedURLException {
    DependencyManager m = getDM();
    Component c = m.createComponent().setImplementation(new Object()).add(m.createBundleDependency().setStateMask(Bundle.ACTIVE | Bundle.RESOLVED));
    ComponentDeclaration cd = c.getComponentDeclaration();
    ComponentDependencyDeclaration[] cdds = cd.getComponentDependencies();
    Assert.assertNotNull(cdds);
    Assert.assertNotNull(cdds.length == 1);
    Assert.assertEquals(cdds[0].getName(), "active resolved");
    Assert.assertNotNull(cdds[0].getSimpleName());
    Assert.assertEquals(cdds[0].getSimpleName(), "active resolved");
    Assert.assertNull(cdds[0].getFilter());
    m.clear();
}
Also used : ComponentDeclaration(org.apache.felix.dm.ComponentDeclaration) DependencyManager(org.apache.felix.dm.DependencyManager) ComponentDependencyDeclaration(org.apache.felix.dm.ComponentDependencyDeclaration) 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