aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1688208 - in /aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal: RepositoryServiceRepositoryTest.java TestCapability.java sub/ sub/Creator.java sub/SubTestRepository.java
Date Mon, 29 Jun 2015 13:30:03 GMT
Author: davidb
Date: Mon Jun 29 13:30:03 2015
New Revision: 1688208

URL: http://svn.apache.org/r1688208
Log:
ARIES-1339 IllegalAccessException when installing a new subsystem

Additional unit tests.

Added:
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/TestCapability.java
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/Creator.java
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/SubTestRepository.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/RepositoryServiceRepositoryTest.java

Modified: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/RepositoryServiceRepositoryTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/RepositoryServiceRepositoryTest.java?rev=1688208&r1=1688207&r2=1688208&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/RepositoryServiceRepositoryTest.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/RepositoryServiceRepositoryTest.java
Mon Jun 29 13:30:03 2015
@@ -20,6 +20,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.aries.subsystem.core.internal.sub.Creator;
 import org.easymock.EasyMock;
 import org.junit.Test;
 import org.osgi.framework.BundleContext;
@@ -39,16 +40,21 @@ public class RepositoryServiceRepository
         ServiceReference<Object> sr = EasyMock.createMock(ServiceReference.class);
         @SuppressWarnings("unchecked")
         ServiceReference<Object> sr2 = EasyMock.createMock(ServiceReference.class);
+        @SuppressWarnings("unchecked")
+        ServiceReference<Object> sr3 = EasyMock.createMock(ServiceReference.class);
+
         EasyMock.expect(bc.getAllServiceReferences("org.osgi.service.repository.Repository",
null)).
-            andReturn(new ServiceReference[] {sr, sr2}).anyTimes();
+            andReturn(new ServiceReference[] {sr, sr2, sr3}).anyTimes();
 
         TestRepository tr = new TestRepository();
         EasyMock.expect(bc.getService(sr)).andReturn(tr).anyTimes();
 
         ToastRepository tr2 = new ToastRepository();
         EasyMock.expect(bc.getService(sr2)).andReturn(tr2).anyTimes();
-        EasyMock.replay(bc);
 
+        Repository tr3 = Creator.create();
+        EasyMock.expect(bc.getService(sr3)).andReturn(tr3).anyTimes();
+        EasyMock.replay(bc);
 
         Map<String, String> dirs = Collections.singletonMap("filter", "(org.foo=bar)");
         Requirement req = new TestRequirement("org.foo", dirs);
@@ -67,6 +73,15 @@ public class RepositoryServiceRepository
         assertEquals("poing", cap2.getNamespace());
         assertEquals(1, cap2.getAttributes().size());
         assertEquals("b", cap2.getAttributes().get("org.foo"));
+
+        Map<String, String> dirs3 = Collections.singletonMap("filter", "(x=y)");
+        Requirement req3 = new TestRequirement("ns1", dirs3);
+        Collection<Capability> res3 = rsr.findProviders(req3);
+        assertEquals(1, res3.size());
+        Capability cap3 = res3.iterator().next();
+        assertEquals("ns1", cap3.getNamespace());
+        assertEquals(1, cap3.getAttributes().size());
+        assertEquals("y", cap3.getAttributes().get("x"));
     }
 
     private static class TestRequirement implements Requirement {
@@ -94,36 +109,6 @@ public class RepositoryServiceRepository
         }
 
         @Override
-        public Resource getResource() {
-            return null;
-        }
-    }
-
-    private static class TestCapability implements Capability {
-        private final String namespace;
-        private final Map<String, Object> attributes;
-
-        private TestCapability(String ns, Map<String, Object> attrs) {
-            namespace = ns;
-            attributes = attrs;
-        }
-
-        @Override
-        public String getNamespace() {
-            return namespace;
-        }
-
-        @Override
-        public Map<String, String> getDirectives() {
-            return Collections.emptyMap();
-        }
-
-        @Override
-        public Map<String, Object> getAttributes() {
-            return attributes;
-        }
-
-        @Override
         public Resource getResource() {
             return null;
         }

Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/TestCapability.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/TestCapability.java?rev=1688208&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/TestCapability.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/TestCapability.java
Mon Jun 29 13:30:03 2015
@@ -0,0 +1,50 @@
+/*
+ * Licensed 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.aries.subsystem.core.internal;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.osgi.resource.Capability;
+import org.osgi.resource.Resource;
+
+public class TestCapability implements Capability {
+    private final String namespace;
+    private final Map<String, Object> attributes;
+
+    public TestCapability(String ns, Map<String, Object> attrs) {
+        namespace = ns;
+        attributes = attrs;
+    }
+
+    @Override
+    public String getNamespace() {
+        return namespace;
+    }
+
+    @Override
+    public Map<String, String> getDirectives() {
+        return Collections.emptyMap();
+    }
+
+    @Override
+    public Map<String, Object> getAttributes() {
+        return attributes;
+    }
+
+    @Override
+    public Resource getResource() {
+        return null;
+    }
+}
\ No newline at end of file

Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/Creator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/Creator.java?rev=1688208&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/Creator.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/Creator.java
Mon Jun 29 13:30:03 2015
@@ -0,0 +1,22 @@
+/*
+ * Licensed 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.aries.subsystem.core.internal.sub;
+
+import org.osgi.service.repository.Repository;
+
+public class Creator {
+    public static Repository create() {
+        return new SubTestRepository();
+    }
+}

Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/SubTestRepository.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/SubTestRepository.java?rev=1688208&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/SubTestRepository.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/sub/SubTestRepository.java
Mon Jun 29 13:30:03 2015
@@ -0,0 +1,43 @@
+/*
+ * Licensed 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.aries.subsystem.core.internal.sub;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.subsystem.core.internal.TestCapability;
+import org.osgi.resource.Capability;
+import org.osgi.resource.Requirement;
+import org.osgi.service.repository.Repository;
+
+// It is important for the test that this class it non-public
+class SubTestRepository implements Repository {
+    @Override
+    public Map<Requirement, Collection<Capability>> findProviders(Collection<?
extends Requirement> requirements) {
+        Map<Requirement, Collection<Capability>> res = new HashMap<Requirement,
Collection<Capability>>();
+
+        for (Requirement req : requirements) {
+            if (req.getNamespace().equals("ns1") &&
+                    req.getDirectives().equals(Collections.singletonMap("filter", "(x=y)")))
{
+                TestCapability cap = new TestCapability("ns1",
+                        Collections.<String, Object>singletonMap("x", "y"));
+                Collection<Capability> caps = Collections.<Capability>singleton(cap);
+                res.put(req, caps);
+            }
+        }
+        return res;
+    }
+}
\ No newline at end of file



Mime
View raw message