Skip to content

Commit

Permalink
Test added
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-tosca committed Oct 2, 2024
1 parent c2e1e15 commit c46e0ce
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,57 @@ public void testCreatePublishDestroyDataset() {
deleteDatasetResponse.prettyPrint();
assertEquals(200, deleteDatasetResponse.getStatusCode());

// Start of deaccession test.

// Create Dataset for deaccession test.
Response deaccessionTestDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken);
deaccessionTestDataset.prettyPrint();
deaccessionTestDataset.then().assertThat().statusCode(CREATED.getStatusCode());
Integer deaccessionTestDatasetId = UtilIT.getDatasetIdFromResponse(deaccessionTestDataset);

// File upload for deaccession test.
String pathToFile = "src/main/webapp/resources/images/dataverseproject.png";
Response uploadResponse = UtilIT.uploadFileViaNative(deaccessionTestDatasetId.toString(), pathToFile, apiToken);
uploadResponse.prettyPrint();
uploadResponse.then().assertThat().statusCode(OK.getStatusCode());
Integer deaccessionTestFileId = JsonPath.from(uploadResponse.body().asString()).getInt("data.files[0].dataFile.id");

// Publish Dataset for deaccession test.
Response deaccessionTestPublishResponse = UtilIT.publishDatasetViaNativeApi(deaccessionTestDatasetId, "major", apiToken);
deaccessionTestPublishResponse.prettyPrint();

// Deaccession Dataset for deaccession test.
Response deaccessionTestDatasetResponse = UtilIT.deaccessionDataset(deaccessionTestDatasetId, DS_VERSION_LATEST_PUBLISHED, "Test deaccession reason.", null, apiToken);
deaccessionTestDatasetResponse.prettyPrint();
deaccessionTestDatasetResponse.then().assertThat().statusCode(OK.getStatusCode());

// Version check for deaccession test - Deaccessioned.
Response deaccessionTestVersions = UtilIT.getDatasetVersions(deaccessionTestDatasetId.toString(), apiToken);
deaccessionTestVersions.prettyPrint();
deaccessionTestVersions.then().assertThat()
.body("data[0].latestVersionPublishingState", equalTo("DEACCESSIONED"))
.statusCode(OK.getStatusCode());

// File deletion / Draft creation due deltigion check for deaccession test.
Response deaccessionTestDeleteFile = UtilIT.deleteFileInDataset(deaccessionTestFileId, apiToken);
deaccessionTestDeleteFile.prettyPrint();

// Version check for deaccession test - Draft.
deaccessionTestVersions = UtilIT.getDatasetVersions(deaccessionTestDatasetId.toString(), apiToken);
deaccessionTestVersions.prettyPrint();
deaccessionTestVersions.then().assertThat()
.body("data[0].latestVersionPublishingState", equalTo("DRAFT"))
.statusCode(OK.getStatusCode());

// Deleting Dataset for deaccession test.
Response deaccessionTestDelete = UtilIT.destroyDataset(deaccessionTestDatasetId, apiToken);
deaccessionTestDelete.prettyPrint();
deaccessionTestDelete.then()
.assertThat()
.statusCode(OK.getStatusCode());

// End of deaccession test.

Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken);
deleteDataverseResponse.prettyPrint();
assertEquals(200, deleteDataverseResponse.getStatusCode());
Expand Down

0 comments on commit c46e0ce

Please sign in to comment.