use of org.apache.felix.resolver.Logger in project felix by apache.
the class ResolverTest method testScenario8.
@Test
public void testScenario8() 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 = populateScenario8(wirings, candMap);
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
Resource res2 = findResource("res2", wireMap.keySet());
Resource res4 = findResource("res4", wireMap.keySet());
Resource res5 = findResource("res5", wireMap.keySet());
assertNotNull(res2);
assertNotNull(res4);
assertNotNull(res5);
List<Wire> wires2 = wireMap.get(res2);
assertEquals(2, wires2.size());
// should be wired to res4 and res5
List<Wire> wires4 = wireMap.get(res4);
assertEquals(1, wires4.size());
// should be wired to res5
List<Wire> wires5 = wireMap.get(res5);
assertEquals(0, wires5.size());
// should not be wired to any of its optional requirements to res6
assertEquals(3, wireMap.size());
}
use of org.apache.felix.resolver.Logger 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.Logger 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.Logger 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.Logger in project felix by apache.
the class ResolverTest method testScenario17_6.
@Test
public void testScenario17_6() throws Exception {
ResolveContext rci = populateScenario17(true, true, true);
ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
resolver.resolve(rci);
}
Aggregations