Search in sources :

Example 16 with ResourceImpl

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

the class ResolverTest method populateScenario2.

private static List<Resource> populateScenario2(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
    List<Capability> fooCands = new ArrayList<Capability>();
    List<Capability> barCands = new ArrayList<Capability>();
    // A
    ResourceImpl a = new ResourceImpl("A");
    PackageCapability p = new PackageCapability(a, "foo");
    a.addCapability(p);
    fooCands.add(p);
    // B
    ResourceImpl b = new ResourceImpl("B");
    p = new PackageCapability(b, "foo");
    b.addCapability(p);
    fooCands.add(p);
    p = new PackageCapability(b, "bar");
    p.addDirective(PackageNamespace.CAPABILITY_USES_DIRECTIVE, "foo");
    b.addCapability(p);
    barCands.add(p);
    // C
    ResourceImpl c = new ResourceImpl("C");
    Requirement r = new PackageRequirement(c, "foo");
    c.addRequirement(r);
    candMap.put(r, fooCands);
    r = new PackageRequirement(c, "bar");
    c.addRequirement(r);
    candMap.put(r, barCands);
    // Mandatory resources
    List<Resource> resources = new ArrayList<Resource>();
    resources.add(c);
    return resources;
}
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) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) 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) PackageRequirement(org.apache.felix.resolver.test.util.PackageRequirement) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource)

Example 17 with ResourceImpl

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

the class ResolverTest method testScenario14.

@Test
public void testScenario14() 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", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("1.0.0"));
    Capability a1_hostCap = addCap(a1, HostNamespace.HOST_NAMESPACE, "A");
    Capability a1_pkgCap = addCap(a1, PackageNamespace.PACKAGE_NAMESPACE, "a");
    Requirement a1_pkgReq = addReq(a1, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
    ResourceImpl a2 = new ResourceImpl("A", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("2.0.0"));
    Capability a2_hostCap = addCap(a2, HostNamespace.HOST_NAMESPACE, "A");
    Capability a2_pkgCap = addCap(a2, PackageNamespace.PACKAGE_NAMESPACE, "a");
    Requirement a2_pkgReq = addReq(a2, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
    ResourceImpl a3 = new ResourceImpl("A", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("3.0.0"));
    Capability a3_hostCap = addCap(a3, HostNamespace.HOST_NAMESPACE, "A");
    Capability a3_pkgCap = addCap(a3, PackageNamespace.PACKAGE_NAMESPACE, "a");
    Requirement a3_pkgReq = addReq(a3, PackageNamespace.PACKAGE_NAMESPACE, "a.impl");
    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, "a.impl");
    Requirement f1_pkgReq = addReq(f1, PackageNamespace.PACKAGE_NAMESPACE, "a");
    ResourceImpl b1 = new ResourceImpl("B");
    Requirement b_pkgReq1 = addReq(b1, PackageNamespace.PACKAGE_NAMESPACE, "a");
    candMap.put(a1_pkgReq, Collections.singletonList(f1_pkgCap));
    candMap.put(a2_pkgReq, Collections.singletonList(f1_pkgCap));
    candMap.put(a3_pkgReq, Collections.singletonList(f1_pkgCap));
    candMap.put(b_pkgReq1, Arrays.asList(a3_pkgCap, a2_pkgCap, a1_pkgCap));
    candMap.put(f1_pkgReq, Arrays.asList(a3_pkgCap, a2_pkgCap, a1_pkgCap));
    candMap.put(f1_hostReq, Arrays.asList(a3_hostCap, a2_hostCap, a1_hostCap));
    ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, Arrays.<Resource>asList(b1, a1, a2, a3), Collections.<Resource>emptyList());
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
    // all bundles should be resolved
    assertEquals(5, wireMap.size());
    List<Wire> wiresB = wireMap.get(b1);
    assertNotNull(wiresB);
    assertEquals(1, wiresB.size());
    assertEquals(a3, wiresB.get(0).getProvider());
    assertEquals(a3_pkgCap, wiresB.get(0).getCapability());
    // There should be three hosts
    List<Wire> wiresF1 = wireMap.get(f1);
    assertNotNull(wiresF1);
    assertEquals(3, wiresF1.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) 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)

Example 18 with ResourceImpl

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

the class ResolverTest method testScenario15.

@Test
public void testScenario15() 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");
    Requirement host1_pkgReq = addReq(host1, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host2 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("2.0.0"));
    Capability host2_hostCap = addCap(host2, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host2_pkgReq = addReq(host2, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host3 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("3.0.0"));
    Capability host3_hostCap = addCap(host3, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host3_pkgReq = addReq(host3, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host4 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("4.0.0"));
    Capability host4_hostCap = addCap(host4, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host4_pkgReq = addReq(host4, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host5 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("5.0.0"));
    Capability host5_hostCap = addCap(host5, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host5_pkgReq = addReq(host5, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host6 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("6.0.0"));
    Capability host6_hostCap = addCap(host6, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host6_pkgReq = addReq(host6, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host7 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("7.0.0"));
    Capability host7_hostCap = addCap(host7, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host7_pkgReq = addReq(host7, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    ResourceImpl host8 = new ResourceImpl("host", IdentityNamespace.TYPE_BUNDLE, Version.parseVersion("8.0.0"));
    Capability host8_hostCap = addCap(host8, HostNamespace.HOST_NAMESPACE, "host");
    Requirement host8_pkgReq = addReq(host8, PackageNamespace.PACKAGE_NAMESPACE, "exporter");
    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(host1_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host2_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host3_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host4_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host5_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host6_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host7_pkgReq, Collections.singletonList(exporter_pkgCap));
    candMap.put(host8_pkgReq, Collections.singletonList(exporter_pkgCap));
    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, host5, host6, host7, host8, hostFrag), Collections.<Resource>emptyList());
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
    // all bundles should be resolved
    assertEquals(11, wireMap.size());
    // There should be 8 hosts
    List<Wire> wiresHostFrag = wireMap.get(hostFrag);
    assertNotNull(wiresHostFrag);
    assertEquals(8, wiresHostFrag.size());
    List<Wire> wiresHost1 = wireMap.get(host1);
    assertNotNull(wiresHost1);
}
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) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Logger(org.apache.felix.resolver.Logger) Wire(org.osgi.resource.Wire) 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)

Example 19 with ResourceImpl

use of org.apache.felix.resolver.test.util.ResourceImpl 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());
}
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) ResolutionException(org.osgi.service.resolver.ResolutionException) 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)

Example 20 with ResourceImpl

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

the class ResolverTest method populateScenario5.

private static List<Resource> populateScenario5(Map<Resource, Wiring> wirings, Map<Requirement, List<Capability>> candMap) {
    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;
}
Also used : ResourceImpl(org.apache.felix.resolver.test.util.ResourceImpl) PackageCapability(org.apache.felix.resolver.test.util.PackageCapability) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) BundleCapability(org.apache.felix.resolver.test.util.BundleCapability) BundleRequirement(org.apache.felix.resolver.test.util.BundleRequirement)

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