Search in sources :

Example 6 with AriesSubsystem

use of org.apache.aries.subsystem.AriesSubsystem 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 7 with AriesSubsystem

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

the class AriesSubsystemTest method testServiceRegistrations.

@Test
public void testServiceRegistrations() {
    Subsystem root1 = null;
    try {
        root1 = getRootSubsystem();
    } catch (Exception e) {
        fail(Subsystem.class.getName() + " service not registered");
    }
    AriesSubsystem root2 = null;
    try {
        root2 = getRootAriesSubsystem();
    } catch (Exception e) {
        fail(AriesSubsystem.class.getName() + " service not registered");
    }
    assertSame("Services should be the same instance", root1, root2);
}
Also used : AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Aggregations

AriesSubsystem (org.apache.aries.subsystem.AriesSubsystem)7 Test (org.junit.Test)6 SubsystemException (org.osgi.service.subsystem.SubsystemException)5 Requirement (org.osgi.resource.Requirement)4 IOException (java.io.IOException)3 BasicRequirement (org.apache.aries.subsystem.core.internal.BasicRequirement)3 IDirectory (org.apache.aries.util.filesystem.IDirectory)2 Subsystem (org.osgi.service.subsystem.Subsystem)2 File (java.io.File)1 SubsystemTest (org.apache.aries.subsystem.itests.SubsystemTest)1 TestRequirement (org.apache.aries.subsystem.itests.util.TestRequirement)1 ICloseableDirectory (org.apache.aries.util.filesystem.ICloseableDirectory)1 Region (org.eclipse.equinox.region.Region)1 Resource (org.osgi.resource.Resource)1