Search in sources :

Example 61 with Subsystem

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

the class DynamicImportTest method verifyThatDynamicImportNeedsHandling.

/*
	 * Install an .esa containing a bundle with a BundleActivator, and a 
	 * DynamicImport-Package on org.apache.aries.subsystem.itests.hello.api.
	 * This app should fail to start because we've not yet intervened to permit 
	 * this dynamic package wiring requirement from being met. 
	 */
@Test
public void verifyThatDynamicImportNeedsHandling() throws Exception {
    Subsystem subsystem = installSubsystemFromFile("dynamicImport.esa");
    try {
        startSubsystem(subsystem);
        Bundle[] bundles = subsystem.getBundleContext().getBundles();
        for (Bundle b : bundles) {
            System.out.println(b.getSymbolicName() + " -> " + b.getState());
        }
        fail("dynamicImport.esa started when we didn't expect it to");
    } catch (SubsystemException sx) {
        Throwable cause = sx.getCause();
        assertTrue("BundleException expected", cause instanceof BundleException);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) BundleException(org.osgi.framework.BundleException) Test(org.junit.Test)

Example 62 with Subsystem

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

the class InstallTest method testLocationAsDirectoryUrl.

/*
     * Install a subsystem using a location string and a null input stream. The
     * location string is a file URL pointing to a subsystem directory 
     * containing nested subsystem and bundle directories.
     */
@Test
public void testLocationAsDirectoryUrl() throws Exception {
    File file = new File("compositeDir");
    try {
        Subsystem subsystem = installSubsystem(getRootSubsystem(), file.toURI().toString(), null, (Boolean[]) null);
        try {
            assertSymbolicName("org.apache.aries.subsystem.itests.composite.dir", subsystem);
            assertConstituents(3, subsystem);
            assertConstituent(subsystem, "org.apache.aries.subsystem.itests.composite.dir.bundle.a");
            Bundle b = getConstituentAsBundle(subsystem, "org.apache.aries.subsystem.itests.composite.dir.bundle.a", null, null);
            assertLocation(subsystem.getLocation() + "!/" + "a.jar", b.getLocation());
            assertClassLoadable("a.A", b);
            assertChildren(1, subsystem);
            Subsystem child = subsystem.getChildren().iterator().next();
            assertSymbolicName("org.apache.aries.subsystem.itests.application.dir", child);
            assertConstituent(child, "org.apache.aries.subsystem.itests.composite.dir.bundle.b");
            b = getConstituentAsBundle(child, "org.apache.aries.subsystem.itests.composite.dir.bundle.b", null, null);
            assertLocation(child.getLocation() + "!/" + "b.jar", b.getLocation());
            assertClassLoadable("b.B", b);
            assertChildren(1, child);
            child = child.getChildren().iterator().next();
            assertSymbolicName("org.apache.aries.subsystem.itests.feature.dir", child);
            assertConstituent(subsystem, "org.apache.aries.subsystem.itests.composite.dir.bundle.a");
            b = getConstituentAsBundle(child, "org.apache.aries.subsystem.itests.composite.dir.bundle.a", null, null);
            assertLocation(child.getLocation() + "!/" + "a.jar", b.getLocation());
            assertClassLoadable("a.A", b);
            assertConstituent(child, "org.apache.aries.subsystem.itests.composite.dir.bundle.b", Version.parseVersion("1"));
            b = getConstituentAsBundle(child, "org.apache.aries.subsystem.itests.composite.dir.bundle.b", Version.parseVersion("1"), null);
            assertLocation(child.getLocation() + "!/" + "b.jar", b.getLocation());
            assertClassLoadable("b.B", b);
        } finally {
            uninstallSubsystemSilently(subsystem);
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("Subsystem installation using directory URL as location failed");
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) File(java.io.File) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 63 with Subsystem

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

the class InstallTest method testLocationAsEmptyString.

@Test
public void testLocationAsEmptyString() throws Exception {
    try {
        Subsystem a = installSubsystemFromFile(getRootSubsystem(), new File(APPLICATION_A), "");
        try {
            BasicSubsystem basic = (BasicSubsystem) a;
            String location = basic.getLocation();
            assertEquals("Location value should be an empty string", "", location);
        } finally {
            uninstallSubsystemSilently(a);
        }
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Subsystem should have installed");
    }
}
Also used : BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) File(java.io.File) Test(org.junit.Test)

Example 64 with Subsystem

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

the class InstallTest method testGeneratedSymbolicNameWithoutManifest.

@Test
public void testGeneratedSymbolicNameWithoutManifest() throws Exception {
    String expected = "org.apache.aries.subsystem.1";
    Subsystem a = installSubsystemFromFile(APPLICATION_A);
    try {
        assertSymbolicName(expected, a);
        assertSymbolicName(expected, a.getSubsystemHeaders(null).get(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME));
    } finally {
        uninstallSubsystemSilently(a);
    }
}
Also used : BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 65 with Subsystem

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

the class InstallTest method testSupportBundleResourcesNotEndingWithJar.

@Test
public void testSupportBundleResourcesNotEndingWithJar() throws Exception {
    Subsystem featureA = installSubsystemFromFile(FEATURE_A);
    try {
        assertConstituents(1, featureA);
        assertConstituent(featureA, BUNDLE_B);
    } finally {
        uninstallSubsystemSilently(featureA);
    }
}
Also used : BasicSubsystem(org.apache.aries.subsystem.core.internal.BasicSubsystem) 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