Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CD2E3104AD for ; Mon, 3 Feb 2014 11:31:33 +0000 (UTC) Received: (qmail 90210 invoked by uid 500); 3 Feb 2014 11:31:33 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 90071 invoked by uid 500); 3 Feb 2014 11:31:32 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 90034 invoked by uid 99); 3 Feb 2014 11:31:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2014 11:31:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Feb 2014 11:31:15 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F3DA82388994; Mon, 3 Feb 2014 11:30:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1563841 [2/2] - in /felix/trunk/bundlerepository: ./ src/main/java/org/apache/felix/bundlerepository/ src/main/java/org/apache/felix/bundlerepository/impl/ src/test/java/org/apache/felix/bundlerepository/impl/ src/test/resources/ src/test/... Date: Mon, 03 Feb 2014 11:30:50 -0000 To: commits@felix.apache.org From: davidb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140203113051.F3DA82388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java?rev=1563841&view=auto ============================================================================== --- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java (added) +++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryImplTest.java Mon Feb 3 11:30:49 2014 @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.bundlerepository.impl; + +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +import org.apache.felix.utils.log.Logger; +import org.mockito.Mockito; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Version; +import org.osgi.framework.namespace.IdentityNamespace; +import org.osgi.resource.Capability; +import org.osgi.resource.Requirement; +import org.osgi.resource.Resource; +import org.osgi.service.repository.ContentNamespace; +import org.osgi.service.repository.Repository; + +public class OSGiRepositoryImplTest extends TestCase +{ + public void testIdentityAndContentCapabilities() throws Exception + { + RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); + URL url = getClass().getResource("/another_repository.xml"); + repoAdmin.addRepository(url); + + Repository repo = new OSGiRepositoryImpl(repoAdmin); + Requirement req = new OSGiRequirementImpl("osgi.identity", null); + + Map> result = repo.findProviders(Collections.singleton(req)); + assertEquals(1, result.size()); + Collection caps = result.values().iterator().next(); + assertEquals(2, caps.size()); + + Capability tf1Cap = null; + for (Capability cap : caps) + { + if ("test_file_1".equals(cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE))) { + tf1Cap = cap; + break; + } + } + + assertEquals(Version.parseVersion("1.0.0.SNAPSHOT"), tf1Cap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE)); + assertEquals(IdentityNamespace.TYPE_BUNDLE, tf1Cap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE)); + + Resource res = tf1Cap.getResource(); + assertEquals(0, res.getRequirements(null).size()); + assertEquals(1, res.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).size()); + assertEquals(1, res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).size()); + assertEquals(2, res.getCapabilities(null).size()); + + Capability contentCap = res.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).iterator().next(); + assertEquals("4b68ab3847feda7d6c62c1fbcbeebfa35eab7351ed5e78f4ddadea5df64b8015", + contentCap.getAttributes().get(ContentNamespace.CONTENT_NAMESPACE)); + assertEquals(getClass().getResource("/repo_files/test_file_1.jar").toExternalForm(), + contentCap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE)); + assertEquals(1L, contentCap.getAttributes().get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE)); + assertEquals("application/vnd.osgi.bundle", contentCap.getAttributes().get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE)); + } + + public void testIdentityCapabilityFilter() throws Exception + { + RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); + URL url = getClass().getResource("/another_repository.xml"); + repoAdmin.addRepository(url); + + Repository repo = new OSGiRepositoryImpl(repoAdmin); + Requirement req = new OSGiRequirementImpl("osgi.identity", "(osgi.identity=test_file_2)"); + + Map> result = repo.findProviders(Collections.singleton(req)); + assertEquals(1, result.size()); + Collection caps = result.values().iterator().next(); + assertEquals(1, caps.size()); + Capability cap = caps.iterator().next(); + + assertEquals("test_file_2", cap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); + assertEquals(Version.parseVersion("1.0.0"), cap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE)); + assertEquals(IdentityNamespace.TYPE_BUNDLE, cap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE)); + } + + public void testFilterOnCapability() throws Exception + { + RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); + URL url = getClass().getResource("/another_repository.xml"); + repoAdmin.addRepository(url); + + Repository repo = new OSGiRepositoryImpl(repoAdmin); + Requirement req = new OSGiRequirementImpl("foo", "(someKey=someOtherVal)"); + + Map> result = repo.findProviders(Collections.singleton(req)); + assertEquals(1, result.size()); + Collection caps = result.values().iterator().next(); + assertEquals(1, caps.size()); + + Resource res = caps.iterator().next().getResource(); + assertEquals("test_file_2", + res.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).iterator().next(). + getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); + } + + public void testFilterOnCapabilityExistence() throws Exception + { + RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); + URL url = getClass().getResource("/another_repository.xml"); + repoAdmin.addRepository(url); + + Repository repo = new OSGiRepositoryImpl(repoAdmin); + Requirement req = new OSGiRequirementImpl("foo", "(someKey=*)"); + + Map> result = repo.findProviders(Collections.singleton(req)); + assertEquals(1, result.size()); + Collection caps = result.values().iterator().next(); + assertEquals(2, caps.size()); + + Set identities = new HashSet(); + for (Capability cap : caps) + { + identities.add(cap.getResource().getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE). + iterator().next().getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); + } + + Set expected = new HashSet(Arrays.asList("test_file_1", "test_file_2")); + assertEquals(expected, identities); + } + + private RepositoryAdminImpl createRepositoryAdmin() throws Exception + { + Bundle sysBundle = Mockito.mock(Bundle.class); + Mockito.when(sysBundle.getHeaders()).thenReturn(new Hashtable()); + + BundleContext bc = Mockito.mock(BundleContext.class); + Mockito.when(bc.getBundle(0)).thenReturn(sysBundle); + Mockito.when(sysBundle.getBundleContext()).thenReturn(bc); + + return new RepositoryAdminImpl(bc, new Logger(bc)); + } +} Added: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java?rev=1563841&view=auto ============================================================================== --- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java (added) +++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/OSGiRepositoryXMLTest.java Mon Feb 3 11:30:49 2014 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.bundlerepository.impl; + +import java.net.URL; +import java.util.Collection; +import java.util.Collections; +import java.util.Hashtable; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.felix.utils.log.Logger; +import org.mockito.Mockito; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Version; +import org.osgi.framework.namespace.IdentityNamespace; +import org.osgi.resource.Capability; +import org.osgi.resource.Requirement; +import org.osgi.service.repository.Repository; + +public class OSGiRepositoryXMLTest extends TestCase +{ + public void testParseStandardRepositoryXML() throws Exception + { + RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); + URL url = getClass().getResource("/spec_repository.xml"); + repoAdmin.addRepository(url); + + Repository repo = new OSGiRepositoryImpl(repoAdmin); + Requirement req = new OSGiRequirementImpl("osgi.identity", "(osgi.identity=cdi-subsystem)"); + + Map> result = repo.findProviders(Collections.singleton(req)); + assertEquals(1, result.size()); + Collection 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)); + } + + private RepositoryAdminImpl createRepositoryAdmin() throws Exception + { + Bundle sysBundle = Mockito.mock(Bundle.class); + Mockito.when(sysBundle.getHeaders()).thenReturn(new Hashtable()); + + BundleContext bc = Mockito.mock(BundleContext.class); + Mockito.when(bc.getBundle(0)).thenReturn(sysBundle); + Mockito.when(sysBundle.getBundleContext()).thenReturn(bc); + + return new RepositoryAdminImpl(bc, new Logger(bc)); + } +} Modified: felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java?rev=1563841&r1=1563840&r2=1563841&view=diff ============================================================================== --- felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java (original) +++ felix/trunk/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/RepositoryImplTest.java Mon Feb 3 11:30:49 2014 @@ -21,8 +21,10 @@ package org.apache.felix.bundlerepositor import java.net.URL; import java.util.Dictionary; import java.util.Hashtable; +import java.util.Map; import junit.framework.TestCase; + import org.apache.felix.bundlerepository.Repository; import org.apache.felix.bundlerepository.Resource; import org.apache.felix.utils.log.Logger; @@ -70,7 +72,7 @@ public class RepositoryImplTest extends URL url = getClass().getResource("/referral1_repository.xml"); RepositoryAdminImpl repoAdmin = createRepositoryAdmin(); - RepositoryImpl repo = (RepositoryImpl) repoAdmin.addRepository(url, 1); + RepositoryImpl repo = repoAdmin.addRepository(url, 1); Referral[] refs = repo.getReferrals(); assertNotNull("Expect referrals", refs); @@ -92,8 +94,8 @@ public class RepositoryImplTest extends private RepositoryAdminImpl createRepositoryAdmin() throws Exception { - BundleContext bundleContext = (BundleContext) EasyMock.createMock(BundleContext.class); - Bundle systemBundle = (Bundle) EasyMock.createMock(Bundle.class); + BundleContext bundleContext = EasyMock.createMock(BundleContext.class); + Bundle systemBundle = EasyMock.createMock(Bundle.class); Activator.setContext(bundleContext); EasyMock.expect(bundleContext.getProperty((String) EasyMock.anyObject())).andReturn(null).anyTimes(); @@ -115,6 +117,9 @@ public class RepositoryImplTest extends public boolean matchCase(Dictionary dictionary) { return true; } + public boolean matches(Map map) { + return true; + } }).anyTimes(); EasyMock.replay(new Object[] { bundleContext, systemBundle }); Added: felix/trunk/bundlerepository/src/test/resources/another_repository.xml URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/resources/another_repository.xml?rev=1563841&view=auto ============================================================================== --- felix/trunk/bundlerepository/src/test/resources/another_repository.xml (added) +++ felix/trunk/bundlerepository/src/test/resources/another_repository.xml Mon Feb 3 11:30:49 2014 @@ -0,0 +1,81 @@ + + + + + + 1 + +

+

+

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+ + + + + 2 + + +

+ + + Added: felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_1.jar URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_1.jar?rev=1563841&view=auto ============================================================================== --- felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_1.jar (added) +++ felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_1.jar Mon Feb 3 11:30:49 2014 @@ -0,0 +1 @@ +X \ No newline at end of file Added: felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_2.jar URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_2.jar?rev=1563841&view=auto ============================================================================== --- felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_2.jar (added) +++ felix/trunk/bundlerepository/src/test/resources/repo_files/test_file_2.jar Mon Feb 3 11:30:49 2014 @@ -0,0 +1 @@ +AB \ No newline at end of file Added: felix/trunk/bundlerepository/src/test/resources/spec_repository.xml URL: http://svn.apache.org/viewvc/felix/trunk/bundlerepository/src/test/resources/spec_repository.xml?rev=1563841&view=auto ============================================================================== --- felix/trunk/bundlerepository/src/test/resources/spec_repository.xml (added) +++ felix/trunk/bundlerepository/src/test/resources/spec_repository.xml Mon Feb 3 11:30:49 2014 @@ -0,0 +1,899 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +