Search in sources :

Example 86 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class ResolutionTest method testMissingBundleRequiredExecutionEnvironment.

/*
	 * BREE headers must be converted into osgi.ee requirements.
	 * 
	 * The subsystem should fail to resolve and install if the required
	 * execution environment is not present.
	 */
@Test
public void testMissingBundleRequiredExecutionEnvironment() throws Exception {
    Subsystem applicationB = null;
    try {
        applicationB = installSubsystemFromFile(APPLICATION_B);
        fail("Missing BREE should result in installation failure");
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue("Installation failure should be due to resolution error", e.getCause() instanceof ResolutionException);
    } finally {
        uninstallSubsystemSilently(applicationB);
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) ResolutionException(org.osgi.service.resolver.ResolutionException) Test(org.junit.Test)

Example 87 with Subsystem

use of org.osgi.service.subsystem.Subsystem in project aries by apache.

the class CompositeTest method testExportPackage.

@Test
public void testExportPackage() throws Exception {
    Subsystem composite = installSubsystemFromFile(COMPOSITE_A);
    try {
        startSubsystem(composite);
        Bundle bundleA = installBundleFromFile(BUNDLE_A, composite);
        try {
            Bundle bundleC = installBundleFromFile(BUNDLE_C);
            try {
                startBundle(bundleC);
            } finally {
                bundleC.uninstall();
            }
        } finally {
            bundleA.uninstall();
        }
    } finally {
        stopSubsystemSilently(composite);
        uninstallSubsystemSilently(composite);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 88 with Subsystem

use of org.osgi.service.subsystem.Subsystem 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 89 with Subsystem

use of org.osgi.service.subsystem.Subsystem 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 90 with Subsystem

use of org.osgi.service.subsystem.Subsystem 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

Subsystem (org.osgi.service.subsystem.Subsystem)202 Test (org.junit.Test)151 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)78 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)52 SubsystemException (org.osgi.service.subsystem.SubsystemException)50 Bundle (org.osgi.framework.Bundle)48 SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)31 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)22 BasicSubsystem (org.apache.aries.subsystem.core.internal.BasicSubsystem)19 IOException (java.io.IOException)13 Hashtable (java.util.Hashtable)9 ServiceReference (org.osgi.framework.ServiceReference)8 File (java.io.File)7 BundleContext (org.osgi.framework.BundleContext)7 ArrayList (java.util.ArrayList)6 TestCapability (org.apache.aries.subsystem.itests.util.TestCapability)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FileInputStream (java.io.FileInputStream)5 Callable (java.util.concurrent.Callable)5 BundleException (org.osgi.framework.BundleException)5