Search in sources :

Example 16 with ResolveContextImpl

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

the class ResolverTest method testScenario5.

@Test
public void testScenario5() 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 = populateScenario5(wirings, candMap);
    ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
    try {
        resolver.resolve(rci);
        fail("Should have thrown a resolution exception as bundle A in scenario 5 cannot be resolved due to constraint violations.");
    } catch (ResolutionException re) {
    // good
    }
}
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) Test(org.junit.Test)

Example 17 with ResolveContextImpl

use of org.apache.felix.resolver.test.util.ResolveContextImpl 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());
}
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) ResolverImpl(org.apache.felix.resolver.ResolverImpl) ArrayList(java.util.ArrayList) List(java.util.List) ResolveContextImpl(org.apache.felix.resolver.test.util.ResolveContextImpl) Logger(org.apache.felix.resolver.Logger) Test(org.junit.Test)

Example 18 with ResolveContextImpl

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

the class ResolverTest method testScenario2.

@Test
public void testScenario2() 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 = populateScenario2(wirings, candMap);
    ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
    assertEquals(2, wireMap.size());
    Resource bRes = findResource("B", wireMap.keySet());
    List<Wire> bWires = wireMap.get(bRes);
    assertEquals(0, bWires.size());
    Resource cRes = findResource("C", wireMap.keySet());
    List<Wire> cWires = wireMap.get(cRes);
    assertEquals(2, cWires.size());
    boolean foundFoo = false;
    boolean foundBar = false;
    for (Wire w : cWires) {
        assertEquals(bRes, w.getProvider());
        assertEquals(cRes, w.getRequirer());
        Capability cap = w.getCapability();
        assertEquals(PackageNamespace.PACKAGE_NAMESPACE, cap.getNamespace());
        assertEquals(bRes, cap.getResource());
        Map<String, Object> attrs = cap.getAttributes();
        assertEquals(1, attrs.size());
        Object pkg = attrs.get(PackageNamespace.PACKAGE_NAMESPACE);
        if ("foo".equals(pkg)) {
            foundFoo = true;
            assertEquals(0, cap.getDirectives().size());
        } else if ("bar".equals(pkg)) {
            foundBar = true;
            assertEquals(1, cap.getDirectives().size());
            assertEquals("foo", cap.getDirectives().get(PackageNamespace.CAPABILITY_USES_DIRECTIVE));
        }
    }
    assertTrue(foundFoo);
    assertTrue(foundBar);
}
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)

Example 19 with ResolveContextImpl

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

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

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