Skip to content

Commit e3ae2bd

Browse files
committed
Merge branch 'develop'
2 parents 08271c6 + 64a5cff commit e3ae2bd

33 files changed

+813
-76
lines changed

changes.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
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.6.0" date="2024-08-26">
27+
<action type="add" dev="senn" issue="49">
28+
Add mock implementation of Adobe Granite Asset API.
29+
</action>
30+
<action type="update" dev="sseifert">
31+
Update to latest OSGi Mock, Resource Resolver Mock, Sling Mock.
32+
</action>
33+
</release>
34+
2635
<release version="5.5.4" date="2024-07-18">
2736
<action type="update" dev="sseifert" issue="45">
2837
MockExternalizer: Apply Sling Mapping for externalized URLs.

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
/**
4848
* Mock implementation of {@link ContentElement} for structured content.
4949
*/
50+
@SuppressWarnings("java:S112") // allow throwing RuntimException
5051
class MockContentFragment_ContentElement_Structured implements ContentElement {
5152

5253
private final MockContentFragment contentFragment;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
/**
5252
* Mock implementation of {@link ContentElement} for text-based content.
5353
*/
54+
@SuppressWarnings("java:S112") // allow throwing RuntimException
5455
class MockContentFragment_ContentElement_Text implements ContentElement {
5556

5657
private final MockContentFragment contentFragment;

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,19 @@ public List<Template> getTemplates(String policyAbsolutePath, Predicate filter)
114114

115115
// AEM Cloud
116116
@SuppressWarnings("unused")
117-
public boolean isPolicyUsed(String arg0, @Nullable Predicate arg1) {
117+
public boolean isPolicyUsed(String arg0, @Nullable Predicate filter) {
118+
throw new UnsupportedOperationException();
119+
}
120+
121+
// AEM Cloud
122+
@SuppressWarnings("unused")
123+
public List<Template> getTemplates(String policyAbsolutePath, @Nullable java.util.function.Predicate filter) {
124+
throw new UnsupportedOperationException();
125+
}
126+
127+
// AEM Cloud
128+
@SuppressWarnings("unused")
129+
public boolean isPolicyUsed(String policyAbsolutePath, @Nullable java.util.function.Predicate filter) {
118130
throw new UnsupportedOperationException();
119131
}
120132

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* their mappings. Basically it stores one global content policy per resource type, and one mapping
4848
* for it. This is usually enough for unit tests.
4949
*/
50+
@SuppressWarnings("java:S112") // allow throwing RuntimException
5051
public final class MockContentPolicyStorage {
5152

5253
static final String RT_CONTENTPOLICY = "wcm/core/components/policy/policy";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
@ProviderType
6161
public final class MockLanguageManager implements LanguageManager {
6262

63+
/**
64+
* @deprecated Deprecated
65+
*/
6366
@Override
6467
@Deprecated(forRemoval = true)
6568
public Map<Locale, Info> getAdjacentInfo(final ResourceResolver resourceResolver, final String path) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
* Mock implementation of {@link TagManager}.
6363
*/
6464
@ProviderType
65+
@SuppressWarnings("java:S112") // allow throwing RuntimException
6566
public final class MockTagManager implements TagManager {
6667

6768
/** resource type for created tags */

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ class MockTemplate extends ResourceWrapper implements Template {
6666
}
6767

6868
@Override
69+
@SuppressWarnings("java:S1185") // overwrite due to different null constraints
6970
public String getPath() {
7071
return super.getPath();
7172
}
7273

7374
@Override
75+
@SuppressWarnings("java:S1185") // overwrite due to different null constraints
7476
public String getName() {
7577
return super.getName();
7678
}

core/src/main/java/io/wcm/testing/mock/aem/builder/ContentBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@
6969
* Helper class for building test content in the resource hierarchy with as less boilerplate code as possible.
7070
*/
7171
@ProviderType
72-
@SuppressWarnings("null")
72+
@SuppressWarnings({
73+
"null",
74+
"java:S112", // allow throwing RuntimException
75+
"java:S2176" // same name as superclass
76+
})
7377
public final class ContentBuilder extends org.apache.sling.testing.mock.sling.builder.ContentBuilder {
7478

7579
static final String DUMMY_TEMPLATE = "/apps/sample/templates/template1";

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* Should not be used directly but via the JUnit 4 rule or JUnit 5 extension.
6464
*/
6565
@ConsumerType
66+
@SuppressWarnings("java:S112") // allow throwing RuntimException
6667
public class AemContextImpl extends SlingContextImpl {
6768

6869
// default to publish instance run mode
@@ -180,6 +181,17 @@ protected final Map<String, Object> resourceResolverFactoryActivatorPropsMergeWi
180181
return assetManager;
181182
}
182183

184+
/**
185+
* @return Adobe Granite Asset manager
186+
*/
187+
public @NotNull com.adobe.granite.asset.api.AssetManager graniteAssetManager() {
188+
com.adobe.granite.asset.api.AssetManager assetManager = resourceResolver().adaptTo(com.adobe.granite.asset.api.AssetManager.class);
189+
if (assetManager == null) {
190+
throw new RuntimeException("No granite asset manager");
191+
}
192+
return assetManager;
193+
}
194+
183195
/**
184196
* @return Content builder for building test content
185197
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* unique root paths for each run, and cleans them up when done.
3131
*/
3232
@ProviderType
33+
@SuppressWarnings("java:S2176") // same name as superclass
3334
public final class UniqueRoot extends org.apache.sling.testing.mock.sling.context.UniqueRoot {
3435

3536
private Resource damRoot;

core/src/main/java/io/wcm/testing/mock/aem/context/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
/**
2121
* AEM context implementation for unit tests.
2222
*/
23-
@org.osgi.annotation.versioning.Version("2.0.0")
23+
@org.osgi.annotation.versioning.Version("2.1.0")
2424
package io.wcm.testing.mock.aem.context;

core/src/main/java/io/wcm/testing/mock/aem/dam/MockAemDamAdapterFactory.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
AdapterFactory.ADAPTABLE_CLASSES + "=org.apache.sling.api.resource.ResourceResolver",
4646
AdapterFactory.ADAPTER_CLASSES + "=com.day.cq.dam.api.Asset",
4747
AdapterFactory.ADAPTER_CLASSES + "=com.day.cq.dam.api.AssetManager",
48-
AdapterFactory.ADAPTER_CLASSES + "=com.day.cq.dam.api.Rendition"
48+
AdapterFactory.ADAPTER_CLASSES + "=com.day.cq.dam.api.Rendition",
49+
AdapterFactory.ADAPTER_CLASSES + "=com.adobe.granite.asset.api.Asset",
50+
AdapterFactory.ADAPTER_CLASSES + "=com.adobe.granite.asset.api.AssetManager",
51+
AdapterFactory.ADAPTER_CLASSES + "=com.adobe.granite.asset.api.Rendition"
4952
})
5053
@ProviderType
5154
public final class MockAemDamAdapterFactory implements AdapterFactory {
@@ -71,21 +74,27 @@ private void activate(BundleContext context) {
7174
return null;
7275
}
7376

74-
@SuppressWarnings("unchecked")
7577
private @Nullable <AdapterType> AdapterType getAdapter(@NotNull final Resource resource, @NotNull final Class<AdapterType> type) {
76-
if (type == Asset.class && DamUtil.isAsset(resource)) {
77-
return (AdapterType)new MockAsset(resource, eventAdmin, bundleContext);
78+
if (DamUtil.isAsset(resource)) {
79+
if (type == com.adobe.granite.asset.api.Asset.class) {
80+
return type.cast(new MockGraniteAssetWrapper(new MockAsset(resource, eventAdmin, bundleContext)));
81+
}
82+
else if (type == Asset.class) {
83+
return type.cast(new MockAsset(resource, eventAdmin, bundleContext));
84+
}
7885
}
79-
if (type == Rendition.class && DamUtil.isRendition(resource)) {
80-
return (AdapterType)new MockRendition(resource);
86+
if ((type == Rendition.class || type == com.adobe.granite.asset.api.Rendition.class) && DamUtil.isRendition(resource)) {
87+
return type.cast(new MockRendition(resource));
8188
}
8289
return null;
8390
}
8491

85-
@SuppressWarnings("unchecked")
8692
private @Nullable <AdapterType> AdapterType getAdapter(@NotNull final ResourceResolver resolver, @NotNull final Class<AdapterType> type) {
8793
if (type == AssetManager.class) {
88-
return (AdapterType)new MockAssetManager(resolver, eventAdmin, bundleContext);
94+
return type.cast(new MockAssetManager(resolver, eventAdmin, bundleContext));
95+
}
96+
else if (type == com.adobe.granite.asset.api.AssetManager.class) {
97+
return type.cast(new MockGraniteAssetManagerWrapper(resolver));
8998
}
9099
return null;
91100
}

core/src/main/java/io/wcm/testing/mock/aem/dam/MockAsset.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.osgi.framework.BundleContext;
4444
import org.osgi.service.event.EventAdmin;
4545

46+
import com.adobe.granite.asset.api.RenditionHandler;
4647
import com.day.cq.commons.jcr.JcrConstants;
4748
import com.day.cq.dam.api.Asset;
4849
import com.day.cq.dam.api.DamConstants;
@@ -54,7 +55,10 @@
5455
/**
5556
* Mock implementation of {@link Asset}.
5657
*/
57-
@SuppressWarnings("null")
58+
@SuppressWarnings({
59+
"null",
60+
"java:S112" // allow throwing RuntimException
61+
})
5862
class MockAsset extends ResourceWrapper implements Asset {
5963

6064
private final ResourceResolver resourceResolver;
@@ -76,11 +80,14 @@ class MockAsset extends ResourceWrapper implements Asset {
7680
this.bundleContext = bundleContext;
7781
}
7882

79-
@SuppressWarnings("unchecked")
8083
@Override
8184
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
8285
if (type == Resource.class) {
83-
return (AdapterType)resource;
86+
return type.cast(resource);
87+
}
88+
//to be able to adapt to granite asset
89+
if (type == com.adobe.granite.asset.api.Asset.class) {
90+
return type.cast(new MockGraniteAssetWrapper(this));
8491
}
8592
return super.adaptTo(type);
8693
}
@@ -243,14 +250,18 @@ public String getID() {
243250
return resource.getValueMap().get(JcrConstants.JCR_UUID, "");
244251
}
245252

246-
247-
// --- unsupported operations ---
248-
249253
@Override
250254
public Rendition addRendition(String name, InputStream is, Map<String, Object> map) {
251-
throw new UnsupportedOperationException();
255+
Object mimeTypeObject = map.get(RenditionHandler.PROPERTY_RENDITION_MIME_TYPE);
256+
if (mimeTypeObject instanceof String) {
257+
return addRendition(name, is, mimeTypeObject.toString());
258+
}
259+
throw new UnsupportedOperationException("Mime type property missing in map: " + RenditionHandler.PROPERTY_RENDITION_MIME_TYPE);
252260
}
253261

262+
263+
// --- unsupported operations ---
264+
254265
@Override
255266
public Rendition getCurrentOriginal() {
256267
throw new UnsupportedOperationException();
@@ -311,27 +322,24 @@ public void initAssetState() {
311322
throw new UnsupportedOperationException();
312323
}
313324

314-
// AEM 6.5
315-
@SuppressWarnings("unused")
316-
public Rendition addRendition(String arg0, Binary arg1, String arg2) {
325+
@Override
326+
public Rendition addRendition(String name, Binary binary, String mimeType) {
317327
throw new UnsupportedOperationException();
318328
}
319329

320-
// AEM 6.5
321-
@SuppressWarnings("unused")
322-
public Rendition addRendition(String arg0, Binary arg1, Map<String, Object> arg2) {
330+
@Override
331+
public Rendition addRendition(String name, Binary binary, Map<String, Object> arg2) {
323332
throw new UnsupportedOperationException();
324333
}
325334

326-
// AEM 6.5.5
327-
@SuppressWarnings("unused")
328-
public Revision createRevision(String arg0, String arg1, User arg2) {
335+
@Override
336+
public Revision createRevision(String name, String binary, User arg2) {
329337
throw new UnsupportedOperationException();
330338
}
331339

332340
// AEM Cloud
333341
@SuppressWarnings("unused")
334-
public Rendition setRendition(String arg0, Binary arg1, String arg2) {
342+
public Rendition setRendition(String name, Binary binary, String mimeType) {
335343
throw new UnsupportedOperationException();
336344
}
337345

core/src/main/java/io/wcm/testing/mock/aem/dam/MockAssetManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
/**
6565
* Mock implementation of {@link AssetManager}
6666
*/
67-
@SuppressWarnings("null")
67+
@SuppressWarnings({
68+
"null",
69+
"java:S112" // allow throwing RuntimException
70+
})
6871
class MockAssetManager implements AssetManager {
6972

7073
private final ResourceResolver resourceResolver;

0 commit comments

Comments
 (0)