This is an automated email from the ASF dual-hosted git repository. davidb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git
commit d871433d5ef623094f997d12ee2e3d987eaef191 Author: David Bosschaert <[email protected]> AuthorDate: Mon Nov 5 16:30:49 2018 +0000 Additional unit tests for the apiregions runtime component. --- .../sling/feature/apiregions/impl/ResolverHookImpl.java | 5 +++-- .../feature/apiregions/impl/ResolverHookImplTest.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java index 4939961..ae446cd 100644 --- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java +++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java @@ -75,8 +75,8 @@ class ResolverHookImpl implements ResolverHook { String reqBundleName = reqBundle.getSymbolicName(); Version reqBundleVersion = reqBundle.getVersion(); - List<String> reqFeatures = new ArrayList<>(); Set<String> reqRegions = new HashSet<>(); + List<String> reqFeatures = new ArrayList<>(); List<String> aids = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(reqBundleName, reqBundleVersion)); if (aids != null) { for (String aid : aids) { @@ -120,7 +120,8 @@ class ResolverHookImpl implements ResolverHook { List<String> capBundleArtifacts = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(capBundleName, capBundleVersion)); if (capBundleArtifacts == null) - return; // TODO what to do? + return; // Capability is not in any feature, everyone can access + List<String> capFeatures = new ArrayList<>(); for (String ba : capBundleArtifacts) { Set<String> capfeats = bundleFeatureMap.get(ba); diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java index 2127804..c27ccd4 100644 --- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java +++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java @@ -141,6 +141,13 @@ public class ResolverHookImplTest { rh.filterMatches(req5, c5); assertEquals(Collections.singletonList(bc5), c5); + // Check that we cannot get at a capability in a region from a bundle not in a feature + BundleRequirement req6 = mockRequirement(6, "bundle.not.in.feature", new Version(2,0,0)); + BundleCapability bc6 = mockCapability("org.foo", "b9", bsnvermap); + Collection<BundleCapability> c6 = new ArrayList<>(Arrays.asList(bc6)); + rh.filterMatches(req6, c6); + assertEquals(0, c6.size()); + // Check that capabilities in non-package namespaces are ignored BundleRequirement req7 = Mockito.mock(BundleRequirement.class); Mockito.when(req7.getNamespace()).thenReturn("some.other.namespace"); @@ -186,6 +193,13 @@ public class ResolverHookImplTest { Collection<BundleCapability> c12 = new ArrayList<>(Arrays.asList(bc12)); rh.filterMatches(req12, c12); assertEquals(Collections.singletonList(bc12), c12); + + // Check that anyone can get a capability from a bundle not in a feature + BundleRequirement req13 = mockRequirement("b9", bsnvermap); + BundleCapability bc13 = mockCapability("some.package", 999, "no.in.any.feature", new Version(1,0,0)); + Collection<BundleCapability> c13 = new ArrayList<>(Arrays.asList(bc13)); + rh.filterMatches(req13, c13); + assertEquals(Collections.singletonList(bc13), c13); } private BundleCapability mockCapability(String pkgName, String bid, Map<Entry<String, Version>, List<String>> bsnvermap) {
