diff --git a/changes.xml b/changes.xml index 1c9f6763..8171291b 100644 --- a/changes.xml +++ b/changes.xml @@ -23,6 +23,12 @@ xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd"> + + + Add support for Rendition.getBinary() method. + + + Add mock implementation of Adobe Granite Asset API. diff --git a/core/pom.xml b/core/pom.xml index 6c34b777..3ff74270 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -25,7 +25,7 @@ io.wcm io.wcm.testing.aem-mock.parent - 5.6.0 + 5.6.2 ../parent/pom.xml diff --git a/core/src/main/java/io/wcm/testing/mock/aem/dam/MockRendition.java b/core/src/main/java/io/wcm/testing/mock/aem/dam/MockRendition.java index e357ba12..9168aa36 100644 --- a/core/src/main/java/io/wcm/testing/mock/aem/dam/MockRendition.java +++ b/core/src/main/java/io/wcm/testing/mock/aem/dam/MockRendition.java @@ -21,16 +21,22 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import javax.jcr.Binary; +import javax.jcr.RepositoryException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.jackrabbit.api.binary.BinaryDownload; +import org.apache.jackrabbit.api.binary.BinaryDownloadOptions; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceUtil; import org.apache.sling.api.resource.ResourceWrapper; import org.apache.sling.api.resource.ValueMap; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import com.day.cq.commons.jcr.JcrConstants; import com.day.cq.dam.api.Asset; @@ -123,12 +129,54 @@ public boolean equals(Object obj) { return StringUtils.equals(getPath(), ((MockRendition)obj).getPath()); } - - // --- unsupported operations --- - @Override public Binary getBinary() { - throw new UnsupportedOperationException(); + return new MockBinary(this); + } + + + private static class MockBinary implements BinaryDownload { + + private Rendition rendition; + + MockBinary(Rendition rendition) { + this.rendition = rendition; + } + + + @Override + public InputStream getStream() throws RepositoryException { + return rendition.getStream(); + } + + @Override + public int read(byte[] b, long position) throws IOException, RepositoryException { + throw new UnsupportedOperationException(); + } + + @Override + public long getSize() throws RepositoryException { + return rendition.getSize(); + } + + @Override + public void dispose() { + // nothing to do + } + + @Override + public @Nullable URI getURI(BinaryDownloadOptions downloadOptions) throws RepositoryException { + final String path = "https://blostore.local/blostore/" + rendition.getPath(); + try { + return new URI(path); + } + catch (URISyntaxException e) { + // nothing + } + return null; + } + } + } diff --git a/core/src/test/java/io/wcm/testing/mock/aem/dam/MockRenditionTest.java b/core/src/test/java/io/wcm/testing/mock/aem/dam/MockRenditionTest.java index 82f712c3..1bddb77e 100644 --- a/core/src/test/java/io/wcm/testing/mock/aem/dam/MockRenditionTest.java +++ b/core/src/test/java/io/wcm/testing/mock/aem/dam/MockRenditionTest.java @@ -23,7 +23,12 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import javax.jcr.Binary; +import javax.jcr.RepositoryException; + +import org.apache.jackrabbit.api.binary.BinaryDownload; import org.apache.sling.api.resource.Resource; import org.junit.Before; import org.junit.Rule; @@ -95,4 +100,18 @@ public void testAdaptTo() { assertSame(rendition, rendition.adaptTo(com.adobe.granite.asset.api.Rendition.class)); } + @Test + public void testBinaryDownload() throws RepositoryException { + Binary binary = rendition.getBinary(); + assertNotNull(binary); + assertEquals(0L, binary.getSize()); + assertNotNull(binary.getStream()); + + assertTrue(binary instanceof BinaryDownload); + assertEquals("https://blostore.local/blostore//content/dam/sample/portraits/scott_reynolds.jpg/jcr:content/renditions/original", + ((BinaryDownload)binary).getURI(null).toString()); + + binary.dispose(); + } + } diff --git a/junit4/pom.xml b/junit4/pom.xml index 9026ccf4..d2224b2e 100644 --- a/junit4/pom.xml +++ b/junit4/pom.xml @@ -25,7 +25,7 @@ io.wcm io.wcm.testing.aem-mock.parent - 5.6.0 + 5.6.2 ../parent/pom.xml @@ -54,7 +54,7 @@ io.wcm io.wcm.testing.aem-mock.core - 5.6.0 + 5.6.2 compile @@ -87,7 +87,7 @@ io.wcm io.wcm.testing.aem-mock.core - 5.6.0 + 5.6.2 tests test diff --git a/junit5/pom.xml b/junit5/pom.xml index 282b9499..61cc5ee4 100644 --- a/junit5/pom.xml +++ b/junit5/pom.xml @@ -25,7 +25,7 @@ io.wcm io.wcm.testing.aem-mock.parent - 5.6.0 + 5.6.2 ../parent/pom.xml @@ -54,14 +54,14 @@ io.wcm io.wcm.testing.aem-mock.core - 5.6.0 + 5.6.2 compile io.wcm io.wcm.testing.aem-mock.core - 5.6.0 + 5.6.2 tests test diff --git a/parent/pom.xml b/parent/pom.xml index ab774748..58597920 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -31,7 +31,7 @@ io.wcm io.wcm.testing.aem-mock.parent - 5.6.0 + 5.6.2 pom AEM Mocks @@ -71,7 +71,7 @@ 1.0.0 - 2024-08-26T09:18:14Z + 2024-09-16T09:26:26Z diff --git a/pom.xml b/pom.xml index cc92f311..aff27674 100644 --- a/pom.xml +++ b/pom.xml @@ -25,14 +25,14 @@ io.wcm io.wcm.testing.aem-mock.parent - 5.6.0 + 5.6.2 parent/pom.xml io.wcm io.wcm.testing.aem-mock.root pom - 5.6.0 + 5.6.2 AEM Mocks ${site.url}/${site.url.module.prefix}/ diff --git a/relocate/pom.xml b/relocate/pom.xml index 7b7c9069..09d0f01b 100644 --- a/relocate/pom.xml +++ b/relocate/pom.xml @@ -25,7 +25,7 @@ io.wcm io.wcm.testing.aem-mock.parent - 5.6.0 + 5.6.2 ../parent/pom.xml