Search in sources :

Example 16 with Logger

use of org.apache.felix.resolver.Logger 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)

Example 17 with Logger

use of org.apache.felix.resolver.Logger 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 18 with Logger

use of org.apache.felix.resolver.Logger in project felix by apache.

the class ResolverTest method testScenario4.

@Test
public void testScenario4() 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 = populateScenario4(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 4 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 19 with Logger

use of org.apache.felix.resolver.Logger in project felix by apache.

the class ResolverTest method testScenario10.

/**
 * Test dynamic resolution with a resolved fragment
 */
@Test
public void testScenario10() 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));
    Map<Resource, List<Wire>> wires = new HashMap<Resource, List<Wire>>();
    wires.put(a1, new ArrayList<Wire>());
    wires.put(b1, new ArrayList<Wire>());
    wires.put(f1, new ArrayList<Wire>());
    wires.get(f1).add(new SimpleWire(f1_hostReq, a1_hostCap));
    Map<Resource, List<Wire>> invertedWires = new HashMap<Resource, List<Wire>>();
    invertedWires.put(a1, new ArrayList<Wire>());
    invertedWires.put(b1, new ArrayList<Wire>());
    invertedWires.put(f1, new ArrayList<Wire>());
    invertedWires.get(a1).add(new SimpleWire(f1_hostReq, a1_hostCap));
    wirings.put(a1, new SimpleWiring(a1, Arrays.asList(a1_hostCap, f1_pkgCap), wires, invertedWires));
    wirings.put(b1, new SimpleWiring(b1, Collections.<Capability>emptyList(), wires, invertedWires));
    wirings.put(f1, new SimpleWiring(f1, 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);
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci, b1, b_pkgReq1, caps);
    assertEquals(1, 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) 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 Logger

use of org.apache.felix.resolver.Logger in project felix by apache.

the class ResolverTest method testScenario17_6.

@Test
public void testScenario17_6() throws Exception {
    ResolveContext rci = populateScenario17(true, true, true);
    ResolverImpl resolver = new ResolverImpl(new Logger(Logger.LOG_DEBUG), 1);
    resolver.resolve(rci);
}
Also used : ResolveContext(org.osgi.service.resolver.ResolveContext) ResolverImpl(org.apache.felix.resolver.ResolverImpl) Logger(org.apache.felix.resolver.Logger) Test(org.junit.Test)

Aggregations

Logger (org.apache.felix.resolver.Logger)29 ResolverImpl (org.apache.felix.resolver.ResolverImpl)29 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)21 List (java.util.List)21 Resource (org.osgi.resource.Resource)21 Capability (org.osgi.resource.Capability)19 Requirement (org.osgi.resource.Requirement)19 HashMap (java.util.HashMap)18 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)18 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)17 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)17 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)17 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)17 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)17 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)17 Wiring (org.osgi.resource.Wiring)15 Wire (org.osgi.resource.Wire)13 Resolver (org.osgi.service.resolver.Resolver)12 ResolveContext (org.osgi.service.resolver.ResolveContext)10