use of org.osgi.service.resolver.Resolver in project felix by apache.
the class ResolverTest method testScenario4.
@Test
public void testScenario4() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario4(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
try {
resolver.resolve(rci);
fail("Should have thrown a resolution exception as bundle A in scenario 4 cannot be resolved due to constraint violations.");
} catch (ResolutionException re) {
// good
}
}
use of org.osgi.service.resolver.Resolver in project felix by apache.
the class ResolverTest method testScenario1.
@Test
public void testScenario1() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario1(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
assertEquals(2, wireMap.size());
Resource aRes = findResource("A", wireMap.keySet());
List<Wire> aWires = wireMap.get(aRes);
assertEquals(0, aWires.size());
Resource bRes = findResource("B", wireMap.keySet());
List<Wire> bWires = wireMap.get(bRes);
assertEquals(1, bWires.size());
Wire bWire = bWires.iterator().next();
assertEquals(aRes, bWire.getProvider());
assertEquals(bRes, bWire.getRequirer());
Capability cap = bWire.getCapability();
assertEquals(PackageNamespace.PACKAGE_NAMESPACE, cap.getNamespace());
assertEquals(1, cap.getAttributes().size());
assertEquals("foo", cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
assertEquals(0, cap.getDirectives().size());
assertEquals(aRes, cap.getResource());
Requirement req = bWire.getRequirement();
assertEquals(1, req.getDirectives().size());
assertEquals("(osgi.wiring.package=foo)", req.getDirectives().get(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE));
assertEquals(0, req.getAttributes().size());
assertEquals(PackageNamespace.PACKAGE_NAMESPACE, req.getNamespace());
assertEquals(bRes, req.getResource());
}
use of org.osgi.service.resolver.Resolver in project felix by apache.
the class ResolverTest method testScenario3.
@Test
public void testScenario3() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario3(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
assertEquals(3, wireMap.size());
Resource cRes = findResource("C", wireMap.keySet());
List<Wire> cWires = wireMap.get(cRes);
assertEquals(0, cWires.size());
Resource dRes = findResource("D", wireMap.keySet());
List<Wire> dWires = wireMap.get(dRes);
assertEquals(1, dWires.size());
Wire dWire = dWires.iterator().next();
assertEquals(cRes, dWire.getProvider());
assertEquals(dRes, dWire.getRequirer());
Capability dwCap = dWire.getCapability();
assertEquals(PackageNamespace.PACKAGE_NAMESPACE, dwCap.getNamespace());
assertEquals(1, dwCap.getAttributes().size());
assertEquals("resources", dwCap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
assertEquals(0, dwCap.getDirectives().size());
assertEquals(cRes, dwCap.getResource());
Resource eRes = findResource("E", wireMap.keySet());
List<Wire> eWires = wireMap.get(eRes);
assertEquals(2, eWires.size());
boolean foundC = false;
boolean foundD = false;
for (Wire w : eWires) {
assertEquals(eRes, w.getRequirer());
Capability cap = w.getCapability();
if (cap.getNamespace().equals(PackageNamespace.PACKAGE_NAMESPACE)) {
assertEquals("resources", cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
assertEquals(0, cap.getDirectives().size());
assertEquals(cRes, cap.getResource());
foundC = true;
Requirement req = w.getRequirement();
assertEquals(PackageNamespace.PACKAGE_NAMESPACE, req.getNamespace());
assertEquals(eRes, req.getResource());
assertEquals(0, req.getAttributes().size());
assertEquals(1, req.getDirectives().size());
assertEquals("(osgi.wiring.package=resources)", req.getDirectives().get("filter"));
} else if (cap.getNamespace().equals(BundleNamespace.BUNDLE_NAMESPACE)) {
assertEquals("D", cap.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE));
assertEquals(1, cap.getDirectives().size());
assertEquals("resources", cap.getDirectives().get(Namespace.CAPABILITY_USES_DIRECTIVE));
assertEquals(dRes, cap.getResource());
foundD = true;
Requirement req = w.getRequirement();
assertEquals(BundleNamespace.BUNDLE_NAMESPACE, req.getNamespace());
assertEquals(eRes, req.getResource());
assertEquals(0, req.getAttributes().size());
assertEquals(1, req.getDirectives().size());
assertEquals("(osgi.wiring.bundle=D)", req.getDirectives().get("filter"));
}
}
assertTrue(foundC);
assertTrue(foundD);
}
use of org.osgi.service.resolver.Resolver in project felix by apache.
the class ResolverTest method testScenario5.
@Test
public void testScenario5() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario5(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
try {
resolver.resolve(rci);
fail("Should have thrown a resolution exception as bundle A in scenario 5 cannot be resolved due to constraint violations.");
} catch (ResolutionException re) {
// good
}
}
use of org.osgi.service.resolver.Resolver in project felix by apache.
the class ResolverTest method testScenario2.
@Test
public void testScenario2() throws Exception {
Resolver resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG));
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
List<Resource> mandatory = populateScenario2(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
assertEquals(2, wireMap.size());
Resource bRes = findResource("B", wireMap.keySet());
List<Wire> bWires = wireMap.get(bRes);
assertEquals(0, bWires.size());
Resource cRes = findResource("C", wireMap.keySet());
List<Wire> cWires = wireMap.get(cRes);
assertEquals(2, cWires.size());
boolean foundFoo = false;
boolean foundBar = false;
for (Wire w : cWires) {
assertEquals(bRes, w.getProvider());
assertEquals(cRes, w.getRequirer());
Capability cap = w.getCapability();
assertEquals(PackageNamespace.PACKAGE_NAMESPACE, cap.getNamespace());
assertEquals(bRes, cap.getResource());
Map<String, Object> attrs = cap.getAttributes();
assertEquals(1, attrs.size());
Object pkg = attrs.get(PackageNamespace.PACKAGE_NAMESPACE);
if ("foo".equals(pkg)) {
foundFoo = true;
assertEquals(0, cap.getDirectives().size());
} else if ("bar".equals(pkg)) {
foundBar = true;
assertEquals(1, cap.getDirectives().size());
assertEquals("foo", cap.getDirectives().get(PackageNamespace.CAPABILITY_USES_DIRECTIVE));
}
}
assertTrue(foundFoo);
assertTrue(foundBar);
}
Aggregations