Skip to content

Commit

Permalink
added another test, for the pagination functionality in the /versions…
Browse files Browse the repository at this point in the history
… api

(also being added in 6.1). #9763
  • Loading branch information
landreev committed Sep 13, 2023
1 parent bfe7f9c commit 8e894c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public void testCreatePublishDestroyDataset() {

/**
* The apis (/api/datasets/{id}/versions and /api/datasets/{id}/versions/{vid}
* are called from other RestAssured tests, in this class and also FileIT.
* are already called from other RestAssured tests, in this class and also FileIT.
* But this test is dedicated to this api specifically, and focuses on the
* functionality added to it in 6.1.
*/
Expand All @@ -584,8 +584,6 @@ public void testDatasetVersionsAPI() {
String pathToFile = "src/main/webapp/resources/images/dataverseproject.png";
Response uploadResponse = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);
uploadResponse.then().assertThat().statusCode(OK.getStatusCode());

Integer fileId = JsonPath.from(uploadResponse.body().asString()).getInt("data.files[0].dataFile.id");

// Check that the file we just uploaded is shown by the versions api:
Response unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, ":draft", apiToken);
Expand Down Expand Up @@ -615,13 +613,27 @@ public void testDatasetVersionsAPI() {
// We should now have a published version, and a draft.

// Call /versions api, *with the owner api token*, make sure both
// versions are listed
// versions are listed; also check that the correct numbers of files
// are shown in each version (2 in the draft, 1 in the published).
Response versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiToken);
versionsResponse.prettyPrint();
versionsResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.size()", equalTo(2));

.body("data.size()", equalTo(2))
.body("data[0].files.size()", equalTo(2))
.body("data[1].files.size()", equalTo(1));

// Now call the this api with the new (as of 6.1) pagination parameters
Integer offset = 0;
Integer howmany = 1;
versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiToken, offset, howmany);
// (the above should return only one version, the draft)
versionsResponse.prettyPrint();
versionsResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.size()", equalTo(1))
.body("data[0].files.size()", equalTo(2));

// And now call it with an un-privileged token, to make sure only one
// (the published one) version is shown:

Expand All @@ -630,7 +642,7 @@ public void testDatasetVersionsAPI() {
versionsResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.size()", equalTo(1));

// And now call the "short", no-files version of the same api
versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms, skipFiles);
versionsResponse.prettyPrint();
Expand Down
22 changes: 22 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 @@ -1803,6 +1803,14 @@ static Response getDatasetVersions(String idOrPersistentId, String apiToken) {
}

static Response getDatasetVersions(String idOrPersistentId, String apiToken, boolean skipFiles) {
return getDatasetVersions(idOrPersistentId, apiToken, null, null, skipFiles);
}

static Response getDatasetVersions(String idOrPersistentId, String apiToken, Integer offset, Integer limit) {
return getDatasetVersions(idOrPersistentId, apiToken, offset, limit, false);
}

static Response getDatasetVersions(String idOrPersistentId, String apiToken, Integer offset, Integer limit, boolean skipFiles) {
logger.info("Getting Dataset Versions");
String idInPath = idOrPersistentId; // Assume it's a number.
String optionalQueryParam = ""; // If idOrPersistentId is a number we'll just put it in the path.
Expand All @@ -1817,6 +1825,20 @@ static Response getDatasetVersions(String idOrPersistentId, String apiToken, boo
optionalQueryParam = optionalQueryParam.concat("&includeFiles=false");
}
}
if (offset != null) {
if ("".equals(optionalQueryParam)) {
optionalQueryParam = "?offset="+offset;
} else {
optionalQueryParam = optionalQueryParam.concat("&offset="+offset);
}
}
if (limit != null) {
if ("".equals(optionalQueryParam)) {
optionalQueryParam = "?limit="+limit;
} else {
optionalQueryParam = optionalQueryParam.concat("&limit="+limit);
}
}
RequestSpecification requestSpecification = given();
if (apiToken != null) {
requestSpecification = given()
Expand Down

0 comments on commit 8e894c3

Please sign in to comment.