You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2016/09/02 11:42:33 UTC
svn commit: r1758941 - in
/sling/trunk/contrib/extensions/contextaware-config/impl/src:
main/java/org/apache/sling/contextaware/config/resource/impl/
test/java/org/apache/sling/contextaware/config/resource/impl/
Author: sseifert
Date: Fri Sep 2 11:42:33 2016
New Revision: 1758941
URL: http://svn.apache.org/viewvc?rev=1758941&view=rev
Log:
SLING-6029 change add /conf suffix to /apps and /libs path, and prepare unit tests for complexer configuration hierarchies
Added:
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java (with props)
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java (with props)
Modified:
sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImpl.java
sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplTest.java
Modified: sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImpl.java?rev=1758941&r1=1758940&r2=1758941&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImpl.java (original)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/main/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImpl.java Fri Sep 2 11:42:33 2016
@@ -47,11 +47,11 @@ public class ConfigurationResourceResolv
@AttributeDefinition(name="Allowed paths",
description = "Whitelist of paths where configurations can reside in.")
- String[] allowedPaths() default {"/conf", "/apps", "/libs"};
+ String[] allowedPaths() default {"/conf", "/apps/conf", "/libs/conf"};
@AttributeDefinition(name="Fallback paths",
description = "Global fallback configurations, ordered from most specific (checked first) to least specific.")
- String[] fallbackPaths() default {"/conf/global", "/apps", "/libs"};
+ String[] fallbackPaths() default {"/conf/global", "/apps/conf", "/libs/conf"};
}
private static final String PROPERTY_CONFIG = "sling:config-ref";
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java?rev=1758941&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java Fri Sep 2 11:42:33 2016
@@ -0,0 +1,137 @@
+/*
+ * 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.contextaware.config.resource.impl;
+
+import static org.apache.sling.contextaware.config.resource.impl.TestUtils.assetResourcePaths;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.Collection;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.contextaware.config.resource.ConfigurationResourceResolver;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests with content and configurations that form a deeper nested hierarchy.
+ */
+public class ConfigurationResourceResolverImplHierarchyTest {
+
+ private static final String BUCKET = "sling:test";
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ private ConfigurationResourceResolver underTest;
+
+ private Resource site1Page1;
+ private Resource site2Page1;
+
+ @Before
+ public void setUp() {
+ underTest = context.registerInjectActivateService(new ConfigurationResourceResolverImpl());
+
+ // content resources that form a deeper hierarchy
+ context.create().resource("/content/tenant1", ImmutableMap.<String, Object>builder()
+ .put("sling:config-ref", "/conf/tenant1")
+ .build());
+ context.create().resource("/content/tenant1/region1", ImmutableMap.<String, Object>builder()
+ .put("sling:config-ref", "/conf/tenant1/region1")
+ .build());
+ context.create().resource("/content/tenant1/region1/site1", ImmutableMap.<String, Object>builder()
+ .put("sling:config-ref", "/conf/tenant1/region1/site1")
+ .build());
+ site1Page1 = context.create().resource("/content/tenant1/region1/site1/page1");
+ context.create().resource("/content/tenant1/region1/site2", ImmutableMap.<String, Object>builder()
+ .put("sling:config-ref", "/conf/tenant1/region1/site2")
+ .build());
+ site2Page1 = context.create().resource("/content/tenant1/region1/site2/page1");
+
+ // configuration
+ context.create().resource("/conf/tenant1/region1/site1/sling:test/cfgSite1");
+ context.create().resource("/conf/tenant1/region1/site1/sling:test/cfgCol/site1");
+ context.create().resource("/conf/tenant1/region1/sling:test/cfgRegion1");
+ context.create().resource("/conf/tenant1/region1/sling:test/cfgCol/region1");
+ context.create().resource("/conf/tenant1/sling:test/cfgTenant1");
+ context.create().resource("/conf/tenant1/sling:test/cfgCol/tenant1");
+ context.create().resource("/conf/tenant1/sling:test/test");
+ context.create().resource("/conf/global/sling:test/cfgGlobal");
+ context.create().resource("/conf/global/sling:test/cfgCol/confGlobal");
+ context.create().resource("/conf/global/sling:test/test");
+ context.create().resource("/apps/conf/sling:test/cfgAppsGlobal");
+ context.create().resource("/apps/conf/sling:test/cfgCol/appsGlobal");
+ context.create().resource("/apps/conf/sling:test/test");
+ context.create().resource("/libs/conf/sling:test/cfgLibsGlobal");
+ context.create().resource("/libs/conf/sling:test/cfgCol/libsGlobal1");
+ context.create().resource("/libs/conf/sling:test/cfgCol/libsGlobal2");
+ context.create().resource("/libs/conf/sling:test/test");
+ }
+
+ @Test
+ @Ignore // TODO: impl. does not yet match the test
+ public void testGetResource() {
+ assertEquals("/conf/tenant1/region1/site1/sling:test/cfgSite1", underTest.getResource(site1Page1, BUCKET, "cfgSite1").getPath());
+ assertEquals("/conf/tenant1/region1/sling:test/cfgRegion1", underTest.getResource(site1Page1, BUCKET, "cfgRegion1").getPath());
+ assertEquals("/conf/tenant1/sling:test/cfgTenant1", underTest.getResource(site1Page1, BUCKET, "cfgTenant1").getPath());
+ assertEquals("/conf/global/sling:test/cfgGloba", underTest.getResource(site1Page1, BUCKET, "cfgGlobal").getPath());
+ assertEquals("/apps/conf/sling:test/cfgAppsGlobal", underTest.getResource(site1Page1, BUCKET, "cfgAppsGlobal").getPath());
+ assertEquals("/libs/conf/sling:test/cfgLibsGlobal", underTest.getResource(site1Page1, BUCKET, "cfgLibsGlobal").getPath());
+ assertEquals("/conf/tenant1/sling:test/test", underTest.getResource(site1Page1, BUCKET, "test").getPath());
+
+ assertNull(underTest.getResource(site2Page1, BUCKET, "cfgSite1").getPath());
+ assertEquals("/conf/tenant1/region1/sling:test/cfgRegion1", underTest.getResource(site2Page1, BUCKET, "cfgRegion1").getPath());
+ assertEquals("/conf/tenant1/sling:test/cfgTenant1", underTest.getResource(site2Page1, BUCKET, "cfgTenant1").getPath());
+ assertEquals("/conf/global/sling:test/cfgGloba", underTest.getResource(site2Page1, BUCKET, "cfgGlobal").getPath());
+ assertEquals("/apps/conf/sling:test/cfgAppsGlobal", underTest.getResource(site2Page1, BUCKET, "cfgAppsGlobal").getPath());
+ assertEquals("/libs/conf/sling:test/cfgLibsGlobal", underTest.getResource(site2Page1, BUCKET, "cfgLibsGlobal").getPath());
+ assertEquals("/conf/tenant1/sling:test/test", underTest.getResource(site2Page1, BUCKET, "test").getPath());
+ }
+
+ @Test
+ @Ignore // TODO: impl. does not yet match the test
+ public void testGetResourceCollection() {
+ Collection<Resource> col1 = underTest.getResourceCollection(site1Page1, BUCKET, "cfgCol");
+ assetResourcePaths(new String[] {
+ "/conf/tenant1/region1/site1/sling:test/cfgCol/site1",
+ "/conf/tenant1/region1/sling:test/cfgCol/region1",
+ "/conf/tenant1/sling:test/cfgCol/tenant1",
+ "/conf/global/sling:test/cfgCol/confGlobal",
+ "/apps/conf/sling:test/cfgCol/appsGlobal",
+ "/libs/conf/sling:test/cfgCol/libsGlobal1",
+ "/libs/conf/sling:test/cfgCol/libsGlobal2" },
+ col1);
+
+ Collection<Resource> col2 = underTest.getResourceCollection(site2Page1, BUCKET, "cfgCol");
+ assetResourcePaths(new String[] {
+ "/conf/tenant1/region1/sling:test/cfgCol/region1",
+ "/conf/tenant1/sling:test/cfgCol/tenant1",
+ "/conf/global/sling:test/cfgCol/confGlobal",
+ "/apps/conf/sling:test/cfgCol/appsGlobal",
+ "/libs/conf/sling:test/cfgCol/libsGlobal1",
+ "/libs/conf/sling:test/cfgCol/libsGlobal2" },
+ col2);
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Sep 2 11:42:33 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplHierarchyTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplTest.java?rev=1758941&r1=1758940&r2=1758941&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplTest.java (original)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/ConfigurationResourceResolverImplTest.java Fri Sep 2 11:42:33 2016
@@ -18,11 +18,10 @@
*/
package org.apache.sling.contextaware.config.resource.impl;
-import static org.junit.Assert.assertArrayEquals;
+import static org.apache.sling.contextaware.config.resource.impl.TestUtils.assetResourcePaths;
import static org.junit.Assert.assertEquals;
import java.util.Collection;
-import java.util.Iterator;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.contextaware.config.resource.ConfigurationResourceResolver;
@@ -59,21 +58,21 @@ public class ConfigurationResourceResolv
.put("sling:config-ref", "/conf/site2")
.build());
site2Page1 = context.create().resource("/content/site2/page1");
-
+
// configuration
- context.create().resource("/libs/sling:test/test");
context.create().resource("/conf/site1/sling:test/test");
- context.create().resource("/apps/sling:test/feature/a");
- context.create().resource("/libs/sling:test/feature/b");
context.create().resource("/conf/site1/sling:test/feature/c");
context.create().resource("/conf/site2/sling:test/feature/c");
context.create().resource("/conf/site2/sling:test/feature/d");
+ context.create().resource("/apps/conf/sling:test/feature/a");
+ context.create().resource("/libs/conf/sling:test/test");
+ context.create().resource("/libs/conf/sling:test/feature/b");
}
@Test
public void testGetResource() {
assertEquals("/conf/site1/sling:test/test", underTest.getResource(site1Page1, BUCKET, "test").getPath());
- assertEquals("/libs/sling:test/test", underTest.getResource(site2Page1, BUCKET, "test").getPath());
+ assertEquals("/libs/conf/sling:test/test", underTest.getResource(site2Page1, BUCKET, "test").getPath());
}
@Test
@@ -81,16 +80,16 @@ public class ConfigurationResourceResolv
Collection<Resource> col1 = underTest.getResourceCollection(site1Page1, BUCKET, "feature");
assetResourcePaths(new String[] {
"/conf/site1/sling:test/feature/c",
- "/apps/sling:test/feature/a",
- "/libs/sling:test/feature/b" },
+ "/apps/conf/sling:test/feature/a",
+ "/libs/conf/sling:test/feature/b" },
col1);
Collection<Resource> col2 = underTest.getResourceCollection(site2Page1, BUCKET, "feature");
assetResourcePaths(new String[] {
"/conf/site2/sling:test/feature/c",
"/conf/site2/sling:test/feature/d",
- "/apps/sling:test/feature/a",
- "/libs/sling:test/feature/b" },
+ "/apps/conf/sling:test/feature/a",
+ "/libs/conf/sling:test/feature/b" },
col2);
}
@@ -106,13 +105,4 @@ public class ConfigurationResourceResolv
assertEquals(ImmutableList.of("/content/site2"), underTest.getAllContextPaths(site2Page1));
}
- private void assetResourcePaths(String[] expectedPaths, Collection<Resource> actualResources) {
- String[] actualPaths = new String[actualResources.size()];
- int i = 0;
- for (Iterator<Resource> it=actualResources.iterator(); it.hasNext(); i++) {
- actualPaths[i] = it.next().getPath();
- }
- assertArrayEquals(expectedPaths, actualPaths);
- }
-
}
Added: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java?rev=1758941&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java (added)
+++ sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java Fri Sep 2 11:42:33 2016
@@ -0,0 +1,43 @@
+/*
+ * 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.contextaware.config.resource.impl;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.sling.api.resource.Resource;
+
+final class TestUtils {
+
+ private TestUtils() {
+ // static methods only
+ }
+
+ public static void assetResourcePaths(String[] expectedPaths, Collection<Resource> actualResources) {
+ String[] actualPaths = new String[actualResources.size()];
+ int i = 0;
+ for (Iterator<Resource> it=actualResources.iterator(); it.hasNext(); i++) {
+ actualPaths[i] = it.next().getPath();
+ }
+ assertArrayEquals(expectedPaths, actualPaths);
+ }
+
+}
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Sep 2 11:42:33 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/contrib/extensions/contextaware-config/impl/src/test/java/org/apache/sling/contextaware/config/resource/impl/TestUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain