Package org.apache.felix.dm

Examples of org.apache.felix.dm.DependencyManager


   
    /** Go through a simple session, containing two empty configurations. */
    public void testSimpleSession() throws Exception {
        AutoConfResourceProcessor p = new AutoConfResourceProcessor();
        Utils.configureObject(p, LogService.class);
        Utils.configureObject(p, DependencyManager.class, new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class)) {
          public void remove(Component service) {
          }
        });
        File tempDir = File.createTempFile("persistence", "dir");
        tempDir.delete();
        tempDir.mkdirs();
       
        System.out.println("Temporary dir: " + tempDir);
       
        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
        Session s = new Session();
        p.begin(s);
        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
            public DependencyManager getDependencyManager() {
                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
            }
        }));
        p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
        p.process("b", new ByteArrayInputStream("<MetaData />".getBytes()));
        p.prepare();
View Full Code Here


    /** Go through a simple session, containing two empty configurations. */
    public void testSimpleInstallAndUninstallSession() throws Throwable {
        AutoConfResourceProcessor p = new AutoConfResourceProcessor();
        Utils.configureObject(p, LogService.class);
        Utils.configureObject(p, DependencyManager.class, new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class)) {
          public void remove(Component service) {
          }
        });
        Logger logger = new Logger();
        Utils.configureObject(p, LogService.class, logger);
        File tempDir = File.createTempFile("persistence", "dir");
        tempDir.delete();
        tempDir.mkdirs();
       
        System.out.println("Temporary dir: " + tempDir);
       
        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
        Session s = new Session();
        p.begin(s);
        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
            public DependencyManager getDependencyManager() {
                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
            }
        }));
        p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
        p.prepare();
        p.commit();
View Full Code Here

    /** Go through a simple session, containing two empty configurations. */
    public void testBasicConfigurationSession() throws Throwable {
        AutoConfResourceProcessor p = new AutoConfResourceProcessor();
        Logger logger = new Logger();
        Utils.configureObject(p, LogService.class, logger);
        Utils.configureObject(p, DependencyManager.class, new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class)) {
          public void remove(Component service) {
          }
        });
        File tempDir = File.createTempFile("persistence", "dir");
        tempDir.delete();
        tempDir.mkdirs();
       
        System.out.println("Temporary dir: " + tempDir);
       
        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
        Session s = new Session();
        p.begin(s);
        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
            public DependencyManager getDependencyManager() {
                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
            }
        }));
        String config =
            "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0'>\n" +
            "  <OCD name='ocd' id='ocd'>\n" +
View Full Code Here

                    }
                });
            }
        });
    Utils.configureObject(p, BundleContext.class, mockBC);
        Utils.configureObject(p, DependencyManager.class, new DependencyManager(mockBC) {
          public void remove(Component service) {
          }
        });
        File tempDir = File.createTempFile("persistence", "dir");
        tempDir.delete();
        tempDir.mkdirs();
       
        System.out.println("Temporary dir: " + tempDir);
       
        Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(tempDir));
        Session s = new Session();
        p.begin(s);
        Utils.configureObject(p, Component.class, Utils.createMockObjectAdapter(Component.class, new Object() {
            public DependencyManager getDependencyManager() {
                return new DependencyManager((BundleContext) Utils.createNullObject(BundleContext.class));
            }
        }));
        String config =
            "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0' filter='(id=42)'>\n" +
            "  <OCD name='ocd' id='ocd'>\n" +
View Full Code Here

        m_bundleContext = mock(BundleContext.class);
        Bundle bundle = mock(Bundle.class);
        when(m_bundleContext.getBundle()).thenReturn(bundle);
        System.setOut(new PrintStream(outContent));
        System.setErr(new PrintStream(errContent));
        dm = new DependencyManager(m_bundleContext);
        dme = new DMCommand(m_bundleContext);
        DependencyManager.getDependencyManagers().add(dm);
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    @Test
    public void testComponentThatDependsOnAOtheComponentShouldRegisterAsFailure() {
        setupEmptyBundles();
        DependencyManager dm = new DependencyManager(m_bundleContext);
        DependencyManager.getDependencyManagers().add(dm);
       
        Component component = dm.createComponent()
            .setImplementation(Object.class)
            .setInterface(Object.class.getName(), null)
            .add(dm.createServiceDependency().setService(Math.class).setRequired(true));
        dm.add(component);
       
        dme.wtf();
        String output = outContent.toString();
        assertTrue(output.contains("1 missing"));
        assertTrue(output.contains("java.lang.Math"));
       
        // remove the mess
        dm.remove(component);
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    @Test
    public void testComponentThatHaveCycliclyDependencyOnAOtheComponentShouldRegisterAsFailure() {
        setupEmptyBundles();
        DependencyManager dm = new DependencyManager(m_bundleContext);
        DependencyManager.getDependencyManagers().add(dm);
       
        Component component1 = dm.createComponent()
            .setImplementation(Cipher.class)
            .setInterface(Cipher.class.getName(), null)
            .add(dm.createServiceDependency().setService(Math.class).setRequired(true));
        dm.add(component1);
       
        Component component2 = dm.createComponent()
            .setImplementation(Math.class)
            .setInterface(Math.class.getName(), null)
            .add(dm.createServiceDependency().setService(Cipher.class).setRequired(true));
        dm.add(component2);
       
        dme.wtf();
        String output = outContent.toString();
        assertTrue(output.contains("Circular dependency found:"));
        assertTrue(output.contains("-> java.lang.Math  -> javax.crypto.Cipher  -> java.lang.Math"));
       
        // remove the mess
        dm.remove(component1);
        dm.remove(component2);
    }
View Full Code Here

     * Checks that a ServiceDependency propagates the dependency service properties to the provided service properties,
     * using a callback method.
     */
    @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

@RunWith(PaxExam.class)
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

@RunWith(PaxExam.class)
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

TOP

Related Classes of org.apache.felix.dm.DependencyManager

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.