Examples of Ensure


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

     */
    @Test
    public void testServiceDependencyPropagate() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        Component c1 = m.createComponent()
                      .setImplementation(new C1(e))
                      .add(m.createServiceDependency().setService(C2.class).setRequired(true).setCallbacks("bind", null));

        Component c2 = m.createComponent()
                      .setInterface(C2.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
                      .setImplementation(new C2())
                      .add(m.createServiceDependency().setService(C3.class).setRequired(true).setPropagate(true));

        Component c3 = m.createComponent()
                      .setInterface(C3.class.getName(), new Hashtable() {{ put("foo2", "bar2"); }})
                      .setImplementation(new C3());
       
        m.add(c1);
        m.add(c2);
        m.add(c3);

        e.waitForStep(3, 10000);
       
        m.remove(c3);
        m.remove(c2);
        m.remove(c1);
        m.clear();
View Full Code Here

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

     */
    @Test
    public void testServiceDependencyPropagateCallback() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        Component c1 = m.createComponent()
                      .setImplementation(new C1(e))
                      .add(m.createServiceDependency().setService(C2.class).setRequired(true).setCallbacks("bind", null));

        C2 c2Impl = new C2();
        Component c2 = m.createComponent()
                      .setInterface(C2.class.getName(), new Hashtable() {{ put("foo", "bar"); }})
                      .setImplementation(c2Impl)
                      .add(m.createServiceDependency().setService(C3.class).setRequired(true).setPropagate(c2Impl, "getServiceProperties"));
       
        Component c3 = m.createComponent()
                      .setInterface(C3.class.getName(), null)
                      .setImplementation(new C3());
       
        m.add(c1);
        m.add(c2);
        m.add(c3);

        e.waitForStep(3, 10000);
        m.clear();
    }
View Full Code Here

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

public class ResourceAdapterDependencyAddAndRemoveTest extends TestBase {
    @Test
    public void testBasicResourceAdapter() throws Exception {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();

        // create and add a service provider
        m.add(m.createComponent()
            .setInterface(ServiceInterface.class.getName(), null)
            .setImplementation(new ServiceProvider(e)));
       
        // create and add a resource provider
        ResourceProvider provider = new ResourceProvider(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
        // also, create a callback instance which will be used for both callbacks on resource changes and
        // life cycle callbacks on the adapters themselves
        CallbackInstance callbackInstance = new CallbackInstance(e);
        Component component = m.createResourceAdapterService("(&(path=/path/to/*.txt)(host=localhost))", false, callbackInstance, "changed")
            .setImplementation(new ResourceAdapter(e))
            .setCallbacks(callbackInstance, "init", "start", "stop", "destroy")
            .add(m.createServiceDependency()
            .setService(ServiceInterface.class)
            .setRequired(true)
            .setInstanceBound(true));
        // add a component state listener
        component.addStateListener(new ComponentStateListenerImpl(e));
        // add the resource adapter
        m.add(component);
        // wait until the single resource is available (the adapter has been started)
        e.waitForStep(1, 5000);
        // trigger a 'change' in our resource
        provider.change();
        // wait until the changed callback is invoked
        e.waitForStep(2, 5000);
        // and has completed (ensuring no "extra" steps are invoked in the mean time)
        e.waitForStep(3, 5000);
       
        // remove the resource adapter again
        m.remove(component);
       
        // wait for the stopped callback in the state listener
        e.waitForStep(4, 5000);
     }
View Full Code Here

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

public class ComponentLifeCycleTest extends TestBase {
    @Test
    public void testComponentLifeCycleCallbacks() {
        DependencyManager m = new DependencyManager(context);
        // 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);
    }
View Full Code Here

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

    @Test
    public void testCustomComponentLifeCycleCallbacks() {
        DependencyManager m = new DependencyManager(context);
        // 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);
    }
View Full Code Here

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

public class AspectBaseTest extends TestBase {   
    @Test
    public void testSingleAspect() {
        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
        ServiceProvider p = new ServiceProvider(e, "a");
        ServiceConsumer c = new ServiceConsumer(e);
        Component sp = m.createComponent()
            .setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "a"); }})
            .setImplementation(p);
        Component sc = m.createComponent()
            .setImplementation(c)
            .add(m.createServiceDependency()
                .setService(ServiceInterface.class)
                .setRequired(true)
                .setCallbacks("add", "remove")
                .setAutoConfig(true)
            );
        Component sa = m.createAspectService(ServiceInterface.class, null, 20, null)
            .setImplementation(ServiceAspect.class);
        m.add(sc);
        m.add(sp);
        // after the provider was added, the consumer's add should have been invoked once
        e.waitForStep(1, 2000);
        Assert.assertEquals("a", c.invoke());
        m.add(sa);
        // after the aspect was added, the consumer should get and add for the aspect and a remove
        // for the original service
        e.waitForStep(3, 2000);
        Assert.assertEquals("aa", c.invoke());
        m.remove(sa);
        // removing the aspect again should give a remove and add
        e.waitForStep(5, 2000);
        Assert.assertEquals("a", c.invoke());
        m.remove(sp);
        // finally removing the original service should give a remove
        e.waitForStep(6, 2000);
        m.remove(sc);
        e.step(7);
    }
View Full Code Here

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

   
    @Test
    public void testSingleAspectThatAlreadyExisted() {
        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
        ServiceProvider p = new ServiceProvider(e, "a");
        ServiceConsumer c = new ServiceConsumer(e);
        Component sp = m.createComponent().setImplementation(p).setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "a"); }});
        Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove").setAutoConfig(true));
        Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
        // we first add the aspect
        m.add(sa);
        // then the service provider
        m.add(sp);
        // finally the consumer
        m.add(sc);

        Assert.assertEquals("aa", c.invoke());
       
        // now the consumer's added should be invoked once, as the aspect is already available and should
        // directly hide the original service
        e.waitForStep(1, 2000);
        e.step(2);

        m.remove(sa);
        // after removing the aspect, the consumer should get the original service back, so
        // remove and add will be invoked
        e.waitForStep(4, 2000);
       
        Assert.assertEquals("a", c.invoke());
       
        m.remove(sp);
        // after removing the original service, the consumer's remove should be called once
        e.waitForStep(5, 2000);
       
        m.remove(sc);
        e.step(6);
    }
View Full Code Here

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

    @Test
    public void testMultipleAspects() {
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
       
        // create service providers and consumers
        ServiceConsumer c = new ServiceConsumer(e);
        Component sp = m.createComponent().setImplementation(new ServiceProvider(e, "a")).setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "a"); }});
        Component sp2 = m.createComponent().setImplementation(new ServiceProvider(e, "b")).setInterface(ServiceInterface.class.getName(), new Properties() {{ put("name", "b"); }});
        Component sc = m.createComponent().setImplementation(c).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true).setCallbacks("add", "remove"));
        Component sa = m.createAspectService(ServiceInterface.class, null, 20, null).setImplementation(ServiceAspect.class);
        Component sa2 = m.createAspectService(ServiceInterface.class, null, 10, null).setImplementation(ServiceAspect.class);
        m.add(sp);
        m.add(sp2);
        m.add(sa);
        m.add(sa2);
        m.add(sc);
        // the consumer will monitor progress, it should get it's add invoked twice, once for every
        // (highest) aspect
        e.waitForStep(2, 2000);
        e.step(3);
       
        // now invoke all services the consumer collected
        List<String> list = c.invokeAll();
        // and make sure both of them are correctly invoked
        Assert.assertTrue(list.size() == 2);
        Assert.assertTrue(list.contains("aaa"));
        Assert.assertTrue(list.contains("bbb"));
       
        m.remove(sc);
        // removing the consumer now should get its removed method invoked twice
        e.waitForStep(5, 2000);
        e.step(6);
        m.remove(sa2);
        m.remove(sa);
        m.remove(sp2);
        m.remove(sp);
        e.step(7);
    }
View Full Code Here

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

                break;
            }
        }
        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
       
        Component shellClient = m.createComponent()
            .setImplementation(new ShellClient(e))
            .add(m.createServiceDependency()
                .setService(CommandProcessor.class)
                .setRequired(true)
            );
        m.add(shellClient);
        e.waitForStep(3, 5000);
        // now create a component with a missing dependency
        Component missing = m.createComponent()
            .setImplementation(new Object() { public String toString() { return "Object"; }})
            .add(m.createServiceDependency()
                .setService(Object.class)
                .setRequired(true)
            );
        m.add(missing);
        e.step(4);
        e.waitForStep(5, 5000);
        m.remove(missing);
        // now start/stop deploymentadmin, which we use here because it's a bundle that
        // publishes a service that uses the dependency manager (saving us from having to
        // create a bundle that does that on the fly)
        m_deploymentAdmin.start();
        m_deploymentAdmin.stop();
        e.step(6);
        e.waitForStep(7, 5000);
        e.ensure();
        m.remove(shellClient);
       
    }
View Full Code Here

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

    }
   
    @Test
    public void testAdapterWithChangedInstanceBoundDependency() {
        DependencyManager m = new DependencyManager(context);
        Ensure e = new Ensure();

        Dictionary props = new Hashtable();
        props.put("foo", "bar");
        Component a = m.createComponent()
                .setImplementation(new AImpl(e))
                .setInterface(A.class.getName(), props);
       
        Component b = m.createAdapterService(A.class, null, "add", "change", "remove")
                .setInterface(B.class.getName(), null)
                .setImplementation(new BImpl(e));               
       
        Component c = m.createComponent()
                .setImplementation(new CImpl())
                .setInterface(C.class.getName(), null)
                .add(m.createServiceDependency().setService(A.class, "(foo=bar)").setRequired(true));                    
             
        m.add(a);
        m.add(c);
        m.add(b);
       
        e.waitForStep(4, 5000);
       
        System.out.println("changing A props ...");
        props = new Hashtable();
        props.put("foo", "bar2");
        a.setServiceProperties(props);
       
        e.waitForStep(7, 5000);               
       
        m.remove(c);
        m.remove(a);
        m.remove(b);
       
        e.waitForStep(9, 5000);               
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.