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);
}
}
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");
}
}
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.
}
}
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();
}
}
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);
}
}
Aggregations