Search in sources :

Example 26 with ResourceImpl

use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.

the class ResolverTest method populateScenario18.

private ResolveContext populateScenario18() {
    Map<Requirement, List<Capability>> candMap = new HashMap<Requirement, List<Capability>>();
    ResourceImpl core1 = new ResourceImpl("core1");
    Capability core1_pkgCap1 = addCap(core1, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    Capability core1_pkgCap2 = addCap(core1, PackageNamespace.PACKAGE_NAMESPACE, "corepkg2", "corepkg1");
    Capability core1_pkgCap3 = addCap(core1, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3", "corepkg2");
    ResourceImpl core2 = new ResourceImpl("core2");
    Capability core2_pkgCap1 = addCap(core2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    Capability core2_pkgCap2 = addCap(core2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg2", "corepkg1");
    Capability core2_pkgCap3 = addCap(core2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3", "corepkg2");
    Requirement core2_pkgReq1 = addReq(core2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    Requirement core2_pkgReq2 = addReq(core2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg2");
    Requirement core2_pkgReq3 = addReq(core2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3");
    ResourceImpl core3 = new ResourceImpl("core3");
    Capability core3_pkgCap1 = addCap(core3, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    Capability core3_pkgCap2 = addCap(core3, PackageNamespace.PACKAGE_NAMESPACE, "corepkg2", "corepkg1");
    Capability core3_pkgCap3 = addCap(core3, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3", "corepkg2");
    Requirement core3_pkgReq1 = addReq(core3, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    Requirement core3_pkgReq2 = addReq(core3, PackageNamespace.PACKAGE_NAMESPACE, "corepkg2");
    Requirement core3_pkgReq3 = addReq(core3, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3");
    ResourceImpl client1 = new ResourceImpl("client1");
    Capability client1_pkgCap = addCap(client1, PackageNamespace.PACKAGE_NAMESPACE, "clientpkg1", "corepkg3");
    Requirement client1_pkgReq1 = addReq(client1, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3");
    ResourceImpl client2 = new ResourceImpl("client2");
    Capability client2_pkgCap = addCap(client2, PackageNamespace.PACKAGE_NAMESPACE, "clientpkg1", "corepkg3");
    Requirement client2_pkgReq1 = addReq(client2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg3");
    ResourceImpl bundle1 = new ResourceImpl("bundle1");
    Requirement bundle1_pkgReq1 = addReq(bundle1, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    Requirement bundle1_pkgReq2 = addReq(bundle1, PackageNamespace.PACKAGE_NAMESPACE, "clientpkg1");
    ResourceImpl bundle2 = new ResourceImpl("bundle2");
    Requirement bundle2_pkgReq1 = addReq(bundle2, PackageNamespace.PACKAGE_NAMESPACE, "corepkg1");
    candMap.put(core2_pkgReq1, Arrays.asList(core3_pkgCap1, core2_pkgCap1));
    candMap.put(core2_pkgReq2, Arrays.asList(core3_pkgCap2, core2_pkgCap2));
    candMap.put(core2_pkgReq3, Arrays.asList(core3_pkgCap3, core2_pkgCap3));
    candMap.put(core3_pkgReq1, Arrays.asList(core3_pkgCap1, core2_pkgCap1));
    candMap.put(core3_pkgReq2, Arrays.asList(core3_pkgCap2, core2_pkgCap2));
    candMap.put(core3_pkgReq3, Arrays.asList(core3_pkgCap3, core2_pkgCap3));
    candMap.put(client1_pkgReq1, Arrays.asList(core3_pkgCap3, core2_pkgCap3, core1_pkgCap3));
    candMap.put(client2_pkgReq1, Arrays.asList(core3_pkgCap3));
    candMap.put(bundle1_pkgReq1, Arrays.asList(core1_pkgCap1));
    candMap.put(bundle1_pkgReq2, Arrays.asList(client1_pkgCap));
    candMap.put(bundle2_pkgReq1, Arrays.asList(core3_pkgCap1));
    Collection<Resource> mandatory = Arrays.<Resource>asList(core1, core2, core3, client1, client2, bundle1, bundle2);
    return new ResolveContextImpl(Collections.<Resource, Wiring>emptyMap(), candMap, mandatory, Collections.<Resource>emptyList());
}
Also used : Requirement(org.osgi.resource.Requirement) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) Capability(org.osgi.resource.Capability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) List(java.util.List) ResolveContextImpl(org.apache.felix.resolver.test.util.ResolveContextImpl)

Example 27 with ResourceImpl

use of org.apache.felix.resolver.test.util.ResourceImpl in project felix by apache.

the class ResolverTest method testScenario12.

/**
 * Test dynamic resolution with an unresolvable host
 */
@Test(expected = ResolutionException.class)
public void testScenario12() 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 b1 = new ResourceImpl("B");
    Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
    ResourceImpl c1 = new ResourceImpl("C");
    Capability c_hostCap = addCap(c1, HostNamespace.HOST_NAMESPACE, "A");
    Capability c_pkgCap = addCap(c1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.a");
    Requirement c_pkgReq1 = addReq(c1, PackageNamespace.PACKAGE_NAMESPACE, "org.foo.b");
    candMap.put(b_pkgReq1, Collections.singletonList(c_pkgCap));
    candMap.put(c_pkgReq1, Collections.<Capability>emptyList());
    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(c_pkgCap);
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci, b1, b_pkgReq1, caps);
    assertEquals(0, wireMap.size());
}
Also used : GenericCapability(org.apache.felix.resolver.test.util.GenericCapability) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) Capability(org.osgi.resource.Capability) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) HashMap(java.util.HashMap) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Logger(org.apache.felix.resolver.Logger) Wire(org.osgi.resource.Wire) Wiring(org.osgi.resource.Wiring) Requirement(org.osgi.resource.Requirement) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement) GenericRequirement(org.apache.felix.resolver.test.util.GenericRequirement) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) ArrayList(java.util.ArrayList) List(java.util.List) ResolveContextImpl(org.apache.felix.resolver.test.util.ResolveContextImpl) Test(org.junit.Test)

Aggregations

ResourceImpl (org.apache.felix.resolver.test.util.ResourceImpl)27 Resource (org.osgi.resource.Resource)26 ArrayList (java.util.ArrayList)25 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)23 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)21 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)21 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)20 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)20 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)19 Capability (org.osgi.resource.Capability)18 Requirement (org.osgi.resource.Requirement)18 HashMap (java.util.HashMap)11 List (java.util.List)11 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)9 Wire (org.osgi.resource.Wire)8 Logger (org.apache.felix.resolver.Logger)7 ResolverImpl (org.apache.felix.resolver.ResolverImpl)7 Test (org.junit.Test)7 Wiring (org.osgi.resource.Wiring)7 Collection (java.util.Collection)3