Search in sources :

Example 1 with AriesSubsystem

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

the class Aries1429Test method testMissingParentChildEdgeNotTolerated.

@Test
public void testMissingParentChildEdgeNotTolerated() throws Exception {
    Subsystem applicationA = installSubsystemFromFile(APPLICATION_A);
    try {
        removeConnectionWithParent(applicationA);
        try {
            ((AriesSubsystem) applicationA).addRequirements(Collections.singletonList((Requirement) new TestRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).attribute(PackageNamespace.PACKAGE_NAMESPACE, "org.osgi.framework").build()));
            fail("No exception received");
        } catch (SubsystemException e) {
            Throwable cause = e.getCause();
            assertNotNull("Wrong cause", cause);
            assertEquals("Wrong cause", IllegalStateException.class, cause.getClass());
        }
    } finally {
        uninstallSubsystemSilently(applicationA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) TestRequirement(org.apache.aries.subsystem.itests.util.TestRequirement) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Subsystem(org.osgi.service.subsystem.Subsystem) SubsystemException(org.osgi.service.subsystem.SubsystemException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) SubsystemTest(org.apache.aries.subsystem.itests.SubsystemTest) Test(org.junit.Test)

Example 2 with AriesSubsystem

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

the class AriesSubsystemTest method testInstallIDirectory.

@Test
public void testInstallIDirectory() {
    File file = new File(COMPOSITE_A);
    IDirectory directory = FileSystem.getFSRoot(file);
    try {
        AriesSubsystem compositeA = getRootAriesSubsystem().install(COMPOSITE_A, directory);
        uninstallSubsystemSilently(compositeA);
    } catch (Exception e) {
        fail("Installation from IDirectory should have succeeded");
    }
}
Also used : IDirectory(org.apache.aries.util.filesystem.IDirectory) File(java.io.File) SubsystemException(org.osgi.service.subsystem.SubsystemException) IOException(java.io.IOException) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Example 3 with AriesSubsystem

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

the class AriesSubsystemTest method testAddRequirementWithVisibleBundleNamespace.

/*
	 * Aries Subsystems uses Equinox Region Digraph as its isolation engine.
	 * Digraph has a "special" namespace value that tells the region to allow
	 * everything a bundle offers. This test ensures that a correctly formatted
	 * requirement in that namespace works as expected.
	 */
@Test
public void testAddRequirementWithVisibleBundleNamespace() throws Exception {
    Requirement requirement = new BasicRequirement.Builder().namespace(RegionFilter.VISIBLE_BUNDLE_NAMESPACE).directive(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(id=0)").resource(EasyMock.createMock(Resource.class)).build();
    AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
    try {
        startSubsystem(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 requirement with the region digraph specific namespace.
        compositeA.addRequirements(Collections.singleton(requirement));
        // Test that the installation and startup 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 4 with AriesSubsystem

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

the class AriesSubsystemTest method testAddRequirementsKeepsEdgesOtherThanParentChild.

/*
	 * The region copy process when adding additional requirements should
	 * keep all edges, not just the ones running between parent and child. This
	 * is of particular concern with regard to the connections all subsystem
	 * regions have with the root region to allow the subsystem services
	 * through. However, it may also be of concern if the region digraph is
	 * modified outside of the subsystems API.
	 */
@Test
public void testAddRequirementsKeepsEdgesOtherThanParentChild() throws Exception {
    AriesSubsystem compositeA = (AriesSubsystem) installSubsystemFromFile(COMPOSITE_A);
    try {
        AriesSubsystem applicationB = (AriesSubsystem) getConstituentAsSubsystem(compositeA, APPLICATION_B, null, SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION);
        Region bRegion = getRegion(applicationB);
        // One edge to parent for import package. One edge to root for subsystem
        // service.
        assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
        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();
        applicationB.addRequirements(Collections.singleton(requirement));
        bRegion = getRegion(applicationB);
        // Still one edge to parent for import package. One edge to root for
        // subsystem service.
        assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
        Region rootRegion = getRegion(getRootSubsystem());
        // The root region won't be the tail region for any connection unless
        // manually added.
        assertEquals("Wrong number of edges", 0, rootRegion.getEdges().size());
        // Manually add a connection from root to application B.
        rootRegion.connectRegion(bRegion, rootRegion.getRegionDigraph().createRegionFilterBuilder().allow("com.foo", "(bar=b)").build());
        // The root region should now have an edge.
        assertEquals("Wrong number of edges", 1, rootRegion.getEdges().size());
        // Add another requirement to force a copy.
        requirement = new BasicRequirement.Builder().namespace(PackageNamespace.PACKAGE_NAMESPACE).directive(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE, "(osgi.wiring.package=org.osgi.framework.wiring)").resource(EasyMock.createMock(Resource.class)).build();
        applicationB.addRequirements(Collections.singleton(requirement));
        rootRegion = getRegion(getRootSubsystem());
        // The root region should still have its edge.
        assertEquals("Wrong number of edges", 1, rootRegion.getEdges().size());
        bRegion = getRegion(applicationB);
        // Still one edge to parent for import package. One edge to root for
        // subsystem service.
        assertEquals("Wrong number of edges", 2, bRegion.getEdges().size());
    } finally {
        uninstallSubsystemSilently(compositeA);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) BasicRequirement(org.apache.aries.subsystem.core.internal.BasicRequirement) BasicRequirement(org.apache.aries.subsystem.core.internal.BasicRequirement) Resource(org.osgi.resource.Resource) Region(org.eclipse.equinox.region.Region) AriesSubsystem(org.apache.aries.subsystem.AriesSubsystem) Test(org.junit.Test)

Example 5 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)

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