Search in sources :

Example 21 with Resolver

use of org.osgi.service.resolver.Resolver 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 22 with Resolver

use of org.osgi.service.resolver.Resolver in project felix by apache.

the class ResolverTest method testScenario1.

@Test
public void testScenario1() 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 = populateScenario1(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 aRes = findResource("A", wireMap.keySet());
    List<Wire> aWires = wireMap.get(aRes);
    assertEquals(0, aWires.size());
    Resource bRes = findResource("B", wireMap.keySet());
    List<Wire> bWires = wireMap.get(bRes);
    assertEquals(1, bWires.size());
    Wire bWire = bWires.iterator().next();
    assertEquals(aRes, bWire.getProvider());
    assertEquals(bRes, bWire.getRequirer());
    Capability cap = bWire.getCapability();
    assertEquals(PackageNamespace.PACKAGE_NAMESPACE, cap.getNamespace());
    assertEquals(1, cap.getAttributes().size());
    assertEquals("foo", cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    assertEquals(0, cap.getDirectives().size());
    assertEquals(aRes, cap.getResource());
    Requirement req = bWire.getRequirement();
    assertEquals(1, req.getDirectives().size());
    assertEquals("(osgi.wiring.package=foo)", req.getDirectives().get(PackageNamespace.REQUIREMENT_FILTER_DIRECTIVE));
    assertEquals(0, req.getAttributes().size());
    assertEquals(PackageNamespace.PACKAGE_NAMESPACE, req.getNamespace());
    assertEquals(bRes, req.getResource());
}
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 23 with Resolver

use of org.osgi.service.resolver.Resolver in project felix by apache.

the class ResolverTest method testScenario3.

@Test
public void testScenario3() 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 = populateScenario3(wirings, candMap);
    ResolveContextImpl rci = new ResolveContextImpl(wirings, candMap, mandatory, Collections.<Resource>emptyList());
    Map<Resource, List<Wire>> wireMap = resolver.resolve(rci);
    assertEquals(3, wireMap.size());
    Resource cRes = findResource("C", wireMap.keySet());
    List<Wire> cWires = wireMap.get(cRes);
    assertEquals(0, cWires.size());
    Resource dRes = findResource("D", wireMap.keySet());
    List<Wire> dWires = wireMap.get(dRes);
    assertEquals(1, dWires.size());
    Wire dWire = dWires.iterator().next();
    assertEquals(cRes, dWire.getProvider());
    assertEquals(dRes, dWire.getRequirer());
    Capability dwCap = dWire.getCapability();
    assertEquals(PackageNamespace.PACKAGE_NAMESPACE, dwCap.getNamespace());
    assertEquals(1, dwCap.getAttributes().size());
    assertEquals("resources", dwCap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
    assertEquals(0, dwCap.getDirectives().size());
    assertEquals(cRes, dwCap.getResource());
    Resource eRes = findResource("E", wireMap.keySet());
    List<Wire> eWires = wireMap.get(eRes);
    assertEquals(2, eWires.size());
    boolean foundC = false;
    boolean foundD = false;
    for (Wire w : eWires) {
        assertEquals(eRes, w.getRequirer());
        Capability cap = w.getCapability();
        if (cap.getNamespace().equals(PackageNamespace.PACKAGE_NAMESPACE)) {
            assertEquals("resources", cap.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE));
            assertEquals(0, cap.getDirectives().size());
            assertEquals(cRes, cap.getResource());
            foundC = true;
            Requirement req = w.getRequirement();
            assertEquals(PackageNamespace.PACKAGE_NAMESPACE, req.getNamespace());
            assertEquals(eRes, req.getResource());
            assertEquals(0, req.getAttributes().size());
            assertEquals(1, req.getDirectives().size());
            assertEquals("(osgi.wiring.package=resources)", req.getDirectives().get("filter"));
        } else if (cap.getNamespace().equals(BundleNamespace.BUNDLE_NAMESPACE)) {
            assertEquals("D", cap.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE));
            assertEquals(1, cap.getDirectives().size());
            assertEquals("resources", cap.getDirectives().get(Namespace.CAPABILITY_USES_DIRECTIVE));
            assertEquals(dRes, cap.getResource());
            foundD = true;
            Requirement req = w.getRequirement();
            assertEquals(BundleNamespace.BUNDLE_NAMESPACE, req.getNamespace());
            assertEquals(eRes, req.getResource());
            assertEquals(0, req.getAttributes().size());
            assertEquals(1, req.getDirectives().size());
            assertEquals("(osgi.wiring.bundle=D)", req.getDirectives().get("filter"));
        }
    }
    assertTrue(foundC);
    assertTrue(foundD);
}
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 24 with Resolver

use of org.osgi.service.resolver.Resolver 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 25 with Resolver

use of org.osgi.service.resolver.Resolver 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)

Aggregations

Resolver (org.osgi.service.resolver.Resolver)29 ArrayList (java.util.ArrayList)24 Resource (org.osgi.resource.Resource)24 List (java.util.List)22 Requirement (org.osgi.resource.Requirement)22 Capability (org.osgi.resource.Capability)16 HashMap (java.util.HashMap)15 ResolverImpl (org.apache.felix.resolver.ResolverImpl)15 Logger (org.apache.felix.resolver.Logger)12 ResolveContextImpl (org.apache.felix.resolver.test.util.ResolveContextImpl)11 Wire (org.osgi.resource.Wire)11 BundleCapability (org.apache.felix.resolver.test.util.BundleCapability)10 BundleRequirement (org.apache.felix.resolver.test.util.BundleRequirement)10 GenericCapability (org.apache.felix.resolver.test.util.GenericCapability)10 GenericRequirement (org.apache.felix.resolver.test.util.GenericRequirement)10 PackageCapability (org.apache.felix.resolver.test.util.PackageCapability)10 PackageRequirement (org.apache.felix.resolver.test.util.PackageRequirement)10 Test (org.junit.Test)10 Wiring (org.osgi.resource.Wiring)10 Repository (org.osgi.service.repository.Repository)8