use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class ResolverTest method testScenario13.
@Test
public void testScenario13() 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));
ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Collections.<Resource>singletonList(b1), Collections.<Resource>emptyList());
Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
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.ResourceImpl in project felix by apache.
the class BigResolutionTest method buildResolutionContext.
private ResolveContext buildResolutionContext() throws IOException, BundleException {
Object resolution;
InputStream is = getClass().getClassLoader().getResourceAsStream("resolution.json");
try {
resolution = JsonReader.read(is);
} finally {
is.close();
}
List<Resource> resources = new ArrayList<Resource>();
ResourceImpl system = new ResourceImpl("system-bundle");
parseCapability(system, "osgi.ee; osgi.ee=JavaSE; version=1.5");
parseCapability(system, "osgi.ee; osgi.ee=JavaSE; version=1.6");
parseCapability(system, "osgi.ee; osgi.ee=JavaSE; version=1.7");
resources.add(system);
for (Object r : (Collection) ((Map) resolution).get("resources")) {
resources.add(parseResource(r));
}
final List<Resource> mandatory = new ArrayList<Resource>();
for (Object r : (Collection) ((Map) resolution).get("mandatory")) {
mandatory.add(parseResource(r));
}
final Map<String, CapabilitySet> capSets = new HashMap<String, CapabilitySet>();
CapabilitySet svcSet = new CapabilitySet(Collections.singletonList("objectClass"));
capSets.put("osgi.service", svcSet);
for (Resource resource : resources) {
for (Capability cap : resource.getCapabilities(null)) {
String ns = cap.getNamespace();
CapabilitySet set = capSets.get(ns);
if (set == null) {
set = new CapabilitySet(Collections.singletonList(ns));
capSets.put(ns, set);
}
set.addCapability(cap);
}
}
return new ResolveContext() {
@Override
public Collection<Resource> getMandatoryResources() {
return mandatory;
}
@Override
public List<Capability> findProviders(Requirement requirement) {
SimpleFilter sf;
if (requirement.getDirectives().containsKey("filter")) {
sf = SimpleFilter.parse(requirement.getDirectives().get("filter"));
} else {
sf = SimpleFilter.convert(requirement.getAttributes());
}
CapabilitySet set = capSets.get(requirement.getNamespace());
List<Capability> caps = new ArrayList<Capability>(set.match(sf, true));
Collections.sort(caps, new CandidateComparator());
return caps;
}
@Override
public int insertHostedCapability(List<Capability> capabilities, HostedCapability hostedCapability) {
capabilities.add(hostedCapability);
return capabilities.size() - 1;
}
@Override
public boolean isEffective(Requirement requirement) {
return true;
}
@Override
public Map<Resource, Wiring> getWirings() {
return Collections.emptyMap();
}
};
}
use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class BigResolutionTest method parseResource.
@SuppressWarnings("unchecked")
public static Resource parseResource(Object resource) throws BundleException {
ResourceImpl res = new ResourceImpl();
Collection<String> caps = (Collection<String>) ((Map) resource).get("capabilities");
if (caps != null) {
for (String s : caps) {
parseCapability(res, s);
}
}
Collection<String> reqs = (Collection<String>) ((Map) resource).get("requirements");
if (reqs != null) {
for (String s : reqs) {
parseRequirement(res, s);
}
}
return res;
}
use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class Main method populateScenario5.
private static List<Resource> populateScenario5(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
wirings.clear();
candMap.clear();
ResourceImpl x = new ResourceImpl("X");
x.addRequirement(new BundleRequirement(x, "A"));
ResourceImpl a = new ResourceImpl("A");
a.addCapability(new BundleCapability(a, "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(x.getRequirements(null).get(0), a.getCapabilities(BundleNamespace.BUNDLE_NAMESPACE));
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(x);
return resources;
}
use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.
the class Main method populateScenario4.
private static List<Resource> populateScenario4(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
wirings.clear();
candMap.clear();
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;
}
Aggregations