Skip to content

Commit aed6835

Browse files
committed
Merge branch 'develop'
2 parents 58ce426 + 5ec4d4e commit aed6835

File tree

12 files changed

+176
-33
lines changed

12 files changed

+176
-33
lines changed

changes.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
2424
<body>
2525

26+
<release version="5.4.4" date="2023-12-12">
27+
<action type="update" dev="sseifert">
28+
Update to latest Sling Mock.
29+
</action>
30+
<action type="update" dev="sseifert" issue="29">
31+
Resource Resolver Factory: Set resource.resolver.optimize.alias.resolution=true and resource.resolver.enable.vanitypath=true to use the optimized sling:alias resolution.
32+
As a result, sling:alias resolution is only supported with JCR_OAK resource resolver type.
33+
</action>
34+
</release>
35+
2636
<release version="5.4.2" date="2023-11-20">
2737
<action type="update" dev="sseifert">
2838
Update to latest OSGi Mock.

core/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
28-
<version>5.4.2</version>
28+
<version>5.4.4</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

@@ -287,6 +287,13 @@
287287
<scope>test</scope>
288288
</dependency>
289289

290+
<dependency>
291+
<groupId>org.awaitility</groupId>
292+
<artifactId>awaitility</artifactId>
293+
<version>4.2.0</version>
294+
<scope>test</scope>
295+
</dependency>
296+
290297
</dependencies>
291298

292299
<build>

core/src/main/java/io/wcm/testing/mock/aem/context/AemContextImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Map;
2525
import java.util.Set;
2626

27-
import io.wcm.testing.mock.aem.xf.MockExperienceFragmentAdapterFactory;
2827
import org.apache.sling.api.SlingHttpServletRequest;
2928
import org.apache.sling.api.resource.Resource;
3029
import org.apache.sling.api.resource.ResourceResolverFactory;
@@ -57,6 +56,7 @@
5756
import io.wcm.testing.mock.aem.dam.MockAssetStore;
5857
import io.wcm.testing.mock.aem.dam.MockPublishUtils;
5958
import io.wcm.testing.mock.aem.granite.MockResourceCollectionManager;
59+
import io.wcm.testing.mock.aem.xf.MockExperienceFragmentAdapterFactory;
6060

6161
/**
6262
* Defines AEM context objects with lazy initialization.
@@ -138,10 +138,8 @@ protected final Map<String, Object> resourceResolverFactoryActivatorPropsMergeWi
138138
});
139139
props.put("resource.resolver.map.location", "/etc/map");
140140
props.put("resource.resolver.default.vanity.redirect.status", "302");
141-
props.put("resource.resolver.enable.vanitypath", false);
142141
props.put("resource.resolver.vanitypath.maxEntries", -1);
143142
props.put("resource.resolver.vanitypath.bloomfilter.maxBytes", 1024000);
144-
props.put("resource.resolver.optimize.alias.resolution", false);
145143
props.put(ResourceResolverFactoryConfigPropertyNames.getVanityPathAllowListPropertyName(), new String[] {
146144
"/apps/",
147145
"/libs/",

core/src/test/java/io/wcm/testing/mock/aem/context/AemContextImplTest.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@
1919
*/
2020
package io.wcm.testing.mock.aem.context;
2121

22-
import static com.day.cq.commons.jcr.JcrConstants.JCR_PRIMARYTYPE;
23-
import static com.day.cq.commons.jcr.JcrConstants.NT_UNSTRUCTURED;
2422
import static org.junit.Assert.assertEquals;
2523
import static org.junit.Assert.assertNotNull;
2624
import static org.junit.Assert.assertNull;
2725

2826
import org.apache.sling.api.resource.Resource;
2927
import org.apache.sling.api.resource.ResourceResolver;
3028
import org.apache.sling.api.resource.ResourceResolverFactory;
31-
import org.apache.sling.testing.mock.sling.ResourceResolverType;
3229
import org.apache.sling.testing.mock.sling.loader.ContentLoader;
3330
import org.junit.After;
3431
import org.junit.Before;
@@ -140,17 +137,4 @@ public void testSetCurrentPageViaSetResource_Resource() {
140137
assertEquals(contentRoot + "/toolbar/jcr:content", context.currentResource().getPath());
141138
}
142139

143-
@Test
144-
public void testSlingAlias() {
145-
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
146-
// sling:alias is not supported for RESOURCERESOLVER_MOCK
147-
return;
148-
}
149-
Resource resource = context.create().resource(contentRoot + "/myresource",
150-
JCR_PRIMARYTYPE, NT_UNSTRUCTURED,
151-
"sling:alias", "myalias");
152-
assertEquals(contentRoot + "/myresource", resource.getPath());
153-
assertEquals(contentRoot + "/myalias", context.resourceResolver().map(resource.getPath()));
154-
}
155-
156140
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2023 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.testing.mock.aem.context;
21+
22+
import static com.day.cq.commons.jcr.JcrConstants.JCR_PRIMARYTYPE;
23+
import static com.day.cq.commons.jcr.JcrConstants.NT_UNSTRUCTURED;
24+
import static org.junit.Assert.assertEquals;
25+
26+
import java.util.Map;
27+
28+
import org.apache.sling.api.resource.PersistenceException;
29+
import org.apache.sling.api.resource.Resource;
30+
import org.apache.sling.testing.mock.sling.ResourceResolverType;
31+
import org.junit.Before;
32+
import org.junit.Rule;
33+
import org.junit.Test;
34+
35+
import io.wcm.testing.mock.aem.junit.AemContext;
36+
import io.wcm.testing.mock.aem.junit.AemContextBuilder;
37+
38+
public class SlingAlias_JcrMockTest {
39+
40+
@Rule
41+
public AemContext context = new AemContextBuilder(ResourceResolverType.JCR_MOCK)
42+
/*
43+
* The optimized alias resolution is based on ResourceChangeListener, which is not supported with JCR_MOCK,
44+
* because JCR_MOCK does not support JCR Observation events. So, to use sling:alias with JCR_MOCK
45+
* we have to disabled the optimized alias resolution.
46+
* But be warned: This old code path is deprecated and likely to be removed in future Sling versions.
47+
* See SLING-12054 and SLING-12025 as references.
48+
*/
49+
.resourceResolverFactoryActivatorProps(Map.of("resource.resolver.optimize.alias.resolution", false))
50+
.build();
51+
52+
private String contentRoot;
53+
54+
@Before
55+
public void setUp() throws Exception {
56+
contentRoot = context.uniqueRoot().content() + "/sample";
57+
}
58+
59+
@Test
60+
public void testSlingAlias() throws PersistenceException {
61+
Resource resource = context.create().resource(contentRoot + "/myresource",
62+
JCR_PRIMARYTYPE, NT_UNSTRUCTURED,
63+
"sling:alias", "myalias");
64+
context.resourceResolver().commit();
65+
66+
assertEquals(contentRoot + "/myresource", resource.getPath());
67+
assertEquals(contentRoot + "/myalias", context.resourceResolver().map(resource.getPath()));
68+
}
69+
70+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2023 wcm.io
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package io.wcm.testing.mock.aem.context;
21+
22+
import static com.day.cq.commons.jcr.JcrConstants.JCR_PRIMARYTYPE;
23+
import static com.day.cq.commons.jcr.JcrConstants.NT_UNSTRUCTURED;
24+
import static java.util.concurrent.TimeUnit.SECONDS;
25+
import static org.awaitility.Awaitility.await;
26+
import static org.junit.Assert.assertEquals;
27+
28+
import org.apache.commons.lang3.StringUtils;
29+
import org.apache.sling.api.resource.PersistenceException;
30+
import org.apache.sling.api.resource.Resource;
31+
import org.apache.sling.testing.mock.sling.ResourceResolverType;
32+
import org.junit.Before;
33+
import org.junit.Rule;
34+
import org.junit.Test;
35+
36+
import io.wcm.testing.mock.aem.junit.AemContext;
37+
38+
public class SlingAlias_JcrOakTest {
39+
40+
@Rule
41+
public AemContext context = new AemContext(ResourceResolverType.JCR_OAK);
42+
43+
private String contentRoot;
44+
45+
@Before
46+
public void setUp() throws Exception {
47+
contentRoot = context.uniqueRoot().content() + "/sample";
48+
}
49+
50+
@Test
51+
public void testSlingAlias() throws PersistenceException {
52+
Resource resource = context.create().resource(contentRoot + "/myresource",
53+
JCR_PRIMARYTYPE, NT_UNSTRUCTURED,
54+
"sling:alias", "myalias");
55+
context.resourceResolver().commit();
56+
57+
assertEquals(contentRoot + "/myresource", resource.getPath());
58+
59+
// alias processing happens asynchronously, so it may take a bit until the alias resolution works
60+
await().atMost(2, SECONDS).until(() -> StringUtils.equals(contentRoot + "/myalias",
61+
context.resourceResolver().map(resource.getPath())));
62+
}
63+
64+
}

core/src/test/java/io/wcm/testing/mock/aem/context/TestAemContext.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3434
import io.wcm.testing.mock.aem.junit.AemContext;
35+
import io.wcm.testing.mock.aem.junit.AemContextBuilder;
3536
import io.wcm.testing.mock.aem.junit.AemContextCallback;
3637

3738
public final class TestAemContext {
@@ -59,6 +60,15 @@ private TestAemContext() {
5960
return new AemContext(new SetUpCallback(), resourceResolverTypes);
6061
}
6162

63+
public static @NotNull AemContextBuilder newAemContextBuilder() {
64+
return newAemContextBuilder(ALL_TYPES);
65+
}
66+
67+
public static @NotNull AemContextBuilder newAemContextBuilder(ResourceResolverType... resourceResolverTypes) {
68+
return new AemContextBuilder(resourceResolverTypes)
69+
.afterSetUp(new SetUpCallback());
70+
}
71+
6272
/**
6373
* Custom set up rules required in all unit tests.
6474
*/

junit4/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
28-
<version>5.4.2</version>
28+
<version>5.4.4</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

@@ -54,7 +54,7 @@
5454
<dependency>
5555
<groupId>io.wcm</groupId>
5656
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
57-
<version>5.4.2</version>
57+
<version>5.4.4</version>
5858
<scope>compile</scope>
5959
</dependency>
6060

@@ -87,7 +87,7 @@
8787
<dependency>
8888
<groupId>io.wcm</groupId>
8989
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
90-
<version>5.4.2</version>
90+
<version>5.4.4</version>
9191
<classifier>tests</classifier>
9292
<scope>test</scope>
9393
</dependency>

junit5/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
28-
<version>5.4.2</version>
28+
<version>5.4.4</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

@@ -54,14 +54,14 @@
5454
<dependency>
5555
<groupId>io.wcm</groupId>
5656
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
57-
<version>5.4.2</version>
57+
<version>5.4.4</version>
5858
<scope>compile</scope>
5959
</dependency>
6060

6161
<dependency>
6262
<groupId>io.wcm</groupId>
6363
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
64-
<version>5.4.2</version>
64+
<version>5.4.4</version>
6565
<classifier>tests</classifier>
6666
<scope>test</scope>
6767
</dependency>

parent/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.parent_toplevel</artifactId>
28-
<version>2.2.4</version>
28+
<version>2.2.6</version>
2929
<relativePath />
3030
</parent>
3131

3232
<groupId>io.wcm</groupId>
3333
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
34-
<version>5.4.2</version>
34+
<version>5.4.4</version>
3535
<packaging>pom</packaging>
3636

3737
<name>AEM Mocks</name>
@@ -59,7 +59,7 @@
5959
<resourceresolver-mock.version>1.4.4</resourceresolver-mock.version>
6060

6161
<!-- Sling Mock -->
62-
<sling-mock.version>3.4.14</sling-mock.version>
62+
<sling-mock.version>3.4.16</sling-mock.version>
6363

6464
<!-- Servlet Helpers -->
6565
<servlet-helpers.version>1.4.6</servlet-helpers.version>
@@ -71,7 +71,7 @@
7171
<logging-logback.version>1.0.0</logging-logback.version>
7272

7373
<!-- Enable reproducible builds -->
74-
<project.build.outputTimestamp>2023-11-20T15:38:25Z</project.build.outputTimestamp>
74+
<project.build.outputTimestamp>2023-12-12T09:23:37Z</project.build.outputTimestamp>
7575

7676
</properties>
7777

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
28-
<version>5.4.2</version>
28+
<version>5.4.4</version>
2929
<relativePath>parent/pom.xml</relativePath>
3030
</parent>
3131

3232
<groupId>io.wcm</groupId>
3333
<artifactId>io.wcm.testing.aem-mock.root</artifactId>
3434
<packaging>pom</packaging>
35-
<version>5.4.2</version>
35+
<version>5.4.4</version>
3636

3737
<name>AEM Mocks</name>
3838
<url>${site.url}/${site.url.module.prefix}/</url>

relocate/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
28-
<version>5.4.2</version>
28+
<version>5.4.4</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

0 commit comments

Comments
 (0)