Skip to content

Commit

Permalink
Merge pull request IQSS#10113 from jp-tosca/10112-ProvIT-enable-fix
Browse files Browse the repository at this point in the history
10112-ProvIT-enable-fix
  • Loading branch information
pdurbin authored Nov 14, 2023
2 parents e284402 + c09034d commit 3305c4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
35 changes: 24 additions & 11 deletions src/test/java/edu/harvard/iq/dataverse/api/ProvIT.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
package edu.harvard.iq.dataverse.api;

import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import io.restassured.RestAssured;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import static jakarta.ws.rs.core.Response.Status.CREATED;
import static jakarta.ws.rs.core.Response.Status.OK;
import static jakarta.ws.rs.core.Response.Status.BAD_REQUEST;
import static jakarta.ws.rs.core.Response.Status.CREATED;
import static jakarta.ws.rs.core.Response.Status.FORBIDDEN;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static jakarta.ws.rs.core.Response.Status.OK;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;

import org.junit.jupiter.api.AfterAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class ProvIT {

private static boolean provEnabled = false;

@BeforeAll
public static void setUpClass() {
RestAssured.baseURI = UtilIT.getRestAssuredBaseUri();
Response provCollectionStatus = UtilIT.getSetting(SettingsServiceBean.Key.ProvCollectionEnabled);

provEnabled = provCollectionStatus.getStatusCode() == 200;
if (!provEnabled) {
UtilIT.enableSetting(SettingsServiceBean.Key.ProvCollectionEnabled);
}
}


@Test
public void testFreeformDraftActions() {

Response createDepositor = UtilIT.createRandomUser();
createDepositor.prettyPrint();
createDepositor.then().assertThat()
Expand Down Expand Up @@ -71,6 +81,7 @@ public void testFreeformDraftActions() {
JsonObject provFreeFormGood = Json.createObjectBuilder()
.add("text", "I inherited this file from my grandfather.")
.build();

Response uploadProvFreeForm = UtilIT.uploadProvFreeForm(dataFileId.toString(), provFreeFormGood, apiTokenForDepositor);
uploadProvFreeForm.prettyPrint();
uploadProvFreeForm.then().assertThat()
Expand All @@ -80,8 +91,7 @@ public void testFreeformDraftActions() {
datasetVersions.prettyPrint();
datasetVersions.then().assertThat()
.body("data[0].versionState", equalTo("DRAFT"));



}

@Test
Expand Down Expand Up @@ -196,6 +206,7 @@ public void testAddProvFile() {
.body("data.json", notNullValue(String.class));
assertEquals(200, getProvJson.getStatusCode());


// TODO: Test that if provenance already exists in CPL (e.g. cplId in fileMetadata is not 0) upload returns error.
// There are currently no api endpoints to set up up this test.

Expand All @@ -204,11 +215,13 @@ public void testAddProvFile() {
deleteProvJson.then().assertThat()
.statusCode(FORBIDDEN.getStatusCode()); //cannot delete json of a published dataset

// Command removed, redundant
// Response deleteProvFreeForm = UtilIT.deleteProvFreeForm(dataFileId.toString(), apiTokenForDepositor);
// deleteProvFreeForm.prettyPrint();
// deleteProvFreeForm.then().assertThat()
// .statusCode(OK.getStatusCode());

}

@AfterAll
public static void tearDownClass() {
if(!provEnabled){
UtilIT.deleteSetting(SettingsServiceBean.Key.ProvCollectionEnabled);
}
}
}
2 changes: 1 addition & 1 deletion tests/integration-tests.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DataversesIT,DatasetsIT,SwordIT,AdminIT,BuiltinUsersIT,UsersIT,UtilIT,ConfirmEmailIT,FileMetadataIT,FilesIT,SearchIT,InReviewWorkflowIT,HarvestingServerIT,HarvestingClientsIT,MoveIT,MakeDataCountApiIT,FileTypeDetectionIT,EditDDIIT,ExternalToolsIT,AccessIT,DuplicateFilesIT,DownloadFilesIT,LinkIT,DeleteUsersIT,DeactivateUsersIT,AuxiliaryFilesIT,InvalidCharactersIT,LicensesIT,NotificationsIT,BagIT,MetadataBlocksIT,NetcdfIT,SignpostingIT,FitsIT,LogoutIT
DataversesIT,DatasetsIT,SwordIT,AdminIT,BuiltinUsersIT,UsersIT,UtilIT,ConfirmEmailIT,FileMetadataIT,FilesIT,SearchIT,InReviewWorkflowIT,HarvestingServerIT,HarvestingClientsIT,MoveIT,MakeDataCountApiIT,FileTypeDetectionIT,EditDDIIT,ExternalToolsIT,AccessIT,DuplicateFilesIT,DownloadFilesIT,LinkIT,DeleteUsersIT,DeactivateUsersIT,AuxiliaryFilesIT,InvalidCharactersIT,LicensesIT,NotificationsIT,BagIT,MetadataBlocksIT,NetcdfIT,SignpostingIT,FitsIT,LogoutIT,ProvIT

0 comments on commit 3305c4a

Please sign in to comment.