Package org.osgi.resource

Examples of org.osgi.resource.Capability


        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
        assertEquals(1, result.size());
        Collection<Capability> caps = result.values().iterator().next();
        assertEquals(1, caps.size());
        Capability cap = caps.iterator().next();
        assertEquals("org.apache.felix.bundlerepository.test_file_3", cap.getAttributes().
                get(IdentityNamespace.IDENTITY_NAMESPACE));
    }
View Full Code Here


        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
        assertEquals(1, result.size());
        Collection<Capability> caps = result.values().iterator().next();
        assertEquals(1, caps.size());
        Capability cap = caps.iterator().next();

        assertEquals("foo", cap.getNamespace());
        assertEquals(0, cap.getDirectives().size());
        assertEquals(1, cap.getAttributes().size());
        Entry<String, Object> fooCap = cap.getAttributes().entrySet().iterator().next();
        assertEquals("bar", fooCap.getKey());
        assertEquals("toast", fooCap.getValue());

        Resource res = cap.getResource();
        List<Capability> idCaps = res.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
        assertEquals(1, idCaps.size());
        Capability idCap = idCaps.iterator().next();

        assertEquals("org.apache.felix.bundlerepository.test_file_3", idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE));
        assertEquals(Version.parseVersion("1.2.3.something"), idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE));
        assertEquals("osgi.bundle", idCap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE));

        List<Capability> contentCaps = res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE);
        assertEquals(1, contentCaps.size());
        Capability contentCap = contentCaps.iterator().next();

        assertEquals("b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78",
            contentCap.getAttributes().get(ContentNamespace.CONTENT_NAMESPACE));
        assertEquals(new Long(3), contentCap.getAttributes().get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE));
        assertEquals("application/vnd.osgi.bundle", contentCap.getAttributes().get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE));

        URL fileURL = getClass().getResource("/repo_files/test_file_3.jar");
        byte[] expectedBytes = Streams.suck(fileURL.openStream());

        String resourceURL = (String) contentCap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
        byte[] actualBytes = Streams.suck(new URL(resourceURL).openStream());
        assertEquals(3L, actualBytes.length);
        assertTrue(Arrays.equals(expectedBytes, actualBytes));
    }
View Full Code Here

    }

    @Override
    public String toString()
    {
        Capability c = getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next();
        Map<String, Object> atts = c.getAttributes();
        return new StringBuilder().append(atts.get(IdentityNamespace.IDENTITY_NAMESPACE)).append(';')
                .append(atts.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE)).append(';')
                .append(atts.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE)).toString();
    }
View Full Code Here

                defaultAttribute(orgMap, converted, BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE,
                    orgMap.get(org.apache.felix.bundlerepository.Resource.VERSION));
            }
            else if (PackageNamespace.PACKAGE_NAMESPACE.equals(getNamespace()))
            {
                Capability bundleCap = getBundleCapability();
                if (bundleCap != null)
                {
                    defaultAttribute(orgMap, converted, PackageNamespace.CAPABILITY_BUNDLE_SYMBOLICNAME_ATTRIBUTE,
                        bundleCap.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE));
                    defaultAttribute(orgMap, converted, PackageNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE,
                        bundleCap.getAttributes().get(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
                }
            }
            convertedAttributes = converted;
        }
        return convertedAttributes;
View Full Code Here

    {
        if (o == this)
            return true;
        if (!(o instanceof Capability))
            return false;
        Capability c = (Capability) o;
        return c.getNamespace().equals(getNamespace()) && c.getAttributes().equals(getAttributes())
                && c.getDirectives().equals(getDirectives()) && c.getResource().equals(getResource());
    }
View Full Code Here

        assertEquals(1, bwbCaps.size());

        Map<String, Object> expectedBWBAttrs = new HashMap<String, Object>();
        expectedBWBAttrs.put("osgi.wiring.bundle", "cap.bundle");
        expectedBWBAttrs.put("bundle-version", Version.parseVersion("1.2.3.Blah"));
        Capability expectedBWBCap = new TestCapability("osgi.wiring.bundle",
                expectedBWBAttrs, Collections.<String, String>emptyMap());
        assertCapsEquals(expectedBWBCap, bwbCaps.get(0));

        List<Capability> bwhCaps = bbr.getCapabilities("osgi.wiring.host");
        assertEquals(1, bwhCaps.size());

        Map<String, Object> expectedBWHAttrs = new HashMap<String, Object>();
        expectedBWHAttrs.put("osgi.wiring.host", "cap.bundle");
        expectedBWHAttrs.put("bundle-version", Version.parseVersion("1.2.3.Blah"));
        Capability expectedBWHCap = new TestCapability("osgi.wiring.host",
                expectedBWHAttrs, Collections.<String, String>emptyMap());
        assertCapsEquals(expectedBWHCap, bwhCaps.get(0));

        List<Capability> bwiCaps = bbr.getCapabilities("osgi.identity");
        assertEquals(1, bwiCaps.size());

        Map<String, Object> expectedBWIAttrs = new HashMap<String, Object>();
        expectedBWIAttrs.put("osgi.identity", "cap.bundle");
        expectedBWIAttrs.put("type", "osgi.bundle");
        expectedBWIAttrs.put("version", Version.parseVersion("1.2.3.Blah"));
        Capability expectedBWICap = new TestCapability("osgi.identity",
                expectedBWIAttrs, Collections.<String, String>emptyMap());
        assertCapsEquals(expectedBWICap, bwiCaps.get(0));

        assertEquals("The Bundle should not directly expose osgi.wiring.package",
                0, bbr.getCapabilities("osgi.wiring.package").size());

        // Check the fragment's capabilities.
        // First check the capabilities on the Bundle Revision, which is available on installed fragments
        BundleRevision fbr = f.adapt(BundleRevision.class);
        List<Capability> fwpCaps = fbr.getCapabilities("osgi.wiring.package");
        assertEquals(1, fwpCaps.size());

        Map<String, Object> expectedFWAttrs = new HashMap<String, Object>();
        expectedFWAttrs.put("osgi.wiring.package", "org.foo.bar");
        expectedFWAttrs.put("version", Version.parseVersion("2"));
        expectedFWAttrs.put("bundle-symbolic-name", "cap.frag");
        expectedFWAttrs.put("bundle-version", Version.parseVersion("1.0.0"));
        Capability expectedFWCap = new TestCapability("osgi.wiring.package",
                expectedFWAttrs, Collections.<String, String>emptyMap());
        assertCapsEquals(expectedFWCap, fwpCaps.get(0));

        List<Capability> fiCaps = fbr.getCapabilities("osgi.identity");
        assertEquals(1, fiCaps.size());
        Map<String, Object> expectedFIAttrs = new HashMap<String, Object>();
        expectedFIAttrs.put("osgi.identity", "cap.frag");
        expectedFIAttrs.put("type", "osgi.fragment");
        expectedFIAttrs.put("version", Version.parseVersion("1.0.0"));
        Capability expectedFICap = new TestCapability("osgi.identity",
                expectedFIAttrs, Collections.<String, String>emptyMap());
        assertCapsEquals(expectedFICap, fiCaps.get(0));

        // Start the bundle. This will make the BundleWiring available on both the bundle and the fragment
        b.start();
View Full Code Here

        assertEquals(1, feCaps.size());
        Map<String, Object> expectedFEAttrs = new HashMap<String, Object>();
        expectedFEAttrs.put("osgi.identity", "fram.ext");
        expectedFEAttrs.put("type", "osgi.fragment");
        expectedFEAttrs.put("version", Version.parseVersion("1.2.3.test"));
        Capability expectedFICap = new TestCapability("osgi.identity",
                expectedFEAttrs, Collections.<String, String>emptyMap());
        assertCapsEquals(expectedFICap, feCaps.get(0));
    }
View Full Code Here

        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
        assertEquals(1, result.size());
        Collection<Capability> caps = result.values().iterator().next();
        assertEquals(1, caps.size());
        Capability cap = caps.iterator().next();

        assertEquals("cdi-subsystem", cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE));
        assertEquals(Version.parseVersion("0.5.0"), cap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE));
        assertEquals("osgi.subsystem.feature", cap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE));
    }
View Full Code Here

        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
        assertEquals(1, result.size());
        Collection<Capability> caps = result.values().iterator().next();
        assertEquals(1, caps.size());
        Capability cap = caps.iterator().next();
        assertEquals("org.apache.felix.bundlerepository.test_file_3", cap.getAttributes().
                get(IdentityNamespace.IDENTITY_NAMESPACE));
    }
View Full Code Here

        Map<Requirement, Collection<Capability>> result = repo.findProviders(Collections.singleton(req));
        assertEquals(1, result.size());
        Collection<Capability> caps = result.values().iterator().next();
        assertEquals(1, caps.size());
        Capability cap = caps.iterator().next();

        assertEquals("foo", cap.getNamespace());
        assertEquals(0, cap.getDirectives().size());
        assertEquals(1, cap.getAttributes().size());
        Entry<String, Object> fooCap = cap.getAttributes().entrySet().iterator().next();
        assertEquals("bar", fooCap.getKey());
        assertEquals("toast", fooCap.getValue());

        Resource res = cap.getResource();
        List<Capability> idCaps = res.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
        assertEquals(1, idCaps.size());
        Capability idCap = idCaps.iterator().next();

        assertEquals("org.apache.felix.bundlerepository.test_file_3", idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE));
        assertEquals(Version.parseVersion("1.2.3.something"), idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE));
        assertEquals("osgi.bundle", idCap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE));

        List<Capability> contentCaps = res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE);
        assertEquals(1, contentCaps.size());
        Capability contentCap = contentCaps.iterator().next();

        assertEquals("b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78",
            contentCap.getAttributes().get(ContentNamespace.CONTENT_NAMESPACE));
        assertEquals(new Long(3), contentCap.getAttributes().get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE));
        assertEquals("application/vnd.osgi.bundle", contentCap.getAttributes().get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE));

        URL fileURL = getClass().getResource("/repo_files/test_file_3.jar");
        byte[] expectedBytes = Streams.suck(fileURL.openStream());

        String resourceURL = (String) contentCap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
        byte[] actualBytes = Streams.suck(new URL(resourceURL).openStream());
        assertEquals(3L, actualBytes.length);
        assertTrue(Arrays.equals(expectedBytes, actualBytes));
    }
View Full Code Here

TOP

Related Classes of org.osgi.resource.Capability

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.