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 19064115ea2bf5ad34074709417ab56ab7f4ddbf Author: David Bosschaert <[email protected]> AuthorDate: Sat Nov 3 12:01:14 2018 +0000 Unit tests for the apiregions runtime component. Remove some obsolete test code that related to the previous implementation. --- .../apiregions/impl/ResolverHookImplTest.java | 3 +- .../apiregions/impl/WhitelistEnforcerTest.java | 62 --------------------- .../impl/WhitelistServiceFactoryImplTest.java | 64 ---------------------- .../apiregions/impl/WhitelistServiceImplTest.java | 52 ------------------ 4 files changed, 1 insertion(+), 180 deletions(-) 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 c5d8ef8..eead297 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 @@ -42,16 +42,15 @@ import java.util.Set; import static org.junit.Assert.assertEquals; public class ResolverHookImplTest { - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test @Ignore public void xxtestFilterMatches() throws Exception { + /* String f = "gid:aid:0.0.9"; String f2 = "gid2:aid2:1.0.0-SNAPSHOT"; String f3 = "gid3:aid3:1.2.3"; String f4 = "gid4:aid4:1.2.3"; String f5 = "gid5:aid5:1.2.3"; - /* Features fs = Mockito.mock(Features.class); Mockito.when(fs.getFeaturesForBundle("a.b.c", new Version(0,0,0))) .thenReturn(Collections.singleton(f)); // b7 diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java deleted file mode 100644 index e83c27f..0000000 --- a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.sling.feature.apiregions.impl; - -public class WhitelistEnforcerTest { - /* - @Test - public void testWhitelistEnforcerConfigUpdate() throws ConfigurationException { - BundleContext bc = Mockito.mock(BundleContext.class); - WhitelistEnforcer enf = new WhitelistEnforcer(bc, null); - - assertNull("Precondition", enf.whitelistService); - - Dictionary<String, Object> props = new Hashtable<>(); - props.put("ignored", "ignored-too"); - props.put("whitelist.region.region1", "org.foo.pkg1"); - props.put("whitelist.region.region2", new String[] {"pkga", "pkgb"}); - props.put("whitelist.region.region.3", Arrays.asList("a.b.c", "d.e.f", "g.h.i")); - props.put("whitelist.feature.gid:aid:slingfeature:testfeature:1.0.0", WhitelistService.GLOBAL_REGION); - props.put("whitelist.feature.gid:myfeature:1.0.0", new String [] {"region1", "region2"}); - enf.updated(props); - - assertNotNull(enf.whitelistService); - Mockito.verify(bc, Mockito.times(1)).registerService( - Mockito.eq(WhitelistService.class), Mockito.isA(WhitelistService.class), Mockito.any()); - - // check that the configuration parsing worked - assertTrue(enf.whitelistService.regionWhitelistsPackage("region1", "org.foo.pkg1")); - assertTrue(enf.whitelistService.regionWhitelistsPackage("region2", "pkga")); - assertTrue(enf.whitelistService.regionWhitelistsPackage("region2", "pkgb")); - assertFalse(enf.whitelistService.regionWhitelistsPackage("region1", "pkg1")); - assertTrue(enf.whitelistService.regionWhitelistsPackage("region.3", "d.e.f")); - assertFalse(enf.whitelistService.regionWhitelistsPackage("region.3", "d.e.f.g")); - assertNull(enf.whitelistService.regionWhitelistsPackage("unknown", "pkga")); - - Set<String> regions = enf.whitelistService.listRegions("gid:myfeature:1.0.0"); - assertEquals(new HashSet<String>(Arrays.asList("region1", "region2")), regions); - assertEquals(Collections.singleton("global"), enf.whitelistService - .listRegions("gid:aid:slingfeature:testfeature:1.0.0")); - assertNull(enf.whitelistService.listRegions("unknown")); - - enf.updated(null); - assertNull("A null configuration should put back the null whitelist service", enf.whitelistService); - } - */ -} diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java deleted file mode 100644 index f9120d3..0000000 --- a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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.sling.feature.apiregions.impl; - -public class WhitelistServiceFactoryImplTest { - /* - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void testWhitelistServiceFactory() { - List<ResolverHookFactory> resolverHookFactory = new ArrayList<>(); - Map<String, Map<String, Set<String>>> wlsCfg = new HashMap<>(); - - ServiceTracker st = Mockito.mock(ServiceTracker.class); - BundleContext bc = Mockito.mock(BundleContext.class); - Mockito.when(bc.registerService(Mockito.isA(Class.class), Mockito.isA(Object.class), Mockito.isA(Dictionary.class))) - .then(i -> { resolverHookFactory.add(i.getArgument(1)); return null; }); - - WhitelistServiceFactory wsf = new WhitelistServiceFactoryImpl(bc, st) { - @Override - WhitelistService createWhitelistService(Map<String, Set<String>> packages, Map<String, Set<String>> regions) { - wlsCfg.put("packages", packages); - wlsCfg.put("regions", regions); - return super.createWhitelistService(packages, regions); - } - }; - - Map<String, Map<String, Set<String>>> m = new HashMap<>(); - Map<String, Set<String>> packages = new HashMap<>(); - packages.put("region1", new HashSet<>(Arrays.asList("org.foo", "org.bar"))); - packages.put("region2", Collections.singleton("org.foo.bar")); - m.put("packages", packages); - - Map<String, Set<String>> regions = new HashMap<>(); - regions.put("f1", new HashSet<String>(Arrays.asList("region1", "region3"))); - regions.put("f2", Collections.singleton("region2")); - regions.put("f3", Collections.singleton("region4")); - regions.put("f4", Collections.singleton("region2")); - m.put("regions", regions); - - wsf.initialize(m); - - assertEquals(wlsCfg, m); - - ResolverHookFactory rhf = resolverHookFactory.get(0); - assertTrue(rhf instanceof WhitelistEnforcer); - } - */ -} diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java deleted file mode 100644 index 832e199..0000000 --- a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.sling.feature.apiregions.impl; - -import org.junit.Ignore; -import org.junit.Test; - -public class WhitelistServiceImplTest { - @Test - @Ignore - public void testListRegions() { - /* - Map<String, Set<String>> frm = new HashMap<>(); - frm.put("myfeature", new HashSet<>(Arrays.asList("rega", "regb", "regc"))); - frm.put("myotherfeature", Collections.emptySet()); - WhitelistService wls = new WhitelistServiceImpl(Collections.emptyMap(), frm); - - assertEquals(new HashSet<>(Arrays.asList("rega", "regb", "regc")), - wls.listRegions("myfeature")); - assertEquals(0, wls.listRegions("myotherfeature").size()); - assertNull(wls.listRegions("nonexistent")); - } - - @Test - public void testRegionContainsPackage() { - Map<String, Set<String>> rpm = new HashMap<>(); - rpm.put("region1", new HashSet<>(Arrays.asList("org.foo", "org.bar", "org.foo.bar"))); - WhitelistService wls = new WhitelistServiceImpl(rpm, Collections.emptyMap()); - - assertTrue(wls.regionWhitelistsPackage("region1", "org.foo")); - assertTrue(wls.regionWhitelistsPackage("region1", "org.foo.bar")); - assertFalse(wls.regionWhitelistsPackage("region1", "org.bar.foo")); - assertNull(wls.regionWhitelistsPackage("nonexitent", "org.foo")); - */ - } -}
