Search in sources :

Example 66 with Ensure

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

the class ExtraServicePropertiesTest method testExtraFactoryServiceProperties.

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

Example 67 with Ensure

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

the class FELIX5337Test method testCatchAllServicesUsingAnnotation.

public void testCatchAllServicesUsingAnnotation() {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, FELIX5337.ENSURE);
    // wait for S to be started
    e.waitForStep(2, 5000);
    // remove our sequencer: this will stop S
    sr.unregister();
    // ensure that S is stopped and destroyed
    e.waitForStep(3, 5000);
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 68 with Ensure

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

the class FactoryConfigurationAdapterAnnotationTest method testFactoryConfigurationAdapterAnnotation.

@SuppressWarnings("serial")
public void testFactoryConfigurationAdapterAnnotation() throws Throwable {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, ServiceProvider.ENSURE);
    ConfigurationAdmin cm = (ConfigurationAdmin) context.getService(context.getServiceReference(ConfigurationAdmin.class.getName()));
    try {
        // Create a factory configuration in order to instantiate the ServiceProvider
        org.osgi.service.cm.Configuration cf = cm.createFactoryConfiguration("FactoryPidTest", null);
        cf.update(new Hashtable() {

            {
                put("foo2", "bar2");
            }
        });
        // Wait for the ServiceProvider activation.
        e.waitForStep(2, MAXWAIT);
        // Update conf
        cf.update(new Hashtable() {

            {
                put("foo2", "bar2_modified");
            }
        });
        // Wait for effective update
        e.waitForStep(4, MAXWAIT);
        // Remove configuration.
        cf.delete();
        // Check if ServiceProvider has been stopped.
        e.waitForStep(6, MAXWAIT);
        e.ensure();
        sr.unregister();
    } catch (IOException err) {
        err.printStackTrace();
        Assert.fail("can't create factory configuration");
    }
}
Also used : 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 69 with Ensure

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

the class Felix4357Test method testSingleProperty.

public void testSingleProperty() {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, Felix4357.ENSURE);
    // wait for S to be started
    e.waitForStep(30, 10000);
    // remove our sequencer: this will stop S
    sr.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 70 with Ensure

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

the class ResourceAdapterDependencyAddAndRemoveTest2 method testBasicResourceAdapter.

public void testBasicResourceAdapter() throws Exception {
    DependencyManager m = getDM();
    // helper class that ensures certain steps get executed in sequence
    Ensure e = new Ensure();
    // create a resource provider
    ResourceProvider provider = new ResourceProvider(context, new URL("file://localhost/path/to/file1.txt"));
    // activate it
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put("id", "1");
    m.add(m.createComponent().setInterface(ServiceInterface.class.getName(), props).setImplementation(new ServiceProvider(e)));
    props = new Hashtable<String, String>();
    props.put("id", "2");
    m.add(m.createComponent().setInterface(ServiceInterface.class.getName(), props).setImplementation(new ServiceProvider(e)));
    m.add(m.createComponent().setImplementation(provider).add(m.createServiceDependency().setService(ResourceHandler.class).setCallbacks("add", "remove")));
    // create a resource adapter for our single resource
    // note that we can provide an actual implementation instance here because there will be only one
    // adapter, normally you'd want to specify a Class here
    Dependency d = m.createServiceDependency().setService(ServiceInterface.class, "(id=1)").setRequired(true);
    ResourceAdapter service = new ResourceAdapter(e, d);
    CallbackInstance callbackInstance = new CallbackInstance(e, d);
    Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed").setImplementation(service).setCallbacks(callbackInstance, "init", "start", "stop", "destroy");
    component.add(new ComponentStateListenerImpl(e));
    m.add(component);
    // wait until the single resource is available
    e.waitForStep(1, 5000);
    // trigger a 'change' in our resource
    provider.change();
    // wait until the changed callback is invoked
    e.waitForStep(2, 5000);
    System.out.println("Done!");
    m.clear();
}
Also used : Hashtable(java.util.Hashtable) DependencyManager(org.apache.felix.dm.DependencyManager) ResourceHandler(org.apache.felix.dm.ResourceHandler) Dependency(org.apache.felix.dm.Dependency) URL(java.net.URL) 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