use of org.osgi.service.subsystem.Subsystem in project aries by apache.
the class ResolutionTest method testMissingBundleRequiredExecutionEnvironment.
/*
* BREE headers must be converted into osgi.ee requirements.
*
* The subsystem should fail to resolve and install if the required
* execution environment is not present.
*/
@Test
public void testMissingBundleRequiredExecutionEnvironment() throws Exception {
Subsystem applicationB = null;
try {
applicationB = installSubsystemFromFile(APPLICATION_B);
fail("Missing BREE should result in installation failure");
} catch (Exception e) {
e.printStackTrace();
assertTrue("Installation failure should be due to resolution error", e.getCause() instanceof ResolutionException);
} finally {
uninstallSubsystemSilently(applicationB);
}
}
use of org.osgi.service.subsystem.Subsystem in project aries by apache.
the class CompositeTest method testExportPackage.
@Test
public void testExportPackage() throws Exception {
Subsystem composite = installSubsystemFromFile(COMPOSITE_A);
try {
startSubsystem(composite);
Bundle bundleA = installBundleFromFile(BUNDLE_A, composite);
try {
Bundle bundleC = installBundleFromFile(BUNDLE_C);
try {
startBundle(bundleC);
} finally {
bundleC.uninstall();
}
} finally {
bundleA.uninstall();
}
} finally {
stopSubsystemSilently(composite);
uninstallSubsystemSilently(composite);
}
}
use of org.osgi.service.subsystem.Subsystem in project aries by apache.
the class CustomContentHandlerTest method testCustomContentStartFailCoordination.
@Test
@Ignore("This test currently doesn't pass, the bundle moves to the active state, while it shouldn't")
public void testCustomContentStartFailCoordination() throws Exception {
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleD".equals(b.getSymbolicName())) {
fail("Precondition");
}
}
SausagesContentHandler handler = new SausagesContentHandler(false, "start");
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
assertEquals("Precondition", 0, handler.calls.size());
Subsystem subsystem = installSubsystemFromFile("customContent3.esa");
try {
assertEquals(Arrays.asList("install:customContent4 sausages = 4"), handler.calls);
try {
Bundle theBundle = null;
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleD".equals(b.getSymbolicName())) {
assertEquals(Bundle.INSTALLED, b.getState());
theBundle = b;
}
}
assertNotNull(theBundle);
try {
subsystem.start();
} catch (Exception ex) {
// good
}
assertEquals("The coordination failued during start, so the bundle should not be started", Bundle.INSTALLED, theBundle.getState());
} finally {
subsystem.uninstall();
}
} finally {
reg.unregister();
}
}
use of org.osgi.service.subsystem.Subsystem in project aries by apache.
the class CustomContentHandlerTest method testCustomContentInstallationSecondTime.
@Test
@Ignore("This test exposes a problem that needs to be fixed, namely that the previous test leaves stuff behind and that " + "customContent1.esa cannot be installed again. Currently ignored until someone finds the time to fix it.")
public void testCustomContentInstallationSecondTime() throws Exception {
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleB".equals(b.getSymbolicName())) {
fail("Precondition");
}
}
SausagesContentHandler handler = new SausagesContentHandler();
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
try {
Subsystem subsystem = installSubsystemFromFile("customContent1.esa");
subsystem.uninstall();
} finally {
reg.unregister();
}
}
use of org.osgi.service.subsystem.Subsystem in project aries by apache.
the class CustomContentHandlerTest method testCustomContentHandler.
@Test
public void testCustomContentHandler() throws Exception {
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(b.getSymbolicName())) {
fail("Precondition");
}
}
SausagesContentHandler handler = new SausagesContentHandler();
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(ContentHandler.CONTENT_TYPE_PROPERTY, "foo.sausages");
ServiceRegistration<ContentHandler> reg = bundleContext.registerService(ContentHandler.class, handler, props);
try {
assertEquals("Precondition", 0, handler.calls.size());
Subsystem subsystem = installSubsystemFromFile("customContent.esa");
try {
assertEquals(Arrays.asList("install:customContent1 sausages = 1"), handler.calls);
Collection<Resource> constituents = subsystem.getConstituents();
assertEquals("The custom content should not show up as a subsystem constituent", 1, constituents.size());
boolean foundBundle = false;
for (Bundle b : bundleContext.getBundles()) {
if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(b.getSymbolicName())) {
foundBundle = true;
}
}
assertTrue(foundBundle);
boolean foundBundleInConstituents = false;
for (Resource c : constituents) {
for (Capability idCap : c.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE)) {
Object name = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
if ("org.apache.aries.subsystem.itests.customcontent.bundleA".equals(name))
foundBundleInConstituents = true;
}
}
assertTrue(foundBundleInConstituents);
handler.calls.clear();
assertEquals(Subsystem.State.INSTALLED, subsystem.getState());
subsystem.start();
assertEquals(Arrays.asList("start:customContent1"), handler.calls);
handler.calls.clear();
assertEquals(Subsystem.State.ACTIVE, subsystem.getState());
subsystem.stop();
assertEquals(Arrays.asList("stop:customContent1"), handler.calls);
assertEquals(Subsystem.State.RESOLVED, subsystem.getState());
} finally {
handler.calls.clear();
subsystem.uninstall();
assertEquals(Arrays.asList("uninstall:customContent1"), handler.calls);
assertEquals(Subsystem.State.UNINSTALLED, subsystem.getState());
}
} finally {
reg.unregister();
}
}
Aggregations