Search in sources :

Example 41 with SubsystemException

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

the class AriesSubsystemTest method testAddRequirements.

/*
	 * Test the AriesSubsystem.addRequirements(Collection<Requirement>) method.
	 * 
	 * There are several things to consider for this test.
	 * 
	 * (1) Installing a child subsystem before the requirement has been added
	 *     should fail.
	 * (2) Installing a child subsystem after the requirement has been added
	 *     should succeed.
	 * (3) The newly created region should contain all of the bundles from the
	 *     old one.
	 * (4) The connections between the subsystem with the added requirement and
	 *     its parents should be reestablished.
	 * (5) The connections between the subsystem with the added requirement and
	 *     its children should be reestablished.
	 */
@Test
public void testAddRequirements() throws Exception {
    AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
    try {
        startSubsystem(compositeA);
        assertCompositeABefore(compositeA);
        // Test that the installation of applicationA fails.
        try {
            installSubsystemFromFile(compositeA, APPLICATION_A);
            fail("Subsystem should not have installed due to unresolved org.osgi.framework package requirement");
        } catch (SubsystemException e) {
        // Okay.
        }
        // Add the org.osgi.framework package requirement.
        Requirement requirement = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=org.osgi.framework)").resource(EasyMock.createMock(Resource.class)).build();
        compositeA.addRequirements(Collections.singleton(requirement));
        // Test that the bundles were copied over to the newly created region.
        assertCompositeABefore(compositeA);
        // Test that the parent connections were reestablished.
        assertRefreshAndResolve(Collections.singletonList(getConstituentAsBundle(compositeA, BUNDLE_B, null, null)));
        // Test that the child connections were reestablished.
        assertRefreshAndResolve(Collections.singletonList(getConstituentAsBundle(getConstituentAsSubsystem(compositeA, APPLICATION_B, null, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION), BUNDLE_B, null, null)));
        // Test that the installation of applicationA succeeds.
        AriesSubsystem applicationA;
        try {
            applicationA = (AriesSubsystem) installSubsystemFromFile(compositeA, APPLICATION_A);
            startSubsystem(applicationA);
        } catch (SubsystemException e) {
            fail("Subsystem should have installed and started");
        }
        assertCompositeAAfter(compositeA);
    } finally {
        stopAndUninstallSubsystemSilently(compositeA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) BasicRequirement(org.apache.aries.subsystem.core.internal.BasicRequirement) SubsystemException(org.osgi.service.subsystem.SubsystemException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Example 42 with SubsystemException

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

the class ServiceDependencyTest method testImportServiceDependencySatisfiedByChild.

//@Test
public void testImportServiceDependencySatisfiedByChild() throws Exception {
    try {
        Subsystem subsystem = installSubsystemFromFile(APPLICATION_D);
        try {
            assertNull("Generated application Subsystem-ImportService header when dependency satisfied by child", subsystem.getSubsystemHeaders(null).get(SubsystemConstants.SUBSYSTEM_IMPORTSERVICE));
            assertSubsystemExportServiceHeader(subsystem.getChildren().iterator().next(), "bundle.b;filter:=\"(&(active=true)(mode=shared))\"");
        } finally {
            uninstallSubsystemSilently(subsystem);
        }
    } catch (SubsystemException e) {
        e.printStackTrace();
        fail("Installation must succeed if missing service dependency is satisfied");
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException)

Example 43 with SubsystemException

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

the class ServiceDependencyTest method testMissingImportServiceDependencyMandatory.

@Test
public void testMissingImportServiceDependencyMandatory() throws Exception {
    try {
        Subsystem subsystem = installSubsystemFromFile(APPLICATION_A);
        uninstallSubsystemSilently(subsystem);
        fail("Installation must fail due to missing service dependency");
    } catch (SubsystemException e) {
    // Okay.
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) Test(org.junit.Test)

Example 44 with SubsystemException

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

the class HelloWorldTest method testHelloFromIDirectory.

@Test
public void testHelloFromIDirectory() throws Exception {
    // services are registered, which should be the case on entry to this test.
    try {
        installSubsystem(getRootSubsystem(), TestIDirectoryFinder.HELLO_ID_STRING, null, (Boolean[]) null);
        fail("installed esa application from idir without an idirfinder service, shouldn't be possible.");
    } catch (SubsystemException se) {
    // expected exception
    }
    // The root subsystem already exists and has a service tracker for
    // IDirectoryFinder services, so it will be notified on service registration. 
    Dictionary<String, String> properties = new Hashtable<String, String>();
    properties.put(IDirectoryFinder.IDIR_FINDERID_KEY, TestIDirectoryFinder.IDIR_FINDERID_VALUE);
    ServiceRegistration serviceRegistration = bundleContext.registerService(IDirectoryFinder.class, new TestIDirectoryFinder(), properties);
    // Call the SubsystemTest.installSubsystem method that does not create a URL
    // and stream from the location, as we just need the location string passed 
    // through to the installing root subsystem.
    Subsystem subsystem = installSubsystem(getRootSubsystem(), TestIDirectoryFinder.HELLO_ID_STRING, null, (Boolean[]) null);
    try {
        checkHelloSubsystem(subsystem);
    } finally {
        uninstallSubsystemSilently(subsystem);
        if (serviceRegistration != null)
            serviceRegistration.unregister();
    }
}
Also used : Hashtable(java.util.Hashtable) SubsystemException(org.osgi.service.subsystem.SubsystemException) Subsystem(org.osgi.service.subsystem.Subsystem) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 45 with SubsystemException

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

the class ProvisionPolicyTest method testFailInstallFeatureAcceptDependencies.

@Test
public void testFailInstallFeatureAcceptDependencies() throws Exception {
    Subsystem subsystem = null;
    try {
        subsystem = installSubsystemFromFile(FEATURE_A);
        fail("Feature with provision-policy:=acceptDependencies did not fail installation");
    } catch (SubsystemException e) {
        // TODO Brittle...
        assertTrue(e.getMessage().contains("Feature subsystems may not declare a provision-policy of acceptDependencies"));
    } finally {
        uninstallSubsystemSilently(subsystem);
    }
}
Also used : Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) Test(org.junit.Test)

Aggregations

SubsystemException (org.osgi.service.subsystem.SubsystemException)61 Subsystem (org.osgi.service.subsystem.Subsystem)39 Test (org.junit.Test)32 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)23 AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)19 SubsystemArchiveBuilder (org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder)15 Bundle (org.osgi.framework.Bundle)11 BundleArchiveBuilder (org.apache.aries.subsystem.itests.util.BundleArchiveBuilder)7 Resource (org.osgi.resource.Resource)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 SubsystemContentHeader (org.apache.aries.subsystem.core.archive.SubsystemContentHeader)5 BundleException (org.osgi.framework.BundleException)5 Requirement (org.osgi.resource.Requirement)5 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3 BundleRevision (org.osgi.framework.wiring.BundleRevision)3 Repository (org.osgi.service.repository.Repository)3 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 DeploymentManifest (org.apache.aries.subsystem.core.archive.DeploymentManifest)2