Skip to content

Commit a2133b6

Browse files
committed
Merge branch 'develop'
2 parents 06ba26a + 09b8d00 commit a2133b6

File tree

59 files changed

+821
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+821
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<img src="https://wcm.io/images/favicon-16@2x.png"/> AEM Mocks
22
======
33
[![Build](https://github.com/wcm-io/io.wcm.testing.aem-mock/workflows/Build/badge.svg?branch=develop)](https://github.com/wcm-io/io.wcm.testing.aem-mock/actions?query=workflow%3ABuild+branch%3Adevelop)
4-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.testing.aem-mock/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.wcm/io.wcm.testing.aem-mock)
4+
[![Maven Central](https://img.shields.io/maven-central/v/io.wcm/io.wcm.testing.aem-mock)](https://repo1.maven.org/maven2/io/wcm/io.wcm.testing.aem-mock/)
55
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=wcm-io_io.wcm.testing.aem-mock&metric=coverage)](https://sonarcloud.io/summary/new_code?id=wcm-io_io.wcm.testing.aem-mock)
66

77
Mock implementation of selected AEM APIs.

changes.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@
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.1.0" date="2022-09-30">
27+
<action type="add" dev="sseifert"><![CDATA[
28+
Add support for new Resource Resovler Type <code>RESOURCEPROVIDER_MOCK</code> introduced with <a href="https://issues.apache.org/jira/browse/SLING-11548">SLING-11548</a>.
29+
]]></action>
30+
<action type="update" dev="sseifert">
31+
Implement MockTemplate.getProperties method.
32+
</action>
33+
<action type="update" dev="sseifert">
34+
Update to latest Sling Mock, Resource Resolver Mock, OSGi Mock.
35+
</action>
36+
<action type="fix" dev="sseifert">
37+
MockTemplate: Fix loading properties for editable templates (with structure support).
38+
</action>
39+
</release>
40+
2641
<release version="5.0.0" date="2022-05-11">
2742
<action type="update" dev="sseifert">
2843
Update to latest ResourceResolver Mock, JCR Mock, OSGi Mock and Sling Mock.

core/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.0.0</version>
28+
<version>5.1.0</version>
2929
<relativePath>../parent/pom.xml</relativePath>
3030
</parent>
3131

core/src/main/java/io/wcm/testing/mock/aem/MockTemplate.java

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

3333
import org.apache.commons.lang3.StringUtils;
3434
import org.apache.sling.api.resource.Resource;
35+
import org.apache.sling.api.resource.ResourceUtil;
3536
import org.apache.sling.api.resource.ResourceWrapper;
3637
import org.apache.sling.api.resource.ValueMap;
3738
import org.apache.sling.commons.json.JSONException;
@@ -56,7 +57,12 @@ class MockTemplate extends ResourceWrapper implements Template {
5657
MockTemplate(@NotNull Resource resource) {
5758
super(resource);
5859
this.resource = resource;
59-
this.properties = resource.getValueMap();
60+
if (hasStructureSupport()) {
61+
this.properties = ResourceUtil.getValueMap(resource.getChild(JCR_CONTENT));
62+
}
63+
else {
64+
this.properties = ResourceUtil.getValueMap(resource);
65+
}
6066
}
6167

6268
@Override
@@ -121,6 +127,11 @@ public Calendar getLastModified() {
121127
return properties.get(JCR_LASTMODIFIED, Calendar.class);
122128
}
123129

130+
@Override
131+
public ValueMap getProperties() {
132+
return properties;
133+
}
134+
124135
@Override
125136
public boolean equals(Object obj) {
126137
if (!(obj instanceof MockTemplate)) {
@@ -183,11 +194,6 @@ public String getPageTypePath() {
183194
throw new UnsupportedOperationException();
184195
}
185196

186-
@Override
187-
public ValueMap getProperties() {
188-
throw new UnsupportedOperationException();
189-
}
190-
191197
@Override
192198
public boolean isAllowed(Resource arg0) {
193199
throw new UnsupportedOperationException();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ private ContextResourceResolverFactory() {
6464
case RESOURCERESOLVER_MOCK:
6565
initializeResourceResolverMock(factory);
6666
break;
67+
case RESOURCEPROVIDER_MOCK:
68+
initializeResourceProviderMock(factory);
69+
break;
6770
case NONE:
6871
initializeResourceResolverNone(factory);
6972
break;
@@ -101,6 +104,11 @@ private static void initializeResourceResolverMock(ResourceResolverFactory facto
101104
// nothing to do
102105
}
103106

107+
@SuppressWarnings("unused")
108+
private static void initializeResourceProviderMock(ResourceResolverFactory factory) {
109+
// nothing to do
110+
}
111+
104112
@SuppressWarnings("unused")
105113
private static void initializeResourceResolverNone(ResourceResolverFactory factory) {
106114
// nothing to do
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* #%L
3+
* wcm.io
4+
* %%
5+
* Copyright (C) 2022 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;
21+
22+
import static com.day.cq.commons.jcr.JcrConstants.JCR_TITLE;
23+
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertNotNull;
25+
26+
import java.io.File;
27+
28+
import org.apache.sling.api.resource.Resource;
29+
import org.apache.sling.testing.mock.sling.ResourceResolverType;
30+
import org.junit.Rule;
31+
import org.junit.Test;
32+
33+
import com.day.cq.dam.api.Asset;
34+
import com.day.cq.wcm.api.Page;
35+
import com.day.cq.wcm.api.Template;
36+
import com.day.cq.wcm.api.components.Component;
37+
import com.day.cq.wcm.api.components.ComponentManager;
38+
import com.day.image.Layer;
39+
40+
import io.wcm.testing.mock.aem.context.TestAemContext;
41+
import io.wcm.testing.mock.aem.junit.AemContext;
42+
43+
/**
44+
* Test loading JCR content from FileVault XML and JSON folder structures
45+
* and access the data via various AEM APIs.
46+
*/
47+
public class ContentLoaderFolderTest {
48+
49+
private static final File FOLDER_CONTENT_SAMPLE = new File("src/test/resources/folder-content-sample");
50+
private static final String STRUCTURE_ELEMENT_TEMPLATE_PATH = "/apps/myproject1/templates/structureElement";
51+
private static final String SAMPLE_COMPONENT_PATH = "/apps/myproject1/components/customcarousel";
52+
53+
@Rule
54+
public AemContext context = TestAemContext.newAemContext();
55+
56+
@Test
57+
@SuppressWarnings("null")
58+
public void testAppsJSON() {
59+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
60+
// skip - FsResourceProvider not supported
61+
return;
62+
}
63+
64+
context.load().folderJson(new File(FOLDER_CONTENT_SAMPLE, "apps-json"), "/apps/myproject1");
65+
66+
Resource templateResource = context.resourceResolver().getResource(STRUCTURE_ELEMENT_TEMPLATE_PATH);
67+
assertNotNull(templateResource);
68+
assertEquals("myproject1 Structure Element", templateResource.getValueMap().get(JCR_TITLE));
69+
70+
Template template = templateResource.adaptTo(Template.class);
71+
assertEquals("myproject1 Structure Element", template.getTitle());
72+
73+
ComponentManager componentManager = context.resourceResolver().adaptTo(ComponentManager.class);
74+
Component component = componentManager.getComponent(SAMPLE_COMPONENT_PATH);
75+
assertNotNull(component);
76+
assertEquals("Carousel (Custom)", component.getTitle());
77+
}
78+
79+
@Test
80+
@SuppressWarnings("null")
81+
public void testAppsFileVault() {
82+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
83+
// skip - FsResourceProvider not supported
84+
return;
85+
}
86+
87+
context.load().folderFileVaultXml(new File(FOLDER_CONTENT_SAMPLE, "apps-filevault"), "/apps/myproject1");
88+
89+
Resource templateResource = context.resourceResolver().getResource(STRUCTURE_ELEMENT_TEMPLATE_PATH);
90+
assertNotNull(templateResource);
91+
assertEquals("myproject1 Structure Element", templateResource.getValueMap().get(JCR_TITLE));
92+
93+
Template template = templateResource.adaptTo(Template.class);
94+
assertEquals("myproject1 Structure Element", template.getTitle());
95+
96+
ComponentManager componentManager = context.resourceResolver().adaptTo(ComponentManager.class);
97+
Component component = componentManager.getComponent(SAMPLE_COMPONENT_PATH);
98+
assertNotNull(component);
99+
assertEquals("Carousel (Custom)", component.getTitle());
100+
}
101+
102+
@Test
103+
public void testContentConfFileVault() {
104+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
105+
// skip - FsResourceProvider not supported
106+
return;
107+
}
108+
109+
context.load().folderFileVaultXml(new File(FOLDER_CONTENT_SAMPLE, "conf-filevault"), "/conf/myproject1");
110+
context.load().folderFileVaultXml(new File(FOLDER_CONTENT_SAMPLE, "content-filevault"), "/content/myproject1");
111+
112+
Page testPage = context.pageManager().getPage("/content/myproject1/test");
113+
assertNotNull(testPage);
114+
assertEquals("Test", testPage.getTitle());
115+
116+
Template template = testPage.getTemplate();
117+
assertNotNull(template);
118+
assertEquals("myproject1 Content", template.getTitle());
119+
}
120+
121+
@Test
122+
@SuppressWarnings("null")
123+
public void testAsset() {
124+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
125+
// skip - FsResourceProvider not supported
126+
return;
127+
}
128+
129+
context.load().folderFileVaultXml(new File(FOLDER_CONTENT_SAMPLE, "content-filevault"), "/content/dam/myproject1");
130+
131+
Resource assetResource = context.resourceResolver().getResource("/content/dam/myproject1/sample.jpg");
132+
assertNotNull(assetResource);
133+
Asset asset = assetResource.adaptTo(Asset.class);
134+
assertEquals("sample.jpg", asset.getName());
135+
136+
Layer layer = asset.getOriginal().adaptTo(Layer.class);
137+
assertNotNull(layer);
138+
assertEquals(100, layer.getWidth());
139+
assertEquals(50, layer.getHeight());
140+
}
141+
142+
}

core/src/test/java/io/wcm/testing/mock/aem/MockPageManagerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ public void testCreatePageWithDuplicateName() throws Exception {
285285
@Test
286286
public void testTouch() throws WCMException, PersistenceException {
287287
// RESOURCERESOLVER_MOCK doesn't support JCR API - skip test
288-
if (ResourceResolverType.RESOURCERESOLVER_MOCK.equals(context.resourceResolverType())) {
288+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK
289+
|| context.resourceResolverType() == ResourceResolverType.RESOURCEPROVIDER_MOCK) {
289290
return;
290291
}
291292
// set custom page properties

core/src/test/java/io/wcm/testing/mock/aem/MockTemplateTest.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
package io.wcm.testing.mock.aem;
2121

2222
import static org.junit.Assert.assertEquals;
23-
import static org.junit.Assert.assertFalse;
23+
import static org.junit.Assert.assertNotEquals;
2424
import static org.junit.Assert.assertNotNull;
2525
import static org.junit.Assert.assertNull;
26-
import static org.junit.Assert.assertTrue;
2726

2827
import org.apache.sling.api.resource.Resource;
28+
import org.apache.sling.testing.mock.sling.ResourceResolverType;
2929
import org.junit.Before;
3030
import org.junit.Rule;
3131
import org.junit.Test;
@@ -61,7 +61,8 @@ public void testProperties() {
6161
assertNull(this.template.getIconPath());
6262
assertEquals("/apps/sample/templates/homepage/thumbnail.png", this.template.getThumbnailPath());
6363
assertEquals((Long)110L, this.template.getRanking());
64-
assertNotNull(template.hashCode());
64+
assertEquals((Integer)110, this.template.getProperties().get("ranking", 0));
65+
assertNotEquals(template.hashCode(), 0);
6566
}
6667

6768
@Test
@@ -70,8 +71,26 @@ public void testEquals() throws Exception {
7071
Template template2 = this.context.resourceResolver().getResource("/apps/sample/templates/homepage").adaptTo(Template.class);
7172
Template template3 = this.context.resourceResolver().getResource("/apps/sample/templates/contentpage").adaptTo(Template.class);
7273

73-
assertTrue(template1.equals(template2));
74-
assertFalse(template1.equals(template3));
74+
assertEquals(template1, template2);
75+
assertNotEquals(template1, template3);
76+
}
77+
78+
@Test
79+
public void testEditableTemplateProperties() {
80+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
81+
// skip - FsResourceProvider not supported
82+
return;
83+
}
84+
85+
context.load().folderFileVaultXml("src/test/resources/folder-content-sample/conf-filevault", "/conf/myproject1");
86+
Resource resource = context.resourceResolver().getResource("/conf/myproject1/settings/wcm/templates/contentpage");
87+
this.template = resource.adaptTo(Template.class);
88+
89+
assertEquals("/conf/myproject1/settings/wcm/templates/contentpage", this.template.getPath());
90+
assertEquals("contentpage", this.template.getName());
91+
assertEquals("myproject1 Content", this.template.getTitle());
92+
assertEquals((Long)10L, this.template.getRanking());
93+
assertEquals((Integer)10, this.template.getProperties().get("ranking", 0));
7594
}
7695

7796
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public void testBindings() {
7979
assertNotNull(model.getResource());
8080
assertNotNull(model.getRequest());
8181
assertNotNull(model.getResponse());
82-
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
82+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK
83+
|| context.resourceResolverType() == ResourceResolverType.RESOURCEPROVIDER_MOCK) {
8384
assertNull(model.getCurrentNode());
8485
assertNull(model.getcurrentSession());
8586
}
@@ -147,7 +148,8 @@ public void testBindings_EditMode() {
147148
assertNotNull(model.getResource());
148149
assertNotNull(model.getRequest());
149150
assertNotNull(model.getResponse());
150-
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
151+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK
152+
|| context.resourceResolverType() == ResourceResolverType.RESOURCEPROVIDER_MOCK) {
151153
assertNull(model.getCurrentNode());
152154
assertNull(model.getcurrentSession());
153155
}
@@ -183,7 +185,8 @@ public void testBindingsModelFactory() throws Exception {
183185
assertNotNull(model.getResource());
184186
assertNotNull(model.getRequest());
185187
assertNotNull(model.getResponse());
186-
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK) {
188+
if (context.resourceResolverType() == ResourceResolverType.RESOURCERESOLVER_MOCK
189+
|| context.resourceResolverType() == ResourceResolverType.RESOURCEPROVIDER_MOCK) {
187190
assertNull(model.getCurrentNode());
188191
assertNull(model.getcurrentSession());
189192
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public final class TestAemContext {
4242
*/
4343
@SuppressFBWarnings("MS_PKGPROTECT")
4444
public static final ResourceResolverType[] ALL_TYPES = new @NotNull ResourceResolverType[] {
45-
ResourceResolverType.JCR_MOCK,
46-
ResourceResolverType.RESOURCERESOLVER_MOCK,
47-
ResourceResolverType.JCR_OAK
45+
ResourceResolverType.JCR_MOCK,
46+
ResourceResolverType.RESOURCERESOLVER_MOCK,
47+
ResourceResolverType.RESOURCEPROVIDER_MOCK,
48+
ResourceResolverType.JCR_OAK
4849
};
4950

5051
private TestAemContext() {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="sling:Folder"/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="sling:Folder"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
3+
jcr:primaryType="cq:Component"
4+
jcr:title="Carousel (Custom)"
5+
componentGroup="myproject1 Content"/>

0 commit comments

Comments
 (0)