From 56d9efa33e492a0005e1a8c045f2d524e5e846ea Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 15 Jan 2024 14:29:34 +0100 Subject: [PATCH] uses md5 hash as asset id --- changes.xml | 2 +- .../java/io/wcm/testing/mock/aem/dam/MockAssetDelivery.java | 6 +++++- .../main/java/io/wcm/testing/mock/aem/dam/package-info.java | 2 +- .../io/wcm/testing/mock/aem/dam/MockAssetDeliveryTest.java | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/changes.xml b/changes.xml index 9dc15235..63e9dcf7 100644 --- a/changes.xml +++ b/changes.xml @@ -24,7 +24,7 @@ - + Add mock for AssetDelivery OSGi service. diff --git a/core/src/main/java/io/wcm/testing/mock/aem/dam/MockAssetDelivery.java b/core/src/main/java/io/wcm/testing/mock/aem/dam/MockAssetDelivery.java index 6f8ec2d1..b54dd24c 100644 --- a/core/src/main/java/io/wcm/testing/mock/aem/dam/MockAssetDelivery.java +++ b/core/src/main/java/io/wcm/testing/mock/aem/dam/MockAssetDelivery.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.stream.Collectors; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.sling.api.resource.Resource; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,6 +35,7 @@ /** * Mock implementation of {@link AssetDelivery}. + * As Asset ID a md5 hash of the path is used. */ @Component(service = AssetDelivery.class) public final class MockAssetDelivery implements AssetDelivery { @@ -69,9 +71,11 @@ public final class MockAssetDelivery implements AssetDelivery { .map(entry -> URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8) + "=" + URLEncoder.encode(entry.getValue().toString(), StandardCharsets.UTF_8)) .collect(Collectors.joining("&")); + String assetId = DigestUtils.md5Hex(path); + StringBuilder sb = new StringBuilder(); sb.append(ASSET_DELIVERY_URL_PREFIX) - .append("/").append(path.hashCode()) + .append("/").append(assetId) .append("/").append(seoname) .append(".").append(format); if (!urlParams.isEmpty()) { diff --git a/core/src/main/java/io/wcm/testing/mock/aem/dam/package-info.java b/core/src/main/java/io/wcm/testing/mock/aem/dam/package-info.java index 587a5d38..06e667ad 100644 --- a/core/src/main/java/io/wcm/testing/mock/aem/dam/package-info.java +++ b/core/src/main/java/io/wcm/testing/mock/aem/dam/package-info.java @@ -20,5 +20,5 @@ /** * Mock implementation of selected AEM DAM APIs. */ -@org.osgi.annotation.versioning.Version("2.2.0") +@org.osgi.annotation.versioning.Version("2.3.0") package io.wcm.testing.mock.aem.dam; diff --git a/core/src/test/java/io/wcm/testing/mock/aem/dam/MockAssetDeliveryTest.java b/core/src/test/java/io/wcm/testing/mock/aem/dam/MockAssetDeliveryTest.java index 1e95150c..49a1a1e4 100644 --- a/core/src/test/java/io/wcm/testing/mock/aem/dam/MockAssetDeliveryTest.java +++ b/core/src/test/java/io/wcm/testing/mock/aem/dam/MockAssetDeliveryTest.java @@ -57,8 +57,8 @@ public void setUp() throws Exception { @Test public void testGetDeliveryURL() { - assertWithParams("/asset/delivery/889908393/test.jpg", Map.of()); - assertWithParams("/asset/delivery/889908393/test.jpg?quality=80&width=100", Map.of( + assertWithParams("/asset/delivery/2cb13619ffaa0b3012476fbd96ec1a29/test.jpg", Map.of()); + assertWithParams("/asset/delivery/2cb13619ffaa0b3012476fbd96ec1a29/test.jpg?quality=80&width=100", Map.of( "width", 100, "quality", 80, "invalid", 1));