Skip to content

Commit

Permalink
Added: FilesIT testGetFileInfo test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Feb 14, 2024
1 parent fc8aac3 commit 153b9ae
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import org.junit.jupiter.api.BeforeAll;
import io.restassured.path.json.JsonPath;

import static edu.harvard.iq.dataverse.api.ApiConstants.DS_VERSION_DRAFT;
import static edu.harvard.iq.dataverse.api.ApiConstants.DS_VERSION_LATEST_PUBLISHED;
import static edu.harvard.iq.dataverse.api.ApiConstants.*;
import static io.restassured.path.json.JsonPath.with;
import io.restassured.path.xml.XmlPath;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
Expand Down Expand Up @@ -1450,9 +1449,9 @@ public void testGetFileInfo() {
.statusCode(NOT_FOUND.getStatusCode());

// Update the file metadata
String newFileName = "trees_2.png";
String newFileNameFirstUpdate = "trees_2.png";
JsonObjectBuilder updateFileMetadata = Json.createObjectBuilder()
.add("label", newFileName);
.add("label", newFileNameFirstUpdate);
Response updateFileMetadataResponse = UtilIT.updateFileMetadata(dataFileId, updateFileMetadata.build().toString(), superUserApiToken);
updateFileMetadataResponse.then().statusCode(OK.getStatusCode());

Expand All @@ -1471,12 +1470,46 @@ public void testGetFileInfo() {
publishDatasetResp.then().assertThat()
.statusCode(OK.getStatusCode());

// Update the file metadata once again
String newFileNameSecondUpdate = "trees_3.png";
updateFileMetadata = Json.createObjectBuilder()
.add("label", newFileNameSecondUpdate);
updateFileMetadataResponse = UtilIT.updateFileMetadata(dataFileId, updateFileMetadata.build().toString(), superUserApiToken);
updateFileMetadataResponse.then().statusCode(OK.getStatusCode());

// Regular user should get to see latest published file data
getFileDataResponse = UtilIT.getFileData(dataFileId, apiTokenRegular, DS_VERSION_LATEST_PUBLISHED);
getFileDataResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.label", equalTo(newFileName));
// TODO
.body("data.label", equalTo(newFileNameFirstUpdate));

// Regular user should get to see latest published file data if latest is requested
getFileDataResponse = UtilIT.getFileData(dataFileId, apiTokenRegular, DS_VERSION_LATEST);
getFileDataResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.label", equalTo(newFileNameFirstUpdate));

// Superuser should get to see draft file data if latest is requested
getFileDataResponse = UtilIT.getFileData(dataFileId, superUserApiToken, DS_VERSION_LATEST);
getFileDataResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.label", equalTo(newFileNameSecondUpdate));

// Publish dataset once again
publishDatasetResp = UtilIT.publishDatasetViaNativeApi(datasetId, "major", superUserApiToken);
publishDatasetResp.then().assertThat()
.statusCode(OK.getStatusCode());

// Regular user should get to see file data by specific version number
getFileDataResponse = UtilIT.getFileData(dataFileId, apiTokenRegular, "2.0");
getFileDataResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.label", equalTo(newFileNameFirstUpdate));

getFileDataResponse = UtilIT.getFileData(dataFileId, apiTokenRegular, "3.0");
getFileDataResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.label", equalTo(newFileNameSecondUpdate));

// Cleanup
Response destroyDatasetResponse = UtilIT.destroyDataset(datasetId, superUserApiToken);
Expand Down

0 comments on commit 153b9ae

Please sign in to comment.