Search in sources :

Example 6 with ResolveContextImpl

use of org.apache.felix.resolver.test.util.ResolveContextImpl 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());
}
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 7 with ResolveContextImpl

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

the class Main method main.

public static void main(String[] args) throws ResolutionException {
    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;
    ResolveContextImpl rci;
    Map<Resource, List<Wire>> wireMap;
    System.out.println("\nSCENARIO 1\n");
    mandatory = populateScenario1(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    wireMap = resolver.resolve(rci);
    System.out.println("RESULT " + wireMap);
    System.out.println("\nSCENARIO 2\n");
    mandatory = populateScenario2(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    wireMap = resolver.resolve(rci);
    System.out.println("RESULT " + wireMap);
    System.out.println("\nSCENARIO 3\n");
    mandatory = populateScenario3(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    wireMap = resolver.resolve(rci);
    System.out.println("RESULT " + wireMap);
    System.out.println("\nSCENARIO 4\n");
    mandatory = populateScenario4(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    try {
        wireMap = resolver.resolve(rci);
        System.err.println("UNEXPECTED RESULT " + wireMap);
    } catch (ResolutionException e) {
        System.out.println("EXPECTED ResolutionException:");
        e.printStackTrace(System.out);
    }
    System.out.println("\nSCENARIO 5\n");
    mandatory = populateScenario5(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    try {
        wireMap = resolver.resolve(rci);
        System.err.println("UNEXPECTED RESULT " + wireMap);
    } catch (ResolutionException e) {
        System.out.println("EXPECTED ResolutionException:");
        e.printStackTrace(System.out);
    }
    System.out.println("\nSCENARIO 6\n");
    mandatory = populateScenario6(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    wireMap = resolver.resolve(rci);
    System.out.println("RESULT " + wireMap);
    System.out.println("\nSCENARIO 7\n");
    mandatory = populateScenario7(wirings, candMap);
    rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.EMPTY_LIST);
    wireMap = resolver.resolve(rci);
    System.out.println("RESULT " + wireMap);
}
Also used : Resolver(org.osgi.service.resolver.Resolver) 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) 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) ArrayList(java.util.ArrayList) List(java.util.List) ResolveContextImpl(org.apache.felix.resolver.test.util.ResolveContextImpl)

Example 8 with ResolveContextImpl

use of org.apache.felix.resolver.test.util.ResolveContextImpl 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 9 with ResolveContextImpl

use of org.apache.felix.resolver.test.util.ResolveContextImpl 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 10 with ResolveContextImpl

use of org.apache.felix.resolver.test.util.ResolveContextImpl 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());
}
Also used : Resolver(org.osgi.service.resolver.Resolver) 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) ArrayList(java.util.ArrayList) List(java.util.List) ResolveContextImpl(org.apache.felix.resolver.test.util.ResolveContextImpl) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 List (java.util.List)20 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)20 Capability (org.osgi.resource.Capability)20 Requirement (org.osgi.resource.Requirement)20 Resource (org.osgi.resource.Resource)20 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)19 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)19 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)19 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)19 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)19 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)19 Logger (org.apache.felix.resolver.Logger)18 ResolverImpl (org.apache.felix.resolver.ResolverImpl)18 Test (org.junit.Test)17 Wiring (org.osgi.resource.Wiring)16 Wire (org.osgi.resource.Wire)14 Resolver (org.osgi.service.resolver.Resolver)11 ResourceImpl (org.apache.felix.resolver.test.util.ResourceImpl)9