Search in sources :

Example 91 with Subsystem

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

the class ApplicationTest method testApplication1.

/*
	 * Subsystem application1 has content bundle tb1.jar.
	 * Bundle tb1.jar has an import package dependency on org.apache.aries.subsystem.itests.tb3.
	 */
@Test
public void testApplication1() throws Exception {
    Subsystem application1 = installSubsystemFromFile("application1.esa");
    try {
        assertSymbolicName("org.apache.aries.subsystem.application1", application1);
        assertVersion("0.0.0", application1);
        assertType(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, application1);
        assertChildren(0, application1);
        assertConstituents(2, application1);
        startSubsystem(application1);
        assertBundleState(Bundle.RESOLVED | Bundle.ACTIVE, "org.apache.aries.subsystem.itests.tb1", application1);
        assertBundleState(Bundle.RESOLVED | Bundle.ACTIVE, "org.apache.aries.subsystem.itests.tb3", getRootSubsystem());
    } finally {
        stopSubsystemSilently(application1);
        uninstallSubsystemSilently(application1);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 92 with Subsystem

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

the class ApplicationTest method testRequireBundle.

@Test
public void testRequireBundle() throws Exception {
    File file = new File(BUNDLE_B);
    // The following input stream is closed by the bundle context.
    Bundle b = getRootSubsystem().getBundleContext().installBundle(file.toURI().toString(), new FileInputStream(file));
    try {
        Subsystem application = installSubsystemFromFile(APPLICATION_B);
        try {
            startSubsystem(application);
        } finally {
            stopSubsystemSilently(application);
            uninstallSubsystemSilently(application);
        }
    } finally {
        uninstallSilently(b);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Subsystem(org.osgi.service.subsystem.Subsystem) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 93 with Subsystem

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

the class AutostartTest method testStartCompositeWithUnresolvedDependency.

@Test
public /* Start a composite with a dependency on an installed, but unresolved subsystem.
	 * The unresolved dependency should be auto-resolved and started (test fix to
	 *  bug ARIES-1348).
	 *
	 * composite b imports package exported by a bundle in composite.a.  
	 *  - install composite a
	 *  - install composite b
	 *  - start composite b
	 */
void testStartCompositeWithUnresolvedDependency() throws Exception {
    Subsystem compositeA = installSubsystemFromFile(COMPOSITE_A);
    Subsystem compositeB = installSubsystemFromFile(COMPOSITE_B);
    try {
        startSubsystem(compositeB);
        // A should be automatically resolved and started.
        assertState(Subsystem.State.ACTIVE, compositeA);
    } finally {
        stopSubsystemSilently(compositeB);
        stopSubsystemSilently(compositeA);
        uninstallSubsystemSilently(compositeB);
        uninstallSubsystemSilently(compositeA);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 94 with Subsystem

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

the class AutostartTest method testAutostartScoped.

@Test
public void testAutostartScoped() throws Exception {
    Subsystem subsystem = null;
    try {
        subsystem = installSubsystemFromFile(APPLICATION_A);
        restartSubsystemsImplBundle();
        subsystem = findSubsystemService(subsystem.getSubsystemId());
        assertState(Subsystem.State.INSTALLED, subsystem);
        assertBundleState(Bundle.INSTALLED | Bundle.RESOLVED, BUNDLE_A, subsystem);
        startSubsystem(subsystem);
        restartSubsystemsImplBundle();
        subsystem = findSubsystemService(subsystem.getSubsystemId());
        assertState(Subsystem.State.ACTIVE, subsystem);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, subsystem);
        stopSubsystem(subsystem);
        restartSubsystemsImplBundle();
        subsystem = findSubsystemService(subsystem.getSubsystemId());
        assertState(Subsystem.State.RESOLVED, subsystem);
        assertBundleState(Bundle.RESOLVED, BUNDLE_A, subsystem);
    } finally {
        stopAndUninstallSubsystemSilently(subsystem);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) Test(org.junit.Test)

Example 95 with Subsystem

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

the class AutostartTest method testAutostartChildAsContentScoped.

@Test
public void testAutostartChildAsContentScoped() throws Exception {
    Subsystem applicationB = null;
    try {
        applicationB = installSubsystemFromFile(APPLICATION_B);
        Subsystem applicationA = applicationB.getChildren().iterator().next();
        restartSubsystemsImplBundle();
        applicationB = findSubsystemService(applicationB.getSubsystemId());
        applicationA = findSubsystemService(applicationA.getSubsystemId());
        assertState(Subsystem.State.INSTALLED, applicationB);
        assertBundleState(Bundle.INSTALLED | Bundle.RESOLVED, BUNDLE_A, applicationB);
        assertState(Subsystem.State.INSTALLED, applicationA);
        assertBundleState(Bundle.INSTALLED | Bundle.RESOLVED, BUNDLE_A, applicationA);
        startSubsystem(applicationB);
        restartSubsystemsImplBundle();
        applicationB = findSubsystemService(applicationB.getSubsystemId());
        applicationA = findSubsystemService(applicationA.getSubsystemId());
        ;
        assertState(Subsystem.State.ACTIVE, applicationB);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, applicationB);
        assertState(Subsystem.State.ACTIVE, applicationA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, applicationA);
        stopSubsystem(applicationA);
        restartSubsystemsImplBundle();
        applicationB = findSubsystemService(applicationB.getSubsystemId());
        applicationA = findSubsystemService(applicationA.getSubsystemId());
        ;
        assertState(Subsystem.State.ACTIVE, applicationB);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, applicationB);
        assertState(Subsystem.State.ACTIVE, applicationA);
        assertBundleState(Bundle.ACTIVE, BUNDLE_A, applicationA);
        stopSubsystem(applicationB);
        restartSubsystemsImplBundle();
        applicationB = findSubsystemService(applicationB.getSubsystemId());
        applicationA = findSubsystemService(applicationA.getSubsystemId());
        ;
        assertState(Subsystem.State.RESOLVED, applicationB);
        assertBundleState(Bundle.RESOLVED, BUNDLE_A, applicationB);
        assertState(Subsystem.State.RESOLVED, applicationA);
        assertBundleState(Bundle.RESOLVED, BUNDLE_A, applicationA);
    } finally {
        stopAndUninstallSubsystemSilently(applicationB);
    }
}
Also used : 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