Package org.apache.felix.dm.test.components

Examples of org.apache.felix.dm.test.components.Ensure


public class AdapterWithExtraDependenciesTest extends TestBase {
    @Test
    public void testAdapterWithExtraDependenciesAndCallbacks() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
       
        // create a service adapter that adapts to services S1 and has an optional dependency on services S2
        Component sa = m.createAdapterService(S1.class, null)
            .setImplementation(SA.class)
            .add(m.createServiceDependency().setService(S2.class).setCallbacks("add", "remove"));
        m.add(sa);
       
        // create a service S1, which triggers the creation of the first adapter instance (A1)
        Component s1 = m.createComponent().setInterface(S1.class.getName(), null).setImplementation(new S1Impl());
        m.add(s1);
       
        // create a service S2, which will be added to A1
        Component s2 = m.createComponent().setInterface(S2.class.getName(), null).setImplementation(new S2Impl(e));
        m.add(s2);
       
        // create a second service S1, which triggers the creation of the second adapter instance (A2)
        Component s1b = m.createComponent().setInterface(S1.class.getName(), null).setImplementation(new S1Impl());
        m.add(s1b);
       
        // observe that S2 is also added to A2
        e.waitForStep(2, 5000);
       
        // remove S2 again
        m.remove(s2);
       
        // make sure both adapters have their "remove" callbacks invoked
        e.waitForStep(4, 5000);
       
        m.remove(s1);
        m.remove(sa);
    }
View Full Code Here


public class FELIX2078_ServiceDependencyTest extends TestBase {
    @Test
    public void testRequiredServiceRegistrationAndConsumption() {
        DependencyManager m = new DependencyManager(context);
        // 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 sp2 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
        m.add(sp);
        m.add(sp2);
        System.out.println("adding client");
        m.add(sc);
        System.out.println("waiting");
        // wait until both services have been added to our consumer
        e.waitForStep(2, 5000);
        m.remove(sc);
        m.remove(sp2);
        m.remove(sp);
        // ensure we executed all steps inside the component instance
    }
View Full Code Here

   
    @Test
    public void testOptionalServiceRegistrationAndConsumption() {
        DependencyManager m = new DependencyManager(context);
        // 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 sp2 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component sc = m.createComponent().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(false).setCallbacks("add", "remove"));
        m.add(sp);
        m.add(sp2);
        m.add(sc);
        // wait until both services have been added to our consumer
        e.waitForStep(2, 5000);
        m.remove(sc);
        m.remove(sp2);
        m.remove(sp);
        // ensure we executed all steps inside the component instance
    }
View Full Code Here

public class ServiceUpdateTest extends TestBase {
    @Test
    public void testServiceUpdate() throws Exception {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a resource provider
        ResourceProvider provider = new ResourceProvider(e);
        // activate it
        m.add(m.createComponent()
        .setImplementation(new ServiceProvider(e))
        .add(m.createServiceDependency()
            .setService(ServiceInterface.class)
        .setRequired(true)
        .setCallbacks("add", "change", "remove")
      )
    );
       
        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
        CallbackInstance callbackInstance = new CallbackInstance(e);
        Properties serviceProps = new Properties();
        serviceProps.setProperty("number", "1");
        Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed")
            .setImplementation(new ResourceAdapter(e))
            .setInterface(ServiceInterface.class.getName(), serviceProps)
            .setCallbacks(callbackInstance, "init", "start", "stop", "destroy");
        m.add(component);
        // wait until the single resource is available
        e.waitForStep(1, 5000);
        // wait until the component gets the dependency injected
        e.waitForStep(2, 5000);
        // trigger a 'change' in our resource
        provider.change();
        // wait until the changed callback is invoked
        e.waitForStep(3, 5000);       
        // wait until the changed event arrived at the component
        e.waitForStep(4, 5000);
        System.out.println("Done!");
        m.clear();
     }
View Full Code Here

public class ConfigurationDependencyTest extends TestBase {
    @Test
    public void testComponentWithRequiredConfigurationAndServicePropertyPropagation() {
        DependencyManager m = new DependencyManager(context);
        // 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("test").setPropagate(true));
        Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e)).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, 15000);
        m.remove(s1);
        m.remove(s2);
        m.remove(s3);
        // ensure we executed all steps inside the component instance
        e.step(5);
    }
View Full Code Here

    @Test
    public void testFELIX2987() {
        // mimics testComponentWithRequiredConfigurationAndServicePropertyPropagation
        DependencyManager m = new DependencyManager(context);
        // 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 ConfigurationConsumer2(e)).setInterface(Runnable.class.getName(), null).add(m.createConfigurationDependency().setPid("test").setPropagate(true));
        Component s2 = m.createComponent().setImplementation(new ConfigurationCreator(e)).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, 15000);
        m.remove(s1);
        m.remove(s2);
        m.remove(s3);
        // ensure we executed all steps inside the component instance
        e.step(5);
    }
View Full Code Here

public class AspectWhiteboardTest extends TestBase {
    @Test
    public void testWhiteboardConsumer() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create service providers and consumer
        Component sp1 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
        ServiceConsumer sci = new ServiceConsumer(e);
        Component sc = m.createComponent().setImplementation(sci).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(false).setCallbacks("add", "remove"));
View Full Code Here

     */
     @Test
     public void testWithTwoAvailableExtraDependency() {  
         DependencyManager m = new DependencyManager(context);
         // Helper class that ensures certain steps get executed in sequence
         Ensure e = new Ensure();
         Component c1 = m.createComponent()
                         .setInterface(Service1.class.getName(), null)
                         .setImplementation(new MyComponent1(e))
                         .add(m.createServiceDependency()
                              .setService(Service2.class)
                              .setRequired(true)
                              .setAutoConfig("m_service2"));
        
         Component c2 = m.createComponent()
                         .setImplementation(new MyComponent2(e))
                         .add(m.createServiceDependency()
                              .setService(Service1.class)
                              .setRequired(false)
                              .setAutoConfig(false)
                              .setCallbacks("added", null, null));
             
         Component c3 = m.createComponent()
                         .setInterface(Service2.class.getName(), null)
                         .setImplementation(Service2Impl.class);
        
         Hashtable h = new Hashtable();
         h.put("type", "xx");
         Component c4 = m.createComponent()
                         .setInterface(Service3.class.getName(), h)
                         .setImplementation(Service3Impl1.class);

         h = new Hashtable();
         h.put("type", "yy");
         Component c5 = m.createComponent()
                         .setInterface(Service3.class.getName(), h)
                         .setImplementation(Service3Impl2.class);


         System.out.println("\n+++ Adding c2 / MyComponent2");
         m.add(c2);
         System.out.println("\n+++ Adding c3 / Service2");
         m.add(c3);
         System.out.println("\n+++ Adding c4 / Service3(xx)");
         m.add(c4);
         System.out.println("\n+++ Adding c5 / Service3(yy)");
         m.add(c5);
         System.out.println("\n+++ Adding c1 / MyComponent1");
         // c1 have declared two extra dependency on Service3 (xx/yy).
         // both extra dependencies are available, so the c1 component should be started immediately.
         m.add(c1);
         e.waitForStep(3, 3000);
         m.clear();
     }
View Full Code Here

     */
   @Test
    public void testWithOneAvailableExtraDependency() { 
        DependencyManager m = new DependencyManager(context);
        // Helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        Component c1 = m.createComponent()
                        .setInterface(Service1.class.getName(), null)
                        .setImplementation(new MyComponent1(e))
                        .add(m.createServiceDependency()
                             .setService(Service2.class)
                             .setRequired(true)
                             .setAutoConfig("m_service2"));
       
        Component c2 = m.createComponent()
                        .setImplementation(new MyComponent2(e))
                        .add(m.createServiceDependency()
                             .setService(Service1.class)
                             .setRequired(false)
                             .setAutoConfig(false)
                             .setCallbacks("added", null, null));
            
        Component c3 = m.createComponent()
                        .setInterface(Service2.class.getName(), null)
                        .setImplementation(Service2Impl.class);
       
        Hashtable h = new Hashtable();
        h.put("type", "xx");
        Component c4 = m.createComponent()
                        .setInterface(Service3.class.getName(), h)
                        .setImplementation(Service3Impl1.class);

        h = new Hashtable();
        h.put("type", "yy");
        Component c5 = m.createComponent()
                        .setInterface(Service3.class.getName(), h)
                        .setImplementation(Service3Impl2.class);


        System.out.println("\n+++ Adding c2 / MyComponent2");
        m.add(c2);
        System.out.println("\n+++ Adding c3 / Service2");
        m.add(c3);
        System.out.println("\n+++ Adding c4 / Service3(xx)");
        m.add(c4);
        System.out.println("\n+++ Adding c1 / MyComponent1");
        m.add(c1);

        // c1 have declared two extra dependency on Service3 (xx/yy).
        // So, because we have not yet added c5 (yy), c1 should not be started currently.
        // But, now, we'll add c5 (Service3/yy) and c1 should then be started ...
        System.out.println("\n+++ Adding c5 / Service3(yy)");
        m.add(c5);
        e.waitForStep(3, 3000);
        m.clear();
    }
View Full Code Here

        m.remove(consumer);
        // check if all bundles were removed correctly
        c.doubleCheck();
       
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        Component consumerWithFilter = m.createComponent().setImplementation(new FilteredConsumer(e)).add(m.createBundleDependency().setFilter("(Bundle-SymbolicName=org.apache.felix.dependencymanager)").setCallbacks("add", "remove"));
        // add a consumer with a filter
        m.add(consumerWithFilter);
        e.step(2);
        // remove the consumer again
        m.remove(consumerWithFilter);
        e.step(4);
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.dm.test.components.Ensure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.