change logic of resource collection inheritance - get items from all bucket names, not only from the first one. expanded buckets for different run modes do not have precedence over each other.
add unit tests
diff --git a/pom.xml b/pom.xml
index 4232c3b..31588d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,6 +127,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.settings</artifactId>
+ <version>1.3.6</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
diff --git a/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java b/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
index b8e672a..8d7bca8 100644
--- a/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
+++ b/src/main/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategy.java
@@ -360,45 +360,40 @@
final List<CollectionInheritanceDecider> deciders = this.collectionInheritanceDeciders;
final Set<String> blockedItems = new HashSet<>();
- boolean inherit = false;
while (paths.hasNext()) {
final String path = paths.next();
- Resource item = null;
- String bucketNameUsed = null;
+ boolean inherit = false;
+ boolean foundAnyParent = false;
for (String bucketName : bucketNames) {
String name = bucketName + "/" + configName;
String configPath = buildResourcePath(path, name);
- item = resourceResolver.getResource(configPath);
+ Resource item = resourceResolver.getResource(configPath);
if (item != null) {
- bucketNameUsed = bucketName;
- break;
+ log.trace("o Check children of collection parent resource: {}", item.getPath());
+ if (item.hasChildren()) {
+ for (Resource child : item.getChildren()) {
+ if (isValidResourceCollectionItem(child)
+ && !result.containsKey(child.getName())
+ && include(deciders, bucketName, child, blockedItems)) {
+ log.trace("+ Found collection resource item {}", child.getPath());
+ result.put(child.getName(), child);
+ }
+ }
+ }
+
+ // check collection inheritance mode on current level - should we check on next-highest level as well?
+ final ValueMap valueMap = item.getValueMap();
+ inherit = inherit || PropertyUtil.getBooleanValueAdditionalKeys(valueMap, PROPERTY_CONFIG_COLLECTION_INHERIT,
+ config.configCollectionInheritancePropertyNames());
+ foundAnyParent = true;
}
else {
log.trace("- No collection parent resource found: {}", configPath);
}
}
-
- if (item != null) {
- log.trace("o Check children of collection parent resource: {}", item.getPath());
- if (item.hasChildren()) {
- for (Resource child : item.getChildren()) {
- if (isValidResourceCollectionItem(child)
- && !result.containsKey(child.getName())
- && include(deciders, bucketNameUsed, child, blockedItems)) {
- log.trace("+ Found collection resource item {}", child.getPath());
- result.put(child.getName(), child);
- }
- }
- }
-
- // check collection inheritance mode on current level - should we check on next-highest level as well?
- final ValueMap valueMap = item.getValueMap();
- inherit = PropertyUtil.getBooleanValueAdditionalKeys(valueMap, PROPERTY_CONFIG_COLLECTION_INHERIT,
- config.configCollectionInheritancePropertyNames());
- if (!inherit) {
- break;
- }
+ if (foundAnyParent && !inherit) {
+ break;
}
}
diff --git a/src/test/java/org/apache/sling/caconfig/impl/def/ConfigurationResolverPropertyInheritanceRunModeTest.java b/src/test/java/org/apache/sling/caconfig/impl/def/ConfigurationResolverPropertyInheritanceRunModeTest.java
new file mode 100644
index 0000000..7cdcd3b
--- /dev/null
+++ b/src/test/java/org/apache/sling/caconfig/impl/def/ConfigurationResolverPropertyInheritanceRunModeTest.java
@@ -0,0 +1,127 @@
+/*
+ * 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.caconfig.impl.def;
+
+import static org.apache.sling.caconfig.impl.def.ConfigurationDefNameConstants.PROPERTY_CONFIG_PROPERTY_INHERIT;
+import static org.apache.sling.caconfig.resource.impl.def.ConfigurationResourceNameConstants.PROPERTY_CONFIG_REF;
+import static org.hamcrest.Matchers.allOf;
+import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.caconfig.ConfigurationResolver;
+import org.apache.sling.caconfig.impl.ConfigurationTestUtils;
+import org.apache.sling.caconfig.resource.impl.def.DefaultConfigurationResourceResolvingStrategy;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/**
+ * Test {@link ConfigurationResolver} with property inheritance and merging with runmode-aware configuration resolving strategy.
+ */
+public class ConfigurationResolverPropertyInheritanceRunModeTest {
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ private ConfigurationResolver underTest;
+
+ private Resource site1Page1;
+ private Resource site2Page1;
+
+ @Before
+ public void setUp() throws IOException {
+
+ // enable runModeAware for DefaultConfigurationResourceResolvingStrategy
+ ConfigurationAdmin configAdmin = context.getService(ConfigurationAdmin.class);
+ Configuration serviceConfig = configAdmin.getConfiguration(DefaultConfigurationResourceResolvingStrategy.class.getName());
+ Dictionary<String,Object> configProps = new Hashtable<>();
+ configProps.put("runModeAware", true);
+ serviceConfig.update(configProps);
+
+ underTest = ConfigurationTestUtils.registerConfigurationResolver(context);
+
+ // content resources that form a deeper hierarchy
+ context.build()
+ .resource("/content/tenant1", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1")
+ .resource("/content/tenant1/region1", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1/region1")
+ .resource("/content/tenant1/region1/site1", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1/region1/site1")
+ .resource("/content/tenant1/region1/site2", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1/region1/site2");
+ site1Page1 = context.create().resource("/content/tenant1/region1/site1/page1");
+ site2Page1 = context.create().resource("/content/tenant1/region1/site2/page1");
+
+ // set sample run mode
+ context.runMode("runmode1");
+ }
+
+ @Test
+ public void testInheritanceWithoutMerging() {
+ context.build()
+ .resource("/conf/global/sling:configs/test", "param1", "value1", "param2", "value2", "param3", "value3")
+ .resource("/conf/global/sling:configs.runmode1/test", "param1", "value1.1", "param2", "value2.1")
+ .resource("/conf/global/sling:configs.runmode2/test", "param1", "value1.2", "param2", "value2.2")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:configs/test", "param1", "value1a", "param3", "value3a")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:configs.runmode1/test", "param1", "value1a.1")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:configs.runmode2/test", "param1", "value1a.2")
+ .resource("/conf/brand1/tenant1/region1/site2/sling:configs/test", "param1", "value1b");
+
+ assertThat(underTest.get(site1Page1).name("test").asValueMap(), allOf(
+ hasEntry("param1", (Object)"value1a.1"),
+ not(hasKey("param2")),
+ not(hasKey("param3"))));
+ assertThat(underTest.get(site2Page1).name("test").asValueMap(), allOf(
+ hasEntry("param1", (Object)"value1b"),
+ not(hasKey("param2")),
+ not(hasKey("param3"))));
+ }
+
+ @Test
+ public void testInheritanceMerging() {
+ context.build()
+ .resource("/conf/global/sling:configs/test", "param1", "value1", "param2", "value2", "param3", "value3")
+ .resource("/conf/global/sling:configs.runmode1/test", "param1", "value1.1", "param2", "value2.1")
+ .resource("/conf/global/sling:configs.runmode2/test", "param1", "value1.2", "param2", "value2.2")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:configs/test", "param1", "value1a", "param3", "value3a",
+ PROPERTY_CONFIG_PROPERTY_INHERIT, true)
+ .resource("/conf/brand1/tenant1/region1/site1/sling:configs.runmode1/test", "param1", "value1a.1",
+ PROPERTY_CONFIG_PROPERTY_INHERIT, true)
+ .resource("/conf/brand1/tenant1/region1/site1/sling:configs.runmode2/test", "param1", "value1a.2",
+ PROPERTY_CONFIG_PROPERTY_INHERIT, true)
+ .resource("/conf/brand1/tenant1/region1/site2/sling:configs/test", "param1", "value1b");
+
+ assertThat(underTest.get(site1Page1).name("test").asValueMap(), allOf(
+ hasEntry("param1", (Object)"value1a.1"),
+ hasEntry("param2", (Object)"value2.1"),
+ not(hasKey("param3"))));
+ assertThat(underTest.get(site2Page1).name("test").asValueMap(), allOf(
+ hasEntry("param1", (Object)"value1b"),
+ not(hasKey("param2")),
+ not(hasKey("param3"))));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyRunModeTest.java b/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyRunModeTest.java
new file mode 100644
index 0000000..14a594c
--- /dev/null
+++ b/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyRunModeTest.java
@@ -0,0 +1,267 @@
+/*
+ * 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.caconfig.resource.impl.def;
+
+import static org.apache.sling.caconfig.resource.impl.def.ConfigurationResourceNameConstants.PROPERTY_CONFIG_COLLECTION_INHERIT;
+import static org.apache.sling.caconfig.resource.impl.def.ConfigurationResourceNameConstants.PROPERTY_CONFIG_REF;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.caconfig.management.impl.ContextPathStrategyMultiplexerImpl;
+import org.apache.sling.caconfig.resource.spi.ConfigurationResourceResolvingStrategy;
+import org.apache.sling.hamcrest.ResourceCollectionMatchers;
+import org.apache.sling.hamcrest.ResourceIteratorMatchers;
+import org.apache.sling.testing.mock.sling.junit.SlingContext;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Tests with content and configurations that form a deeper nested hierarchy and run-mode aware activated.
+ */
+public class DefaultConfigurationResourceResolvingStrategyHierarchyRunModeTest {
+
+ private static final String BUCKET = "sling:test";
+ private static final Collection<String> BUCKETS = Collections.singleton(BUCKET);
+ private static final String PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM = "custom:configCollectionInherit";
+
+ @Rule
+ public SlingContext context = new SlingContext();
+
+ private ConfigurationResourceResolvingStrategy underTest;
+
+ private Resource site1Page1;
+ private Resource site2Page1;
+
+ @Before
+ public void setUp() {
+ context.registerInjectActivateService(new DefaultContextPathStrategy());
+ context.registerInjectActivateService(new ContextPathStrategyMultiplexerImpl());
+ underTest = context.registerInjectActivateService(new DefaultConfigurationResourceResolvingStrategy(),
+ "configCollectionInheritancePropertyNames", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM,
+ "runModeAware", true);
+
+ // content resources that form a deeper hierarchy
+ context.build()
+ .resource("/content/tenant1", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1")
+ .resource("/content/tenant1/region1", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1/region1")
+ .resource("/content/tenant1/region1/site1", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1/region1/site1")
+ .resource("/content/tenant1/region1/site2", PROPERTY_CONFIG_REF, "/conf/brand1/tenant1/region1/site2");
+ site1Page1 = context.create().resource("/content/tenant1/region1/site1/page1");
+ site2Page1 = context.create().resource("/content/tenant1/region1/site2/page1");
+
+ // set sample run mode
+ context.runMode("runmode1");
+ }
+
+ @Test
+ public void testGetResource() {
+ context.build()
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test/cfgSite1")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test.runmode1/cfgSite1")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test.runmode2/cfgSite1")
+ .resource("/conf/brand1/tenant1/region1/sling:test/cfgRegion1")
+ .resource("/conf/brand1/tenant1/sling:test/cfgTenant1")
+ .resource("/conf/brand1/tenant1/sling:test.runmode1/cfgTenant1")
+ .resource("/conf/brand1/tenant1/sling:test/test")
+ .resource("/conf/brand1/sling:test/cfgBrand1")
+ .resource("/conf/global/sling:test/cfgGlobal")
+ .resource("/conf/global/sling:test/test")
+ .resource("/apps/conf/sling:test/cfgAppsGlobal")
+ .resource("/apps/conf/sling:test.runmode2/cfgAppsGlobal")
+ .resource("/apps/conf/sling:test/test")
+ .resource("/libs/conf/sling:test/cfgLibsGlobal")
+ .resource("/libs/conf/sling:test.runmode1/cfgLibsGlobal")
+ .resource("/libs/conf/sling:test/test");
+
+ assertEquals("/conf/brand1/tenant1/region1/site1/sling:test.runmode1/cfgSite1", underTest.getResource(site1Page1, BUCKETS, "cfgSite1").getPath());
+ assertEquals("/conf/brand1/tenant1/region1/sling:test/cfgRegion1", underTest.getResource(site1Page1, BUCKETS, "cfgRegion1").getPath());
+ assertEquals("/conf/brand1/tenant1/sling:test.runmode1/cfgTenant1", underTest.getResource(site1Page1, BUCKETS, "cfgTenant1").getPath());
+ assertEquals("/conf/brand1/sling:test/cfgBrand1", underTest.getResource(site1Page1, BUCKETS, "cfgBrand1").getPath());
+ assertEquals("/conf/global/sling:test/cfgGlobal", underTest.getResource(site1Page1, BUCKETS, "cfgGlobal").getPath());
+ assertEquals("/apps/conf/sling:test/cfgAppsGlobal", underTest.getResource(site1Page1, BUCKETS, "cfgAppsGlobal").getPath());
+ assertEquals("/libs/conf/sling:test.runmode1/cfgLibsGlobal", underTest.getResource(site1Page1, BUCKETS, "cfgLibsGlobal").getPath());
+ assertEquals("/conf/brand1/tenant1/sling:test/test", underTest.getResource(site1Page1, BUCKETS, "test").getPath());
+
+ assertNull(underTest.getResource(site2Page1, BUCKETS, "cfgSite1"));
+ assertEquals("/conf/brand1/tenant1/region1/sling:test/cfgRegion1", underTest.getResource(site2Page1, BUCKETS, "cfgRegion1").getPath());
+ assertEquals("/conf/brand1/tenant1/sling:test.runmode1/cfgTenant1", underTest.getResource(site2Page1, BUCKETS, "cfgTenant1").getPath());
+ assertEquals("/conf/brand1/sling:test/cfgBrand1", underTest.getResource(site2Page1, BUCKETS, "cfgBrand1").getPath());
+ assertEquals("/conf/global/sling:test/cfgGlobal", underTest.getResource(site2Page1, BUCKETS, "cfgGlobal").getPath());
+ assertEquals("/apps/conf/sling:test/cfgAppsGlobal", underTest.getResource(site2Page1, BUCKETS, "cfgAppsGlobal").getPath());
+ assertEquals("/libs/conf/sling:test.runmode1/cfgLibsGlobal", underTest.getResource(site2Page1, BUCKETS, "cfgLibsGlobal").getPath());
+ assertEquals("/conf/brand1/tenant1/sling:test/test", underTest.getResource(site2Page1, BUCKETS, "test").getPath());
+ }
+
+ @Test
+ public void testGetResourceInheritanceChain() {
+ context.build()
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test/test")
+ .resource("/conf/brand1/tenant1/sling:test/test")
+ .resource("/conf/brand1/tenant1/sling:test.runmode1/test")
+ .resource("/conf/brand1/tenant1/sling:test.runmode2/test")
+ .resource("/conf/global/sling:test/test")
+ .resource("/apps/conf/sling:test/test")
+ .resource("/libs/conf/sling:test/test");
+
+ assertThat(underTest.getResourceInheritanceChain(site1Page1, BUCKETS, "test"), ResourceIteratorMatchers.paths(
+ "/conf/brand1/tenant1/region1/site1/sling:test/test",
+ "/conf/brand1/tenant1/sling:test.runmode1/test",
+ "/conf/global/sling:test/test",
+ "/apps/conf/sling:test/test",
+ "/libs/conf/sling:test/test"));
+
+ assertThat(underTest.getResourceInheritanceChain(site2Page1, BUCKETS, "test"), ResourceIteratorMatchers.paths(
+ "/conf/brand1/tenant1/sling:test.runmode1/test",
+ "/conf/global/sling:test/test",
+ "/apps/conf/sling:test/test",
+ "/libs/conf/sling:test/test"));
+ }
+
+ @Test
+ public void testGetResourceCollectionWithInheritance() {
+ context.build()
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("site1")
+ .resource("/conf/brand1/tenant1/region1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("region1")
+ .resource("/conf/brand1/tenant1/region1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("region1")
+ .resource("/conf/brand1/tenant1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("tenant1")
+ .resource("/conf/brand1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("brand1")
+ .resource("/conf/global/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("confGlobal")
+ .resource("/apps/conf/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("appsGlobal")
+ .resource("/libs/conf/sling:test/cfgCol/libsGlobal1")
+ .resource("/libs/conf/sling:test/cfgCol/libsGlobal2")
+ .resource("/libs/conf/sling:test.runmode1/cfgCol/libsGlobal1")
+ .resource("/libs/conf/sling:test.runmode1/cfgCol/libsGlobal3")
+ .resource("/libs/conf/sling:test.runmode2/cfgCol/libsGlobal1")
+ .resource("/libs/conf/sling:test.runmode2/cfgCol/libsGlobal4");
+
+ assertThat(underTest.getResourceCollection(site1Page1, BUCKETS, "cfgCol"), ResourceCollectionMatchers.paths(
+ "/conf/brand1/tenant1/region1/site1/sling:test/cfgCol/site1",
+ "/conf/brand1/tenant1/region1/sling:test.runmode1/cfgCol/region1",
+ "/conf/brand1/tenant1/sling:test/cfgCol/tenant1",
+ "/conf/brand1/sling:test/cfgCol/brand1",
+ "/conf/global/sling:test/cfgCol/confGlobal",
+ "/apps/conf/sling:test/cfgCol/appsGlobal",
+ "/libs/conf/sling:test.runmode1/cfgCol/libsGlobal1",
+ "/libs/conf/sling:test.runmode1/cfgCol/libsGlobal3",
+ "/libs/conf/sling:test/cfgCol/libsGlobal2"));
+
+ assertThat(underTest.getResourceCollection(site2Page1, BUCKETS, "cfgCol"), ResourceCollectionMatchers.paths(
+ "/conf/brand1/tenant1/region1/sling:test.runmode1/cfgCol/region1",
+ "/conf/brand1/tenant1/sling:test/cfgCol/tenant1",
+ "/conf/brand1/sling:test/cfgCol/brand1",
+ "/conf/global/sling:test/cfgCol/confGlobal",
+ "/apps/conf/sling:test/cfgCol/appsGlobal",
+ "/libs/conf/sling:test.runmode1/cfgCol/libsGlobal1",
+ "/libs/conf/sling:test.runmode1/cfgCol/libsGlobal3",
+ "/libs/conf/sling:test/cfgCol/libsGlobal2"));
+ }
+
+ @Test
+ public void testGetResourceCollectionInheritanceChain() {
+ context.build()
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item1")
+ .resource("item2")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item2")
+ .resource("/conf/brand1/tenant1/region1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true)
+ .siblingsMode()
+ .resource("item1")
+ .resource("item3")
+ .resource("/conf/brand1/tenant1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item4")
+ .resource("/conf/global/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item1")
+ .resource("/conf/global/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item1")
+ .resource("/conf/global/sling:test.runmode2/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item1")
+ .resource("/libs/conf/sling:test/cfgCol")
+ .siblingsMode()
+ .resource("item2")
+ .resource("item3")
+ .resource("/libs/conf/sling:test.runmode1/cfgCol")
+ .siblingsMode()
+ .resource("item3");
+
+ List<Iterator<Resource>> resources = ImmutableList.copyOf(underTest.getResourceCollectionInheritanceChain(site1Page1, BUCKETS, "cfgCol"));
+ assertEquals(4, resources.size());
+
+ assertThat(resources.get(0), ResourceIteratorMatchers.paths(
+ "/conf/brand1/tenant1/region1/site1/sling:test.runmode1/cfgCol/item2",
+ "/libs/conf/sling:test/cfgCol/item2"));
+ assertThat(resources.get(1), ResourceIteratorMatchers.paths(
+ "/conf/brand1/tenant1/region1/site1/sling:test/cfgCol/item1",
+ "/conf/brand1/tenant1/region1/sling:test/cfgCol/item1",
+ "/conf/global/sling:test.runmode1/cfgCol/item1"));
+ assertThat(resources.get(2), ResourceIteratorMatchers.paths(
+ "/conf/brand1/tenant1/region1/sling:test/cfgCol/item3",
+ "/libs/conf/sling:test.runmode1/cfgCol/item3"));
+ assertThat(resources.get(3), ResourceIteratorMatchers.paths(
+ "/conf/brand1/tenant1/sling:test/cfgCol/item4"));
+ }
+
+ @Test
+ public void testGetResourceCollectionContentConfigRefInheritanceAndConfigResourceInheritance() {
+ context.build()
+ .resource("/content/level1", PROPERTY_CONFIG_REF, "/conf/a1/a2")
+ .resource("/content/level1/level2", PROPERTY_CONFIG_REF, "/conf/b1/b2")
+ .resource("/conf/a1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("a1")
+ .resource("/conf/a1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("a1")
+ .resource("/conf/a1/sling:test.runmode2/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("a2")
+ .resource("/conf/a1/a2/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("a1_a2")
+ .resource("/conf/b1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("b1")
+ .resource("/conf/b1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("b1")
+ .resource("/conf/b1/b2/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("b1_b2")
+ .resource("/conf/global/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("confGlobal")
+ .resource("/conf/global/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("confGlobal")
+ .resource("/conf/global/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("confGlobal2")
+ .resource("/apps/conf/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("appsGlobal")
+ .resource("/libs/conf/sling:test/cfgCol/libsGlobal");
+
+ Resource level1_2 = context.resourceResolver().getResource("/content/level1/level2");
+
+ assertThat(underTest.getResourceCollection(level1_2, BUCKETS, "cfgCol"), ResourceCollectionMatchers.paths(
+ "/conf/b1/b2/sling:test/cfgCol/b1_b2",
+ "/conf/b1/sling:test.runmode1/cfgCol/b1",
+ "/conf/a1/a2/sling:test/cfgCol/a1_a2",
+ "/conf/a1/sling:test.runmode1/cfgCol/a1",
+ "/conf/global/sling:test.runmode1/cfgCol/confGlobal",
+ "/conf/global/sling:test.runmode1/cfgCol/confGlobal2",
+ "/apps/conf/sling:test/cfgCol/appsGlobal",
+ "/libs/conf/sling:test/cfgCol/libsGlobal"));
+ }
+
+}
diff --git a/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyTest.java b/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyTest.java
index 1bc4993..4236011 100644
--- a/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyTest.java
+++ b/src/test/java/org/apache/sling/caconfig/resource/impl/def/DefaultConfigurationResourceResolvingStrategyHierarchyTest.java
@@ -42,7 +42,7 @@
import com.google.common.collect.ImmutableList;
/**
- * Tests with content and configurations that form a deeper nested hierarchy.
+ * Tests with content and configurations that form a deeper nested hierarchy with run-mode aware *not* activated
*/
public class DefaultConfigurationResourceResolvingStrategyHierarchyTest {
@@ -79,15 +79,20 @@
public void testGetResource() {
context.build()
.resource("/conf/brand1/tenant1/region1/site1/sling:test/cfgSite1")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test.runmode1/cfgSite1")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test.runmode2/cfgSite1")
.resource("/conf/brand1/tenant1/region1/sling:test/cfgRegion1")
.resource("/conf/brand1/tenant1/sling:test/cfgTenant1")
+ .resource("/conf/brand1/tenant1/sling:test.runmode1/cfgTenant1")
.resource("/conf/brand1/tenant1/sling:test/test")
.resource("/conf/brand1/sling:test/cfgBrand1")
.resource("/conf/global/sling:test/cfgGlobal")
.resource("/conf/global/sling:test/test")
.resource("/apps/conf/sling:test/cfgAppsGlobal")
+ .resource("/apps/conf/sling:test.runmode2/cfgAppsGlobal")
.resource("/apps/conf/sling:test/test")
.resource("/libs/conf/sling:test/cfgLibsGlobal")
+ .resource("/libs/conf/sling:test.runmode1/cfgLibsGlobal")
.resource("/libs/conf/sling:test/test");
assertEquals("/conf/brand1/tenant1/region1/site1/sling:test/cfgSite1", underTest.getResource(site1Page1, BUCKETS, "cfgSite1").getPath());
@@ -114,6 +119,8 @@
context.build()
.resource("/conf/brand1/tenant1/region1/site1/sling:test/test")
.resource("/conf/brand1/tenant1/sling:test/test")
+ .resource("/conf/brand1/tenant1/sling:test.runmode1/test")
+ .resource("/conf/brand1/tenant1/sling:test.runmode2/test")
.resource("/conf/global/sling:test/test")
.resource("/apps/conf/sling:test/test")
.resource("/libs/conf/sling:test/test");
@@ -137,12 +144,17 @@
context.build()
.resource("/conf/brand1/tenant1/region1/site1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("site1")
.resource("/conf/brand1/tenant1/region1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("region1")
+ .resource("/conf/brand1/tenant1/region1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("region1")
.resource("/conf/brand1/tenant1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("tenant1")
.resource("/conf/brand1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("brand1")
.resource("/conf/global/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("confGlobal")
.resource("/apps/conf/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("appsGlobal")
.resource("/libs/conf/sling:test/cfgCol/libsGlobal1")
- .resource("/libs/conf/sling:test/cfgCol/libsGlobal2");
+ .resource("/libs/conf/sling:test/cfgCol/libsGlobal2")
+ .resource("/libs/conf/sling:test.runmode1/cfgCol/libsGlobal1")
+ .resource("/libs/conf/sling:test.runmode1/cfgCol/libsGlobal3")
+ .resource("/libs/conf/sling:test.runmode2/cfgCol/libsGlobal1")
+ .resource("/libs/conf/sling:test.runmode2/cfgCol/libsGlobal4");
assertThat(underTest.getResourceCollection(site1Page1, BUCKETS, "cfgCol"), ResourceCollectionMatchers.paths(
"/conf/brand1/tenant1/region1/site1/sling:test/cfgCol/site1",
@@ -171,6 +183,9 @@
.siblingsMode()
.resource("item1")
.resource("item2")
+ .resource("/conf/brand1/tenant1/region1/site1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item2")
.resource("/conf/brand1/tenant1/region1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true)
.siblingsMode()
.resource("item1")
@@ -181,9 +196,18 @@
.resource("/conf/global/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
.siblingsMode()
.resource("item1")
+ .resource("/conf/global/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item1")
+ .resource("/conf/global/sling:test.runmode2/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true)
+ .siblingsMode()
+ .resource("item1")
.resource("/libs/conf/sling:test/cfgCol")
.siblingsMode()
.resource("item2")
+ .resource("item3")
+ .resource("/libs/conf/sling:test.runmode1/cfgCol")
+ .siblingsMode()
.resource("item3");
List<Iterator<Resource>> resources = ImmutableList.copyOf(underTest.getResourceCollectionInheritanceChain(site1Page1, BUCKETS, "cfgCol"));
@@ -209,10 +233,15 @@
.resource("/content/level1", PROPERTY_CONFIG_REF, "/conf/a1/a2")
.resource("/content/level1/level2", PROPERTY_CONFIG_REF, "/conf/b1/b2")
.resource("/conf/a1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("a1")
+ .resource("/conf/a1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("a1")
+ .resource("/conf/a1/sling:test.runmode2/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("a2")
.resource("/conf/a1/a2/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("a1_a2")
.resource("/conf/b1/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("b1")
+ .resource("/conf/b1/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("b1")
.resource("/conf/b1/b2/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT_CUSTOM, true).resource("b1_b2")
.resource("/conf/global/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("confGlobal")
+ .resource("/conf/global/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("confGlobal")
+ .resource("/conf/global/sling:test.runmode1/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("confGlobal2")
.resource("/apps/conf/sling:test/cfgCol", PROPERTY_CONFIG_COLLECTION_INHERIT, true).resource("appsGlobal")
.resource("/libs/conf/sling:test/cfgCol/libsGlobal");