Skip to content

Commit

Permalink
uses md5 hash as asset id
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jan 15, 2024
1 parent 31b5e87 commit 56d9efa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<body>

<release version="5.5.0" date="not released">
<action type="add" dev="sseifert">
<action type="add" dev="sseifert" issue="30">
Add mock for AssetDelivery OSGi service.
</action>
<action type="update" dev="sseifert">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 56d9efa

Please sign in to comment.