use of org.osgi.resource.Resource 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);
}
}
use of org.osgi.resource.Resource 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();
}
}
use of org.osgi.resource.Resource in project aries by apache.
the class ProvisionResourceHeader method newInstance.
public static ProvisionResourceHeader newInstance(Collection<Resource> resources) {
StringBuilder builder = new StringBuilder();
for (Resource resource : resources) {
appendResource(resource, builder);
builder.append(',');
}
// Remove the trailing comma.
// TODO Intentionally letting the exception propagate since there must be at least one resource.
builder.deleteCharAt(builder.length() - 1);
return new ProvisionResourceHeader(builder.toString());
}
use of org.osgi.resource.Resource in project aries by apache.
the class SubsystemContentHeader method newInstance.
public static SubsystemContentHeader newInstance(Collection<Resource> resources) {
StringBuilder builder = new StringBuilder();
for (Resource resource : resources) {
appendResource(resource, builder);
builder.append(',');
}
// Remove the trailing comma.
// TODO Intentionally letting the exception propagate since there must be at least one resource.
builder.deleteCharAt(builder.length() - 1);
return new SubsystemContentHeader(builder.toString());
}
use of org.osgi.resource.Resource in project aries by apache.
the class DeployedContentHeader method newInstance.
public static DeployedContentHeader newInstance(Collection<Resource> resources) {
StringBuilder builder = new StringBuilder();
for (Resource resource : resources) {
appendResource(resource, builder, true);
builder.append(',');
}
// Remove the trailing comma.
// TODO Intentionally letting the exception propagate since there must
// be at least one resource.
builder.deleteCharAt(builder.length() - 1);
return new DeployedContentHeader(builder.toString());
}
Aggregations