use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class ResolverTest method populateScenario7.
private static List<Resource> populateScenario7(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
ResourceImpl a1 = new ResourceImpl("A");
GenericCapability a1_hostCap = new GenericCapability(a1, HostNamespace.HOST_NAMESPACE);
a1_hostCap.addAttribute(HostNamespace.HOST_NAMESPACE, "A");
a1.addCapability(a1_hostCap);
ResourceImpl f1 = new ResourceImpl("F1", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
GenericRequirement f1_hostReq = new GenericRequirement(f1, HostNamespace.HOST_NAMESPACE);
f1_hostReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + HostNamespace.HOST_NAMESPACE + "=A)");
f1.addRequirement(f1_hostReq);
ResourceImpl f2 = new ResourceImpl("F2", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
GenericRequirement f2_hostReq = new GenericRequirement(f2, HostNamespace.HOST_NAMESPACE);
f2_hostReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + HostNamespace.HOST_NAMESPACE + "=A)");
f2.addRequirement(f2_hostReq);
ResourceImpl b1 = new ResourceImpl("B");
GenericRequirement b1_identityReq = new GenericRequirement(b1, IdentityNamespace.IDENTITY_NAMESPACE);
b1_identityReq.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, "(" + IdentityNamespace.IDENTITY_NAMESPACE + "=F2)");
b1.addRequirement(b1_identityReq);
candMap.put(f1.getRequirements(null).get(0), a1.getCapabilities(HostNamespace.HOST_NAMESPACE));
candMap.put(f2.getRequirements(null).get(0), a1.getCapabilities(HostNamespace.HOST_NAMESPACE));
candMap.put(b1.getRequirements(null).get(0), f2.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE));
List<Resource> resources = new ArrayList<Resource>();
resources.add(a1);
resources.add(f1);
resources.add(f2);
resources.add(b1);
return resources;
}
use of org.apache.felix.resolver.test.util.ResourceImpl 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.ResourceImpl in project felix by apache.
the class ResolverTest method populateScenario4.
private static List<Resource> populateScenario4(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
ResourceImpl a = new ResourceImpl("A");
a.addRequirement(new BundleRequirement(a, "B"));
a.addRequirement(new BundleRequirement(a, "C"));
ResourceImpl b = new ResourceImpl("B");
b.addCapability(new BundleCapability(b, "B"));
b.addCapability(new PackageCapability(b, "p1"));
ResourceImpl c = new ResourceImpl("C");
c.addRequirement(new BundleRequirement(c, "D"));
c.addCapability(new BundleCapability(c, "C"));
PackageCapability p2 = new PackageCapability(c, "p2");
p2.addDirective(Namespace.CAPABILITY_USES_DIRECTIVE, "p1");
c.addCapability(p2);
ResourceImpl d = new ResourceImpl("D");
d.addCapability(new BundleCapability(d, "D"));
d.addCapability(new PackageCapability(d, "p1"));
candMap.put(a.getRequirements(null).get(0), b.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
candMap.put(a.getRequirements(null).get(1), c.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
candMap.put(c.getRequirements(null).get(0), d.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
List<Resource> resources = new ArrayList<Resource>();
resources.add(a);
return resources;
}
use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class ResolverTest method testScenario16.
@Test
public void testScenario16() throws Exception {
ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
ResourceImpl exporter = new ResourceImpl("exporter", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("1.0.0"));
Capability exporter_hostCap = addCap(exporter, HostNamespace.HOST_NAMESPACE, "exporter");
Capability exporter_pkgCap = addCap(exporter, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
ResourceImpl exporterFrag = new ResourceImpl("exporter.frag", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
Requirement exporterFrag_hostReq = addReq(exporterFrag, HostNamespace.HOST_NAMESPACE, "exporter");
ResourceImpl host1 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("1.0.0"));
Capability host1_hostCap = addCap(host1, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host2 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("2.0.0"));
Capability host2_hostCap = addCap(host2, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host3 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("3.0.0"));
Capability host3_hostCap = addCap(host3, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host4 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("4.0.0"));
Capability host4_hostCap = addCap(host4, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host5 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("5.0.0"));
Capability host5_hostCap = addCap(host4, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host6 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("6.0.0"));
Capability host6_hostCap = addCap(host4, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host7 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("7.0.0"));
Capability host7_hostCap = addCap(host4, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl host8 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("8.0.0"));
Capability host8_hostCap = addCap(host4, HostNamespace.HOST_NAMESPACE, "host");
ResourceImpl hostFrag = new ResourceImpl("host.frag", IdentityNamespace.TYPE_FRAGMENT, Version.emptyVersion);
Requirement hostFrag_hostReq = addReq(hostFrag, HostNamespace.HOST_NAMESPACE, "host");
Requirement hostFrag_pkgReq = addReq(hostFrag, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
candMap.put(exporterFrag_hostReq, Collections.singletonList(exporter_hostCap));
candMap.put(hostFrag_pkgReq, Collections.singletonList(exporter_pkgCap));
candMap.put(hostFrag_hostReq, Arrays.asList(host1_hostCap, host2_hostCap, host3_hostCap, host4_hostCap, host5_hostCap, host6_hostCap, host7_hostCap, host8_hostCap));
ResolveContextImpl rci = new ResolveContextImpl(Collections.<Resource, Wiring>emptyMap(), candMap, Arrays.<Resource>asList(host1, host2, host3, host4, exporter, exporterFrag, hostFrag, host5, host6, host7, host8), Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
// all bundles should be resolved
assertEquals(11, wireMap.size());
}
use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class ResolverTest method populateScenario1.
private static List<Resource> populateScenario1(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
ResourceImpl exporter = new ResourceImpl("A");
exporter.addCapability(new PackageCapability(exporter, "foo"));
ResourceImpl importer = new ResourceImpl("B");
importer.addRequirement(new PackageRequirement(importer, "foo"));
candMap.put(importer.getRequirements(null).get(0), exporter.getCapabilities(PackageNamespace.PACKAGE_NAMESPACE));
List<Resource> resources = new ArrayList<Resource>();
resources.add(importer);
return resources;
}
Aggregations