Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/sphinx-guides/source/api/dataaccess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ the following parameter values are supported (for image and pdf files only):
============== ===========
Value Description
============== ===========
true Generates a thumbnail image, by rescaling to the default thumbnail size (64 pixels)
``N`` Rescales the image to ``N`` pixels.
true Generates a thumbnail image by rescaling to the default thumbnail size (64 pixels wide).
``N`` Rescales the image to ``N`` pixels wide. ``imageThumb=true`` and ``imageThumb=64`` are equivalent.
============== ===========

Multiple File ("bundle") download
Expand Down
24 changes: 21 additions & 3 deletions src/test/java/edu/harvard/iq/dataverse/api/SearchIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,25 @@ public void testDatasetThumbnail() {


Response getThumbnailImageA = UtilIT.getDatasetThumbnail(datasetPersistentId, apiToken); //
getThumbnailImageA.prettyPrint();
getThumbnailImageA.then().assertThat()
.contentType("image/png")
.statusCode(OK.getStatusCode());

// heads up that calling prettyPrint on an image will increase the length.
assertEquals(1153, getThumbnailImageA.asByteArray().length);

// A width of "true" is 1893 bytes. 64 pixels wide is the default.
// A width of "500" is 11372 bytes. 500 pixels wide.
String trueOrWidthInPixels = "true";
// String trueOrWidthInPixels = "500";
Response getFileThumbnailImageA = UtilIT.getFileThumbnail(dataFileId1.toString(), trueOrWidthInPixels, apiToken);
getFileThumbnailImageA.then().assertThat()
.contentType("image/png")
.statusCode(OK.getStatusCode());

// heads up that calling prettyPrint on an image will increase the length.
assertEquals(1893, getFileThumbnailImageA.asByteArray().length);

InputStream inputStream2creator = UtilIT.getInputStreamFromUnirest(thumbnailUrl, apiToken);
assertEquals(treesAsBase64, UtilIT.inputStreamToDataUrlSchemeBase64Png(inputStream2creator));

Expand All @@ -407,7 +421,6 @@ public void testDatasetThumbnail() {
}

Response getThumbnailImage2 = UtilIT.getDatasetThumbnail(datasetPersistentId, apiToken);
getThumbnailImage2.prettyPrint();
getThumbnailImage2.then().assertThat()
// .body(CoreMatchers.equalTo(decodedImg))
.contentType("image/png")
Expand All @@ -419,6 +432,9 @@ public void testDatasetThumbnail() {
// .content(CoreMatchers.equalTo(decodedImg))
.statusCode(200);

// heads up that calling prettyPrint on an image will increase the length.
assertEquals(1153, getThumbnailImage2.asByteArray().length);

String pathToFile = "src/main/webapp/resources/images/dataverseproject.png";
Response uploadSecondImage = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);
uploadSecondImage.prettyPrint();
Expand Down Expand Up @@ -594,11 +610,13 @@ public void testDatasetThumbnail() {
.statusCode(200);

Response getThumbnailImageNoSpecialAccess99 = UtilIT.getDatasetThumbnail(datasetPersistentId, noSpecialAcessApiToken);
// getThumbnailImageNoSpecialAccess99.prettyPrint();
getThumbnailImageNoSpecialAccess99.then().assertThat()
.contentType("image/png")
.statusCode(OK.getStatusCode());

// heads up that calling prettyPrint on an image will increase the length.
assertEquals(1153, getThumbnailImage2.asByteArray().length);

InputStream inputStream99creator = UtilIT.getInputStreamFromUnirest(thumbnailUrl, apiToken);
assertEquals(treesAsBase64, UtilIT.inputStreamToDataUrlSchemeBase64Png(inputStream99creator));

Expand Down
9 changes: 9 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,15 @@ static Response getDatasetThumbnailMetadata(Integer datasetId, String apiToken)
.get("/api/admin/datasets/thumbnailMetadata/" + datasetId);
}

/**
* @param trueOrWidthInPixels Passing "true" will result in the default width in pixels (64).
*/
static Response getFileThumbnail(String fileDatabaseId, String trueOrWidthInPixels, String apiToken) {
return given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
.get("/api/access/datafile/" + fileDatabaseId + "?imageThumb=" + trueOrWidthInPixels);
}

static Response useThumbnailFromDataFile(String datasetPersistentId, long dataFileId1, String apiToken) {
return given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
Expand Down