-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added preview handling for converter
- Loading branch information
Showing
6 changed files
with
170 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
commons-asset-core/src/test/java/io/rocketbase/commons/converter/AssetConverterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.rocketbase.commons.converter; | ||
|
||
import io.rocketbase.commons.config.AssetConfiguration; | ||
import io.rocketbase.commons.dto.asset.AssetRead; | ||
import io.rocketbase.commons.dto.asset.AssetType; | ||
import io.rocketbase.commons.dto.asset.PreviewSize; | ||
import io.rocketbase.commons.dto.asset.Resolution; | ||
import io.rocketbase.commons.model.AssetEntity; | ||
import io.rocketbase.commons.service.MongoFileStorageService; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.time.LocalDateTime; | ||
import java.util.Arrays; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
public class AssetConverterTest { | ||
|
||
@Test | ||
public void testFromEntityWithLocalRender() { | ||
// given | ||
AssetConfiguration config = new AssetConfiguration(); | ||
config.setApiEndpoint("/api/asset"); | ||
config.setRenderEndpoint("/get/asset"); | ||
|
||
HttpServletRequest mockedRequest = Mockito.mock(HttpServletRequest.class); | ||
Mockito.when(mockedRequest.getScheme()) | ||
.thenReturn("http"); | ||
Mockito.when(mockedRequest.getServerName()) | ||
.thenReturn("localhost"); | ||
Mockito.when(mockedRequest.getServerPort()) | ||
.thenReturn(8080); | ||
Mockito.when(mockedRequest.getContextPath()) | ||
.thenReturn("/"); | ||
|
||
String baseUrl = "http://localhost:8080" + config.getRenderEndpoint() + "/"; | ||
|
||
AssetConverter converter = new AssetConverter(config, new MongoFileStorageService(null)); | ||
// when | ||
AssetRead assetRead = converter.fromEntity(AssetEntity.builder() | ||
.id("1235678") | ||
.urlPath("12345678") | ||
.fileSize(1234L) | ||
.created(LocalDateTime.now()) | ||
.originalFilename("originial.png") | ||
.type(AssetType.PNG) | ||
.systemRefId("123") | ||
.resolution(new Resolution(100, 200)) | ||
.build(), Arrays.asList(PreviewSize.S, PreviewSize.M, PreviewSize.L), mockedRequest); | ||
|
||
// then | ||
assertThat(assetRead, notNullValue()); | ||
assertThat(assetRead.getPreviews(), notNullValue()); | ||
assertThat(assetRead.getPreviews().getPreviewMap().size(), equalTo(3)); | ||
assertThat(assetRead.getPreviews().getPreviewMap().get(PreviewSize.S), equalTo(baseUrl + assetRead.getId() + "/s")); | ||
assertThat(assetRead.getPreviews().getPreviewMap().get(PreviewSize.M), equalTo(baseUrl + assetRead.getId() + "/m")); | ||
assertThat(assetRead.getPreviews().getPreviewMap().get(PreviewSize.L), equalTo(baseUrl + assetRead.getId() + "/l")); | ||
|
||
} | ||
} |