Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Sep 16, 2024
2 parents e3ae2bd + 44c3367 commit 9922b78
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 16 deletions.
6 changes: 6 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<body>

<release version="5.6.2" date="2024-09-16">
<action type="update" dev="joerghoh" issue="50">
Add support for Rendition.getBinary() method.
</action>
</release>

<release version="5.6.0" date="2024-08-26">
<action type="add" dev="senn" issue="49">
Add mock implementation of Adobe Granite Asset API.
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down
56 changes: 52 additions & 4 deletions core/src/main/java/io/wcm/testing/mock/aem/dam/MockRendition.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}
6 changes: 3 additions & 3 deletions junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<scope>compile</scope>
</dependency>

Expand Down Expand Up @@ -87,7 +87,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -54,14 +54,14 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.core</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<packaging>pom</packaging>

<name>AEM Mocks</name>
Expand Down Expand Up @@ -71,7 +71,7 @@
<logging-logback.version>1.0.0</logging-logback.version>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2024-08-26T09:18:14Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-09-16T09:26:26Z</project.build.outputTimestamp>

</properties>

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<relativePath>parent/pom.xml</relativePath>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.root</artifactId>
<packaging>pom</packaging>
<version>5.6.0</version>
<version>5.6.2</version>

<name>AEM Mocks</name>
<url>${site.url}/${site.url.module.prefix}/</url>
Expand Down
2 changes: 1 addition & 1 deletion relocate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.parent</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

Expand Down

0 comments on commit 9922b78

Please sign in to comment.