Search in sources :

Example 51 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class ComponentFactoryAnnotationTest method testServiceFactory.

public void testServiceFactory() {
    ServiceRegistration sr = register(m_ensure, ComponentFactoryAnnotation.ENSURE);
    DependencyManager m = new DependencyManager(context);
    // Wait for the factory.
    m.add(m.createComponent().setImplementation(this).add(m.createServiceDependency().setService(ComponentFactory.class, "(" + Component.FACTORY_NAME + "=" + ComponentFactoryAnnotation.FACTORY + ")").setRequired(true).setCallbacks("bindFactory", null)));
    // Check if the test.annotation components have been initialized orderly
    m_ensure.waitForStep(10, 5000);
    m.clear();
    sr.unregister();
}
Also used : DependencyManager(org.apache.felix.dm.DependencyManager) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 52 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class ConfigurationDependencyAnnotationTest method testConfigurationDependencyWithAnotherExtraDynamicConfigurationAnnotation.

/**
 * Tests a Component two ConfigurationDependency (the second one is "instance bound"
 * and its pid is declared from the init method).
 */
@SuppressWarnings({ "serial", "rawtypes", "unchecked" })
public void testConfigurationDependencyWithAnotherExtraDynamicConfigurationAnnotation() throws Throwable {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, ConfigurableComponentWithDynamicExtraConfiguration.ENSURE);
    ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
    try {
        org.osgi.service.cm.Configuration cf = cm.getConfiguration(ConfigurableComponentWithDynamicExtraConfiguration.class.getName(), null);
        cf.update(new Hashtable() {

            {
                put("foo", "bar");
                // Pid of the second Configuration Dependency.
                put("dynamicPid", "dynamicPid");
            }
        });
        org.osgi.service.cm.Configuration extraCf = cm.getConfiguration("dynamicPid", null);
        extraCf.update(new Hashtable() {

            {
                put("foo2", "bar2");
            }
        });
        e.waitForStep(4, MAXWAIT);
        cf.delete();
        extraCf.delete();
        e.waitForStep(5, MAXWAIT);
        e.ensure();
        sr.unregister();
    } catch (IOException err) {
        err.printStackTrace();
        Assert.fail("can't create factory configuration");
    }
}
Also used : ConfigurableComponentWithDynamicExtraConfiguration(org.apache.felix.dm.runtime.itest.components.ConfigurationDependencyAnnotation.ConfigurableComponentWithDynamicExtraConfiguration) Hashtable(java.util.Hashtable) IOException(java.io.IOException) Ensure(org.apache.felix.dm.itest.util.Ensure) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 53 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class ConfigurationDependencyAnnotationTest method testConfigurationDependencyAnnotation.

/**
 * Tests the ConfigurationDependency annotation.
 */
@SuppressWarnings({ "serial", "rawtypes", "unchecked" })
public void testConfigurationDependencyAnnotation() throws Throwable {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, ConfigurableComponent.ENSURE);
    ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
    try {
        org.osgi.service.cm.Configuration cf = cm.getConfiguration(ConfigurableComponent.class.getName(), null);
        cf.update(new Hashtable() {

            {
                put("foo", "bar");
            }
        });
        e.waitForStep(1, MAXWAIT);
        cf.delete();
        e.waitForStep(3, MAXWAIT);
        e.ensure();
        sr.unregister();
    } catch (IOException err) {
        err.printStackTrace();
        Assert.fail("can't create factory configuration");
    }
}
Also used : Hashtable(java.util.Hashtable) ConfigurableComponent(org.apache.felix.dm.runtime.itest.components.ConfigurationDependencyAnnotation.ConfigurableComponent) IOException(java.io.IOException) Ensure(org.apache.felix.dm.itest.util.Ensure) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 54 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class ConfigurationProxyTest method testConfigurationProxy.

/**
 * Validates ServiceDependency method signatures.
 */
public void testConfigurationProxy() {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, ConfigurationProxy.ENSURE_CONFIG_DEPENDENCY);
    e.waitForStep(1, 5000);
    sr.unregister();
    e.waitForStep(3, 5000);
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 55 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class ExtraServicePropertiesTest method testExtraServiceProperties.

/**
 * Tests if a Service can provide its service properties from its start method.
 */
public void testExtraServiceProperties() {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, ExtraServiceProperties.ENSURE);
    e.waitForStep(2, 10000);
    sr.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

ServiceRegistration (org.osgi.framework.ServiceRegistration)365 Test (org.junit.Test)106 Hashtable (java.util.Hashtable)94 Bundle (org.osgi.framework.Bundle)64 BundleContext (org.osgi.framework.BundleContext)64 Dictionary (java.util.Dictionary)62 Ensure (org.apache.felix.dm.itest.util.Ensure)42 Properties (java.util.Properties)39 ServiceReference (org.osgi.framework.ServiceReference)38 ArrayList (java.util.ArrayList)34 HashMap (java.util.HashMap)28 ServiceFactory (org.osgi.framework.ServiceFactory)21 IOException (java.io.IOException)16 Map (java.util.Map)15 List (java.util.List)12 ServiceEvent (org.osgi.framework.ServiceEvent)12 HashSet (java.util.HashSet)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 Collection (java.util.Collection)9