use of org.apache.felix.resolver.test.util.ResolveContextImpl in project felix by apache.
the class ResolverTest method testScenario11.
/**
* Test dynamic resolution with an unresolved fragment
*/
@Test
public void testScenario11() throws Exception {
ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
ResourceImpl a1 = new ResourceImpl("A");
Capability a1_hostCap = addCap(a1, HostNamespace.HOST_NAMESPACE, "A");
ResourceImpl f1 = new ResourceImpl("F1", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
Requirement f1_hostReq = addReq(f1, HostNamespace.HOST_NAMESPACE, "A");
Capability f1_pkgCap = addCap(f1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
ResourceImpl b1 = new ResourceImpl("B");
Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
candMap.put(b_pkgReq1, Collections.singletonList(f1_pkgCap));
candMap.put(f1_hostReq, Collections.singletonList(a1_hostCap));
Map<Resource, List<Wire>> wires = new HashMap<Resource, List<Wire>>();
wires.put(a1, new ArrayList<Wire>());
wires.put(b1, new ArrayList<Wire>());
Map<Resource, List<Wire>> invertedWires = new HashMap<Resource, List<Wire>>();
invertedWires.put(a1, new ArrayList<Wire>());
invertedWires.put(b1, new ArrayList<Wire>());
wirings.put(a1, new SimpleWiring(a1, Collections.<Capability>emptyList(), wires, invertedWires));
wirings.put(b1, new SimpleWiring(b1, Collections.<Capability>emptyList(), wires, invertedWires));
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Collections.<Resource>emptyList(), Collections.<Resource>emptyList());
List<Capability> caps = new ArrayList<Capability>();
caps.add(f1_pkgCap);
try {
resolver.resolve(rci, b1, b_pkgReq1, caps);
fail("Should fail to dynamic requirement to fragment when host is resolved already.");
} catch (ResolutionException e) {
// expected
assertTrue(e.getUnresolvedRequirements().contains(b_pkgReq1));
}
// now remove host wiring
wirings.remove(a1);
caps.clear();
caps.add(f1_pkgCap);
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci, b1, b_pkgReq1, caps);
assertEquals(3, wireMap.size());
List<Wire> wiresB = wireMap.get(b1);
assertNotNull(wiresB);
assertEquals(1, wiresB.size());
// should be wired to A through the fragment capability
assertEquals(a1, wiresB.get(0).getProvider());
assertEquals(f1_pkgCap, wiresB.get(0).getCapability());
}
use of org.apache.felix.resolver.test.util.ResolveContextImpl 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.apache.felix.resolver.test.util.ResolveContextImpl in project felix by apache.
the class ResolverTest method testScenario10.
/**
* Test dynamic resolution with a resolved fragment
*/
@Test
public void testScenario10() throws Exception {
ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
Map<Resource, Wiring> wirings = new HashMap<Resource, Wiring>();
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
ResourceImpl a1 = new ResourceImpl("A");
Capability a1_hostCap = addCap(a1, HostNamespace.HOST_NAMESPACE, "A");
ResourceImpl f1 = new ResourceImpl("F1", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
Requirement f1_hostReq = addReq(f1, HostNamespace.HOST_NAMESPACE, "A");
Capability f1_pkgCap = addCap(f1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
ResourceImpl b1 = new ResourceImpl("B");
Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
candMap.put(b_pkgReq1, Collections.singletonList(f1_pkgCap));
Map<Resource, List<Wire>> wires = new HashMap<Resource, List<Wire>>();
wires.put(a1, new ArrayList<Wire>());
wires.put(b1, new ArrayList<Wire>());
wires.put(f1, new ArrayList<Wire>());
wires.get(f1).add(new SimpleWire(f1_hostReq, a1_hostCap));
Map<Resource, List<Wire>> invertedWires = new HashMap<Resource, List<Wire>>();
invertedWires.put(a1, new ArrayList<Wire>());
invertedWires.put(b1, new ArrayList<Wire>());
invertedWires.put(f1, new ArrayList<Wire>());
invertedWires.get(a1).add(new SimpleWire(f1_hostReq, a1_hostCap));
wirings.put(a1, new SimpleWiring(a1, Arrays.asList(a1_hostCap, f1_pkgCap), wires, invertedWires));
wirings.put(b1, new SimpleWiring(b1, Collections.<Capability>emptyList(), wires, invertedWires));
wirings.put(f1, new SimpleWiring(f1, Collections.<Capability>emptyList(), wires, invertedWires));
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Collections.<Resource>emptyList(), Collections.<Resource>emptyList());
List<Capability> caps = new ArrayList<Capability>();
caps.add(f1_pkgCap);
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci, b1, b_pkgReq1, caps);
assertEquals(1, wireMap.size());
List<Wire> wiresB = wireMap.get(b1);
assertNotNull(wiresB);
assertEquals(1, wiresB.size());
// should be wired to A through the fragment capability
assertEquals(a1, wiresB.get(0).getProvider());
assertEquals(f1_pkgCap, wiresB.get(0).getCapability());
}
use of org.apache.felix.resolver.test.util.ResolveContextImpl 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.apache.felix.resolver.test.util.ResolveContextImpl 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);
}
Aggregations