Search in sources :

Example 1 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomContentHandlerTest method testCustomContentInstallationException.

@Test
public void testCustomContentInstallationException() throws Exception {
    for (Bundle b : bundleContext.getBundles()) {
        if ("org.apache.aries.subsystem.itests.customcontent.bundleB".equals(b.getSymbolicName())) {
            fail("Precondition");
        }
    }
    SausagesContentHandler handler = new SausagesContentHandler(true, "install");
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
    ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
    assertEquals("Precondition", 0, handler.calls.size());
    try {
        installSubsystemFromFile("customContent1.esa");
    } catch (Exception ex) {
    // ignore
    }
    try {
        for (Bundle b : bundleContext.getBundles()) {
            if ("org.apache.aries.subsystem.itests.customcontent.bundleB".equals(b.getSymbolicName())) {
                fail("Should not have installed the bundle");
            }
        }
    } finally {
        reg.unregister();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ContentHandler(org.apache.aries.subsystem.ContentHandler) Test(org.junit.Test)

Example 2 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomResourceInstaller method install.

@Override
public Resource install() throws Exception {
    try {
        ContentHandler handler = subsystem.getBundleContext().getService(handlerRef);
        if (handler != null) {
            InputStream is = ((RepositoryContent) resource).getContent();
            handler.install(is, ResourceHelper.getSymbolicNameAttribute(resource), type, subsystem, coordination);
            addReference(resource);
            return resource;
        } else {
            throw new Exception("Custom content handler not found: " + handlerRef);
        }
    } finally {
        subsystem.getBundleContext().ungetService(handlerRef);
    }
}
Also used : InputStream(java.io.InputStream) RepositoryContent(org.osgi.service.repository.RepositoryContent) ContentHandler(org.apache.aries.subsystem.ContentHandler)

Example 3 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomContentHandlerTest method testCustomContentStartFailCoordination.

@Test
@Ignore("This test currently doesn't pass, the bundle moves to the active state, while it shouldn't")
public void testCustomContentStartFailCoordination() throws Exception {
    for (Bundle b : bundleContext.getBundles()) {
        if ("org.apache.aries.subsystem.itests.customcontent.bundleD".equals(b.getSymbolicName())) {
            fail("Precondition");
        }
    }
    SausagesContentHandler handler = new SausagesContentHandler(false, "start");
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
    ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
    assertEquals("Precondition", 0, handler.calls.size());
    Subsystem subsystem = installSubsystemFromFile("customContent3.esa");
    try {
        assertEquals(Arrays.asList("install:customContent4 sausages = 4"), handler.calls);
        try {
            Bundle theBundle = null;
            for (Bundle b : bundleContext.getBundles()) {
                if ("org.apache.aries.subsystem.itests.customcontent.bundleD".equals(b.getSymbolicName())) {
                    assertEquals(Bundle.INSTALLED, b.getState());
                    theBundle = b;
                }
            }
            assertNotNull(theBundle);
            try {
                subsystem.start();
            } catch (Exception ex) {
            // good
            }
            assertEquals("The coordination failued during start, so the bundle should not be started", Bundle.INSTALLED, theBundle.getState());
        } finally {
            subsystem.uninstall();
        }
    } finally {
        reg.unregister();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Subsystem(org.osgi.service.subsystem.Subsystem) ContentHandler(org.apache.aries.subsystem.ContentHandler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomContentHandlerTest method testCustomContentInstallationSecondTime.

@Test
@Ignore("This test exposes a problem that needs to be fixed, namely that the previous test leaves stuff behind and that " + "customContent1.esa cannot be installed again. Currently ignored until someone finds the time to fix it.")
public void testCustomContentInstallationSecondTime() throws Exception {
    for (Bundle b : bundleContext.getBundles()) {
        if ("org.apache.aries.subsystem.itests.customcontent.bundleB".equals(b.getSymbolicName())) {
            fail("Precondition");
        }
    }
    SausagesContentHandler handler = new SausagesContentHandler();
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
    ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
    try {
        Subsystem subsystem = installSubsystemFromFile("customContent1.esa");
        subsystem.uninstall();
    } finally {
        reg.unregister();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Subsystem(org.osgi.service.subsystem.Subsystem) ContentHandler(org.apache.aries.subsystem.ContentHandler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with ContentHandler

use of org.apache.aries.subsystem.ContentHandler in project aries by apache.

the class CustomContentHandlerTest method testCustomContentHandler.

@Test
public void testCustomContentHandler() throws Exception {
    for (Bundle b : bundleContext.getBundles()) {
        if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(b.getSymbolicName())) {
            fail("Precondition");
        }
    }
    SausagesContentHandler handler = new SausagesContentHandler();
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
    ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
    try {
        assertEquals("Precondition", 0, handler.calls.size());
        Subsystem subsystem = installSubsystemFromFile("customContent.esa");
        try {
            assertEquals(Arrays.asList("install:customContent1 sausages = 1"), handler.calls);
            Collection<Resource> constituents = subsystem.getConstituents();
            assertEquals("The custom content should not show up as a subsystem constituent", 1, constituents.size());
            boolean foundBundle = false;
            for (Bundle b : bundleContext.getBundles()) {
                if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(b.getSymbolicName())) {
                    foundBundle = true;
                }
            }
            assertTrue(foundBundle);
            boolean foundBundleInConstituents = false;
            for (Resource c : constituents) {
                for (Capability idCap : c.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE)) {
                    Object name = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
                    if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(name))
                        foundBundleInConstituents = true;
                }
            }
            assertTrue(foundBundleInConstituents);
            handler.calls.clear();
            assertEquals(Subsystem.State.INSTALLED, subsystem.getState());
            subsystem.start();
            assertEquals(Arrays.asList("start:customContent1"), handler.calls);
            handler.calls.clear();
            assertEquals(Subsystem.State.ACTIVE, subsystem.getState());
            subsystem.stop();
            assertEquals(Arrays.asList("stop:customContent1"), handler.calls);
            assertEquals(Subsystem.State.RESOLVED, subsystem.getState());
        } finally {
            handler.calls.clear();
            subsystem.uninstall();
            assertEquals(Arrays.asList("uninstall:customContent1"), handler.calls);
            assertEquals(Subsystem.State.UNINSTALLED, subsystem.getState());
        }
    } finally {
        reg.unregister();
    }
}
Also used : Capability(org.osgi.resource.Capability) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) Resource(org.osgi.resource.Resource) ContentHandler(org.apache.aries.subsystem.ContentHandler) Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Aggregations

ContentHandler (org.apache.aries.subsystem.ContentHandler)7 Hashtable (java.util.Hashtable)6 Test (org.junit.Test)6 Bundle (org.osgi.framework.Bundle)6 Subsystem (org.osgi.service.subsystem.Subsystem)4 Ignore (org.junit.Ignore)3 InputStream (java.io.InputStream)1 Capability (org.osgi.resource.Capability)1 Resource (org.osgi.resource.Resource)1 RepositoryContent (org.osgi.service.repository.RepositoryContent)1