From bba6b6f2b333b991f3d56756d02875535d87aaff Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Thu, 4 Apr 2024 14:58:42 -0300 Subject: [PATCH 01/12] 9729: Handling repeated role creation error for datasets --- doc/release-notes/9729-release-notes.md | 1 + .../command/impl/AssignRoleCommand.java | 12 +++ .../harvard/iq/dataverse/api/DatasetsIT.java | 90 ++++++++----------- 3 files changed, 51 insertions(+), 52 deletions(-) create mode 100644 doc/release-notes/9729-release-notes.md diff --git a/doc/release-notes/9729-release-notes.md b/doc/release-notes/9729-release-notes.md new file mode 100644 index 00000000000..de679e9d81e --- /dev/null +++ b/doc/release-notes/9729-release-notes.md @@ -0,0 +1 @@ +Fixing unhandled exception when trying to create a role that already exists for a dataset object \ No newline at end of file diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java index e4edb973cd9..71b1212d260 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java @@ -68,11 +68,23 @@ public RoleAssignment execute(CommandContext ctxt) throws CommandException { throw new IllegalCommandException("User " + user.getUserIdentifier() + " is deactivated and cannot be given a role.", this); } } + if(isExistingRole(ctxt)){ + throw new IllegalCommandException("User already has this role for this object", this); + } // TODO make sure the role is defined on the dataverse. RoleAssignment roleAssignment = new RoleAssignment(role, grantee, defPoint, privateUrlToken, anonymizedAccess); + ctxt.roles().directRoleAssignments(grantee,defPoint); return ctxt.roles().save(roleAssignment); } + private boolean isExistingRole(CommandContext ctxt) { + return ctxt.roles() + .directRoleAssignments(grantee, defPoint) + .stream() + .map(RoleAssignment::getRole) + .anyMatch(it -> it.equals(role)); + } + @Override public Map> getRequiredPermissions() { // for data file check permission on owning dataset diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 734d48fd89f..01e61420eec 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -67,7 +67,7 @@ public class DatasetsIT { private static final Logger logger = Logger.getLogger(DatasetsIT.class.getCanonicalName()); - + @BeforeAll public static void setUpClass() { @@ -602,7 +602,6 @@ public void testCreatePublishDestroyDataset() { */ @Test public void testDatasetVersionsAPI() { - // Create user String apiToken = UtilIT.createRandomUserGetToken(); @@ -633,7 +632,7 @@ public void testDatasetVersionsAPI() { // Now check that the file is NOT shown, when we ask the versions api to // skip files: - boolean excludeFiles = true; + boolean excludeFiles = true; unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_DRAFT, apiToken, excludeFiles, false); unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() @@ -644,8 +643,8 @@ public void testDatasetVersionsAPI() { unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() .statusCode(UNAUTHORIZED.getStatusCode()); - - excludeFiles = false; + + excludeFiles = false; unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_DRAFT, apiToken, excludeFiles, false); unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() @@ -662,8 +661,8 @@ public void testDatasetVersionsAPI() { UtilIT.publishDataverseViaNativeApi(collectionAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); - //Set of tests on non-deaccesioned dataset - String specificVersion = "1.0"; + //Set of tests on non-deaccesioned dataset + String specificVersion = "1.0"; boolean includeDeaccessioned = false; Response datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); @@ -672,7 +671,7 @@ public void testDatasetVersionsAPI() { .body("data.versionState", equalTo("RELEASED")) .body("data.latestVersionPublishingState", equalTo("RELEASED")); - // Upload another file: + // Upload another file: String pathToFile2 = "src/main/webapp/resources/images/cc0.png"; Response uploadResponse2 = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile2, apiToken); uploadResponse2.prettyPrint(); @@ -691,7 +690,7 @@ public void testDatasetVersionsAPI() { .statusCode(OK.getStatusCode()) .body("data.versionState", equalTo("RELEASED")) .body("data.latestVersionPublishingState", equalTo("DRAFT")); - + // We should now have a published version, and a draft. // Call /versions api, *with the owner api token*, make sure both @@ -719,7 +718,7 @@ public void testDatasetVersionsAPI() { .body("data[0].files.size()", equalTo(2)); // And now call it with an un-privileged token, to make sure only one - // (the published) version is shown: + // (the published) version is shown: versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms); versionsResponse.prettyPrint(); versionsResponse.then().assertThat() @@ -736,10 +735,10 @@ public void testDatasetVersionsAPI() { .body("data[0].files", equalTo(null)); - - - + + + excludeFiles = true; //Latest published authorized token //Latest published requested, draft exists and user has access to draft @@ -790,7 +789,7 @@ public void testDatasetVersionsAPI() { .body("data.files", equalTo(null)); excludeFiles = false; - + //Latest published authorized token //Latest published requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); @@ -1004,7 +1003,7 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); - + } @@ -1716,26 +1715,6 @@ public void testAddRoles(){ giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); giveRandoPermission.prettyPrint(); assertEquals(200, giveRandoPermission.getStatusCode()); - - // Create another random user to become curator: - - Response createCuratorUser = UtilIT.createRandomUser(); - createCuratorUser.prettyPrint(); - String curatorUsername = UtilIT.getUsernameFromResponse(createCuratorUser); - String curatorUserApiToken = UtilIT.getApiTokenFromResponse(createCuratorUser); - - Response giveCuratorPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "curator", "@" + curatorUsername, apiToken); - giveCuratorPermission.prettyPrint(); - assertEquals(200, giveCuratorPermission.getStatusCode()); - - // Test if privilege escalation is possible: curator should not be able to assign admin rights - Response giveTooMuchPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "admin", "@" + curatorUsername, curatorUserApiToken); - giveTooMuchPermission.prettyPrint(); - assertEquals(401, giveTooMuchPermission.getStatusCode()); - - giveTooMuchPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "admin", "@" + randomUsername, curatorUserApiToken); - giveTooMuchPermission.prettyPrint(); - assertEquals(401, giveTooMuchPermission.getStatusCode()); String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); @@ -1758,7 +1737,7 @@ public void testAddRoles(){ deleteGrantedAccess.prettyPrint(); assertEquals(200, deleteGrantedAccess.getStatusCode()); - Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); + Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); @@ -1777,7 +1756,7 @@ public void testAddRoles(){ deleteUserResponse = UtilIT.deleteUser(curatorUsername); deleteUserResponse.prettyPrint(); assertEquals(200, deleteUserResponse.getStatusCode()); - + } @Test @@ -1853,6 +1832,14 @@ public void testListRoleAssignments() { assertEquals(UNAUTHORIZED.getStatusCode(), notPermittedToListRoleAssignmentOnDataverse.getStatusCode()); } + private static void validateAssignExistingRole(String datasetPersistentId, String randomUsername, String apiToken) { + final Response failedGrantPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); + failedGrantPermission.prettyPrint(); + failedGrantPermission.then().assertThat() + .body("message",containsString("User already has this role for this object")) + .statusCode(FORBIDDEN.getStatusCode()); + } + @Test public void testFileChecksum() { @@ -1961,7 +1948,7 @@ public void testDeleteDatasetWhileFileIngesting() { .statusCode(FORBIDDEN.getStatusCode()); } - + @Test public void testGetDatasetOwners() { @@ -1987,8 +1974,8 @@ public void testGetDatasetOwners() { Response getDatasetWithOwners = UtilIT.getDatasetWithOwners(persistentId, apiToken, true); getDatasetWithOwners.prettyPrint(); - getDatasetWithOwners.then().assertThat().body("data.isPartOf.identifier", equalTo(dataverseAlias)); - + getDatasetWithOwners.then().assertThat().body("data.isPartOf.identifier", equalTo(dataverseAlias)); + Response destroyDatasetResponse = UtilIT.destroyDataset(datasetId, apiToken); assertEquals(200, destroyDatasetResponse.getStatusCode()); @@ -1996,7 +1983,7 @@ public void testGetDatasetOwners() { assertEquals(200, deleteDataverseResponse.getStatusCode()); Response deleteUserResponse = UtilIT.deleteUser(username); - assertEquals(200, deleteUserResponse.getStatusCode()); + assertEquals(200, deleteUserResponse.getStatusCode()); } /** @@ -2772,7 +2759,7 @@ public void testUpdateDatasetVersionWithFiles() throws InterruptedException { System.out.println("Author username/password: " + authorUsername); } - + @Test public void testLinkingDatasets() { @@ -3124,11 +3111,11 @@ public void testSemanticMetadataAPIs() { response = UtilIT.updateDatasetJsonLDMetadata(datasetId, apiToken, badTerms, false); response.then().assertThat().statusCode(BAD_REQUEST.getStatusCode()); - - //We publish the dataset and dataverse - UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); + + //We publish the dataset and dataverse + UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); - + //We check the version is published response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiToken); response.prettyPrint(); @@ -3143,14 +3130,14 @@ public void testSemanticMetadataAPIs() { uploadResponse.prettyPrint(); uploadResponse.then().assertThat().statusCode(OK.getStatusCode()); int fileID = uploadResponse.jsonPath().getInt("data.files[0].dataFile.id"); - + //We check the authenticated user gets DRAFT response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiToken); - response.prettyPrint(); + response.prettyPrint(); jsonLDString = getData(response.getBody().asString()); jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString); assertEquals("DRAFT", jsonLDObject.getString("http://schema.org/version")); - + // Create user with no permission and check they get published version String apiTokenNoPerms = UtilIT.createRandomUserGetToken(); response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiTokenNoPerms); @@ -3158,7 +3145,7 @@ public void testSemanticMetadataAPIs() { jsonLDString = getData(response.getBody().asString()); jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString); assertNotEquals("DRAFT", jsonLDObject.getString("http://schema.org/version")); - + // Delete the file Response deleteFileResponse = UtilIT.deleteFileInDataset(fileID, apiToken); deleteFileResponse.prettyPrint(); @@ -3763,8 +3750,7 @@ public void testArchivalStatusAPI() throws IOException { //Verify the status is empty Response nullStatus = UtilIT.getDatasetVersionArchivalStatus(datasetId, "1.0", apiToken); - nullStatus.prettyPrint(); - nullStatus.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); + nullStatus.then().assertThat().statusCode(NO_CONTENT.getStatusCode()); //Set it Response setStatus = UtilIT.setDatasetVersionArchivalStatus(datasetId, "1.0", apiToken, "pending", From e25ace5c7442808646f0466a2d14f070894d3ec4 Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Thu, 4 Apr 2024 15:21:08 -0300 Subject: [PATCH 02/12] 9729: Fixing unit test --- .../command/impl/CreatePrivateUrlCommandTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java index 33f9acd0e1a..9a125e357ff 100644 --- a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java @@ -1,10 +1,8 @@ package edu.harvard.iq.dataverse.engine.command.impl; -import edu.harvard.iq.dataverse.Dataset; -import edu.harvard.iq.dataverse.DatasetVersion; -import edu.harvard.iq.dataverse.DataverseRoleServiceBean; -import edu.harvard.iq.dataverse.RoleAssignment; +import edu.harvard.iq.dataverse.*; import edu.harvard.iq.dataverse.authorization.DataverseRole; +import edu.harvard.iq.dataverse.authorization.RoleAssignee; import edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser; import edu.harvard.iq.dataverse.engine.TestCommandContext; import edu.harvard.iq.dataverse.engine.TestDataverseEngine; @@ -73,6 +71,10 @@ public RoleAssignment save(RoleAssignment assignment) { // no-op return assignment; } + @Override + public List directRoleAssignments(RoleAssignee roas, DvObject dvo) { + return List.of(); + } }; } From 258d553e5b25cbabc1b7b2f70534ecbd6abb31d8 Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Thu, 4 Apr 2024 15:32:06 -0300 Subject: [PATCH 03/12] 9729: Optimizing Imports --- .../command/impl/CreatePrivateUrlCommandTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java index 9a125e357ff..454bf2e40f1 100644 --- a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java @@ -1,6 +1,11 @@ package edu.harvard.iq.dataverse.engine.command.impl; -import edu.harvard.iq.dataverse.*; + +import edu.harvard.iq.dataverse.Dataset; +import edu.harvard.iq.dataverse.DatasetVersion; +import edu.harvard.iq.dataverse.DataverseRoleServiceBean; +import edu.harvard.iq.dataverse.DvObject; +import edu.harvard.iq.dataverse.RoleAssignment; import edu.harvard.iq.dataverse.authorization.DataverseRole; import edu.harvard.iq.dataverse.authorization.RoleAssignee; import edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser; @@ -16,8 +21,8 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class CreatePrivateUrlCommandTest { From 6a9027310836dd6c3c461a9e0273d0be70c18c4f Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Thu, 4 Apr 2024 15:33:06 -0300 Subject: [PATCH 04/12] 9729: Deleting white space --- .../engine/command/impl/CreatePrivateUrlCommandTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java index 454bf2e40f1..b67fc8cb4c3 100644 --- a/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java +++ b/src/test/java/edu/harvard/iq/dataverse/engine/command/impl/CreatePrivateUrlCommandTest.java @@ -1,6 +1,5 @@ package edu.harvard.iq.dataverse.engine.command.impl; - import edu.harvard.iq.dataverse.Dataset; import edu.harvard.iq.dataverse.DatasetVersion; import edu.harvard.iq.dataverse.DataverseRoleServiceBean; From 2b6040d093889ff14cf8c93be08930960466d8db Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Thu, 4 Apr 2024 15:40:14 -0300 Subject: [PATCH 05/12] 9729: Deleting redundant line --- .../iq/dataverse/engine/command/impl/AssignRoleCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java index 71b1212d260..dee567a83a2 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java @@ -73,7 +73,6 @@ public RoleAssignment execute(CommandContext ctxt) throws CommandException { } // TODO make sure the role is defined on the dataverse. RoleAssignment roleAssignment = new RoleAssignment(role, grantee, defPoint, privateUrlToken, anonymizedAccess); - ctxt.roles().directRoleAssignments(grantee,defPoint); return ctxt.roles().save(roleAssignment); } From fab40cc20387e91460e694a6a54bf42f9972981e Mon Sep 17 00:00:00 2001 From: Jose Lucas Cordeiro Date: Tue, 9 Apr 2024 17:01:53 -0300 Subject: [PATCH 06/12] Update doc/release-notes/9729-release-notes.md Co-authored-by: Philip Durbin --- doc/release-notes/9729-release-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/release-notes/9729-release-notes.md b/doc/release-notes/9729-release-notes.md index de679e9d81e..9dc27995405 100644 --- a/doc/release-notes/9729-release-notes.md +++ b/doc/release-notes/9729-release-notes.md @@ -1 +1 @@ -Fixing unhandled exception when trying to create a role that already exists for a dataset object \ No newline at end of file +An error is now correctly reported when an attempt is made to assign an identical role to the same collection, dataset, or file. #9729 #10465 \ No newline at end of file From a6f939b489aef6461a76b57ec4ec01bbb7de0714 Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Tue, 9 Apr 2024 20:02:23 -0300 Subject: [PATCH 07/12] 9375: Rolling back wrong code removal and reformatting --- .../harvard/iq/dataverse/api/DatasetsIT.java | 553 +++++++++--------- 1 file changed, 285 insertions(+), 268 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 01e61420eec..61ec8cfde14 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -70,8 +70,8 @@ public class DatasetsIT { @BeforeAll public static void setUpClass() { - - + + RestAssured.baseURI = UtilIT.getRestAssuredBaseUri(); Response removeIdentifierGenerationStyle = UtilIT.deleteSetting(SettingsServiceBean.Key.IdentifierGenerationStyle); @@ -128,20 +128,20 @@ public static void afterClass() { .statusCode(200); */ } - + @Test - public void testCollectionSchema(){ - + public void testCollectionSchema() { + Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); - - Response getCollectionSchemaResponse = UtilIT.getCollectionSchema(dataverseAlias, apiToken); + + Response getCollectionSchemaResponse = UtilIT.getCollectionSchema(dataverseAlias, apiToken); getCollectionSchemaResponse.prettyPrint(); getCollectionSchemaResponse.then().assertThat() .statusCode(200); @@ -153,33 +153,33 @@ public void testCollectionSchema(){ } assertEquals(JsonUtil.prettyPrint(expectedSchema), JsonUtil.prettyPrint(getCollectionSchemaResponse.body().asString())); - + String expectedJson = UtilIT.getDatasetJson("scripts/search/tests/data/dataset-finch1.json"); - + Response validateDatasetJsonResponse = UtilIT.validateDatasetJson(dataverseAlias, expectedJson, apiToken); validateDatasetJsonResponse.prettyPrint(); validateDatasetJsonResponse.then().assertThat() .statusCode(200); - - - String pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; - + + + String pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; + String jsonIn = UtilIT.getDatasetJson(pathToJsonFile); - + Response validateBadDatasetJsonResponse = UtilIT.validateDatasetJson(dataverseAlias, jsonIn, apiToken); validateBadDatasetJsonResponse.prettyPrint(); validateBadDatasetJsonResponse.then().assertThat() .statusCode(200); - + validateBadDatasetJsonResponse.then().assertThat() .statusCode(OK.getStatusCode()) .body(containsString("failed validation")); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); - + } @Test @@ -189,7 +189,7 @@ public void testCreateDataset() { createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); @@ -201,28 +201,28 @@ public void testCreateDataset() { Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken); datasetAsJson.then().assertThat() .statusCode(OK.getStatusCode()); - + String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); assertEquals(10, identifier.length()); Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + // Now, let's allow anyone with a Dataverse account (any "random user") // to create datasets in this dataverse: - + Response grantRole = UtilIT.grantRoleOnDataverse(dataverseAlias, DataverseRole.DS_CONTRIBUTOR, AuthenticatedUsers.get().getIdentifier(), apiToken); grantRole.prettyPrint(); assertEquals(OK.getStatusCode(), grantRole.getStatusCode()); - + // Create another random user: - + Response createRandomUser = UtilIT.createRandomUser(); createRandomUser.prettyPrint(); String randomUsername = UtilIT.getUsernameFromResponse(createRandomUser); String randomUserApiToken = UtilIT.getApiTokenFromResponse(createRandomUser); - + // This random user should be able to create a dataset in the dataverse // above, because we've set it up so, right? - Not exactly: the dataverse // hasn't been published yet! So if this random user tries to create @@ -233,7 +233,7 @@ public void testCreateDataset() { assertEquals(UNAUTHORIZED.getStatusCode(), createDatasetResponse.getStatusCode()); */ // Now, let's publish this dataverse... - + Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); assertEquals(OK.getStatusCode(), publishDataverse.getStatusCode()); @@ -242,12 +242,13 @@ public void testCreateDataset() { try { Thread.sleep(1000l); - } catch (InterruptedException iex) {} + } catch (InterruptedException iex) { + } // ... And now that it's published, try to create a dataset again, // as the "random", not specifically authorized user: // (this time around, it should work!) - + createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, randomUserApiToken); createDatasetResponse.prettyPrint(); datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); @@ -257,11 +258,11 @@ public void testCreateDataset() { .statusCode(OK.getStatusCode()); // OK, let's delete this dataset as well, and then delete the dataverse... - + deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); @@ -271,7 +272,7 @@ public void testCreateDataset() { assertEquals(200, deleteUserResponse.getStatusCode()); } - + @Test public void testAddUpdateDatasetViaNativeAPI() { @@ -279,7 +280,7 @@ public void testAddUpdateDatasetViaNativeAPI() { createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); @@ -291,43 +292,41 @@ public void testAddUpdateDatasetViaNativeAPI() { Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken); datasetAsJson.then().assertThat() .statusCode(OK.getStatusCode()); - + String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); - + //Test Add Data - - + + Response getDatasetJsonBeforePublishing = UtilIT.nativeGet(datasetId, apiToken); getDatasetJsonBeforePublishing.prettyPrint(); String protocol = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.protocol"); String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority"); - + String datasetPersistentId = protocol + ":" + authority + "/" + identifier; String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-add-metadata.json"; Response addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - - + RestAssured.registerParser("text/plain", Parser.JSON); Response exportDatasetAsJson = UtilIT.exportDataset(datasetPersistentId, "dataverse_json", apiToken); exportDatasetAsJson.prettyPrint(); - + pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-add-subject-metadata.json"; addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()).body(containsString("Mathematical Sciences")); - + String pathToJsonFileSingle = "doc/sphinx-guides/source/_static/api/dataset-simple-update-metadata.json"; Response addSubjectSingleViaNative = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileSingle, apiToken); String responseString = addSubjectSingleViaNative.prettyPrint(); addSubjectSingleViaNative.then().assertThat() .statusCode(OK.getStatusCode()).body(containsString("Mathematical Sciences")).body(containsString("Social Sciences")); - //Trying to blank out required field should fail... @@ -338,12 +337,12 @@ public void testAddUpdateDatasetViaNativeAPI() { Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); - + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); //post publish update - String pathToJsonFilePostPub= "doc/sphinx-guides/source/_static/api/dataset-add-metadata-after-pub.json"; - Response addDataToPublishedVersion = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFilePostPub, apiToken); + String pathToJsonFilePostPub = "doc/sphinx-guides/source/_static/api/dataset-add-metadata-after-pub.json"; + Response addDataToPublishedVersion = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFilePostPub, apiToken); addDataToPublishedVersion.prettyPrint(); addDataToPublishedVersion.then().assertThat().statusCode(OK.getStatusCode()); @@ -353,34 +352,34 @@ public void testAddUpdateDatasetViaNativeAPI() { String pathToJsonFileBadDataSubtitle = "doc/sphinx-guides/source/_static/api/dataset-edit-metadata-subtitle.json"; Response addDataToBadData = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileBadDataSubtitle, apiToken); addDataToBadData.prettyPrint(); - + addDataToBadData.then().assertThat() .body("message", equalToCI("Error parsing dataset update: Invalid value submitted for Subtitle. It should be a single value.")) .statusCode(400); - - addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); + + addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - - String pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-subject-metadata.json"; + + String pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-subject-metadata.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-author-metadata.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-author-no-match.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat().body("message", equalTo("Delete metadata failed: Author: Spruce, Sabrina not found.")) .statusCode(400); - + publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); //6078 @@ -388,11 +387,11 @@ public void testAddUpdateDatasetViaNativeAPI() { Response editPublishedVersion = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileEditPostPub, apiToken); editPublishedVersion.prettyPrint(); editPublishedVersion.then().assertThat().statusCode(OK.getStatusCode()); - + publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); //"Delete metadata failed: " + updateField.getDatasetFieldType().getDisplayName() + ": " + displayValue + " not found." } - + @Test public void testAddEmptyDatasetViaNativeAPI() { @@ -400,27 +399,27 @@ public void testAddEmptyDatasetViaNativeAPI() { createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); - String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); - + String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); + String pathToJsonFile = "scripts/search/tests/data/emptyDataset.json"; Response createDatasetResponse = UtilIT.createDatasetViaNativeApi(dataverseAlias, pathToJsonFile, apiToken); createDatasetResponse.prettyPrint(); createDatasetResponse.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()) - .body("message", startsWith("Validation Failed: ")); - - pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; + .body("message", startsWith("Validation Failed: ")); + + pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; createDatasetResponse = UtilIT.createDatasetViaNativeApi(dataverseAlias, pathToJsonFile, apiToken); createDatasetResponse.prettyPrint(); - + createDatasetResponse.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()) .body("message", startsWith("Validation Failed: ")); - + } /** @@ -436,10 +435,10 @@ public void testCreatePublishDestroyDataset() { String apiToken = UtilIT.getApiTokenFromResponse(createUser); Response makeSuperUser = UtilIT.makeSuperUser(username); assertEquals(200, makeSuperUser.getStatusCode()); - + Response createNoAccessUser = UtilIT.createRandomUser(); createNoAccessUser.prettyPrint(); - String apiTokenNoAccess= UtilIT.getApiTokenFromResponse(createNoAccessUser); + String apiTokenNoAccess = UtilIT.getApiTokenFromResponse(createNoAccessUser); Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); @@ -455,11 +454,11 @@ public void testCreatePublishDestroyDataset() { String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority"); String identifier = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.identifier"); String datasetPersistentId = protocol + ":" + authority + "/" + identifier; - + Response datasetAsJsonNoAccess = UtilIT.nativeGet(datasetId, apiTokenNoAccess); datasetAsJsonNoAccess.then().assertThat() - .statusCode(UNAUTHORIZED.getStatusCode()); - + .statusCode(UNAUTHORIZED.getStatusCode()); + Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); assertEquals(200, publishDataverse.getStatusCode()); Response attemptToPublishZeroDotOne = UtilIT.publishDatasetViaNativeApiDeprecated(datasetPersistentId, "minor", apiToken); @@ -468,7 +467,7 @@ public void testCreatePublishDestroyDataset() { attemptToPublishZeroDotOne.then().assertThat() .body("message", equalTo("Cannot publish as minor version. Re-try as major release.")) .statusCode(403); - + logger.info("Attempting to publish a major version"); // Return random sleep 9/13/2019 // Without it we've seen some DB deadlocks @@ -476,7 +475,8 @@ public void testCreatePublishDestroyDataset() { try { Thread.sleep(3000l); - } catch (InterruptedException iex) {} + } catch (InterruptedException iex) { + } Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -489,10 +489,10 @@ public void testCreatePublishDestroyDataset() { // FIXME: make this less brittle by removing "2" and "0". See also test below. .body("data.latestVersion.metadataBlocks.citation.fields[2].value[0].datasetContactEmail.value", equalTo("finch@mailinator.com")) .statusCode(OK.getStatusCode()); - + Response datasetAsJsonNoAccessPostPublish = UtilIT.nativeGet(datasetId, apiTokenNoAccess); datasetAsJsonNoAccessPostPublish.then().assertThat() - .statusCode(OK.getStatusCode()); + .statusCode(OK.getStatusCode()); assertTrue(datasetAsJsonNoAccessPostPublish.body().asString().contains(identifier)); List datasetContactsFromNativeGet = with(getDatasetJsonAfterPublishing.body().asString()).param("datasetContact", "datasetContact") @@ -596,10 +596,10 @@ public void testCreatePublishDestroyDataset() { /** * The apis (/api/datasets/{id}/versions and /api/datasets/{id}/versions/{vid} - * are already called from other RestAssured tests, in this class and also in FilesIT. - * But this test is dedicated to this api specifically, and focuses on the - * functionality added to it in 6.1. - */ + * are already called from other RestAssured tests, in this class and also in FilesIT. + * But this test is dedicated to this api specifically, and focuses on the + * functionality added to it in 6.1. + */ @Test public void testDatasetVersionsAPI() { // Create user @@ -623,13 +623,13 @@ 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()); - + // Check that the file we just uploaded is shown by the versions api: Response unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, ":draft", apiToken); unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() .statusCode(OK.getStatusCode()); - + // Now check that the file is NOT shown, when we ask the versions api to // skip files: boolean excludeFiles = true; @@ -692,7 +692,7 @@ public void testDatasetVersionsAPI() { .body("data.latestVersionPublishingState", equalTo("DRAFT")); // We should now have a published version, and a draft. - + // Call /versions api, *with the owner api token*, make sure both // versions are listed; also check that the correct numbers of files // are shown in each version (2 in the draft, 1 in the published). @@ -716,7 +716,7 @@ public void testDatasetVersionsAPI() { .body("data.size()", equalTo(1)) .body("data.versionState[0]", equalTo("DRAFT")) .body("data[0].files.size()", equalTo(2)); - + // And now call it with an un-privileged token, to make sure only one // (the published) version is shown: versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms); @@ -725,7 +725,7 @@ public void testDatasetVersionsAPI() { .statusCode(OK.getStatusCode()) .body("data.versionState[0]", not("DRAFT")) .body("data.size()", equalTo(1)); - + // And now call the "short", no-files version of the same api excludeFiles = true; versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms, excludeFiles); @@ -735,58 +735,54 @@ public void testDatasetVersionsAPI() { .body("data[0].files", equalTo(null)); - - - - excludeFiles = true; //Latest published authorized token //Latest published requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Latest published unauthorized token //Latest published requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Latest authorized token //Latest requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files", equalTo(null)); //Latest unauthorized token //Latest requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Specific version authorized token //Specific version requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Specific version unauthorized token //Specific version requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); excludeFiles = false; @@ -795,48 +791,48 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Latest published unauthorized token //Latest published requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Latest authorized token, user is authenticated should get the Draft version //Latest requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files.size()", equalTo(2)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files.size()", equalTo(2)); //Latest unauthorized token, user has no permissions should get the latest Published version //Latest requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Specific version authorized token //Specific version requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Specific version unauthorized token //Specific version requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //We deaccession the dataset Response deaccessionDatasetResponse = UtilIT.deaccessionDataset(datasetId, DS_VERSION_LATEST_PUBLISHED, "Test deaccession reason.", null, apiToken); @@ -851,8 +847,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files.size()", equalTo(1)); //Latest published requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -863,8 +859,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files.size()", equalTo(2)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files.size()", equalTo(2)); //Latest unauthorized token requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -875,8 +871,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files.size()", equalTo(1)); //Specific version unauthorized token requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets. datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -890,48 +886,48 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Latest published exclude files, should get the DEACCESSIONED version //Latest published requested, that version was deaccessioned but a draft exist but the user doesn't have access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Latest authorized token should get the DRAFT version with no files //Latest requested there is a draft and the user has access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files", equalTo(null)); //Latest unauthorized token excluding files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets //Latest requested and latest version is deaccessioned and the user doesn't have access to the draft. datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Specific version authorized token //Specific version requested (deaccesioned), the latest version is on draft amd the user has access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Specific version unauthorized token requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets. //Specific version requested (deaccesioned), the latest version is on draft but the user doesn't have access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Set of test when we have a deaccessioned dataset but we don't include deaccessioned includeDeaccessioned = false; @@ -952,8 +948,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files.size()", equalTo(2)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files.size()", equalTo(2)); //Latest unauthorized token one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -986,8 +982,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files", equalTo(null)); //Latest unauthorized token one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -1006,7 +1002,7 @@ public void testDatasetVersionsAPI() { } - + /** * This test requires the root dataverse to be published to pass. */ @@ -1052,7 +1048,8 @@ public void testExport() { try { Thread.sleep(3000l); - } catch (InterruptedException iex) {} + } catch (InterruptedException iex) { + } Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -1190,7 +1187,8 @@ public void testExcludeEmail() { try { Thread.sleep(3000l); - } catch (InterruptedException iex) {} + } catch (InterruptedException iex) { + } Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -1305,9 +1303,11 @@ public void testStoredProcGeneratedAsIdentifierGenerationStyle() { try { Thread.sleep(3000l); - } catch (Exception ex) {logger.warning("failed to execute sleep 3 sec.");} + } catch (Exception ex) { + logger.warning("failed to execute sleep 3 sec."); + } + - Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); @@ -1429,14 +1429,14 @@ public void testPrivateUrl() { * asadmin create-jvm-options * "-Ddataverse.siteUrl=http\://localhost\:8080" */ - - /* - * Attempt to follow the private link url; as a user not otherwise + + /* + * Attempt to follow the private link url; as a user not otherwise * authorized to view the draft - and make sure they get the dataset page: - * + * * MAKE SURE TO READ the note below, about jsessions and cookies! - */ - + */ + Response getDatasetAsUserWhoClicksPrivateUrl = given() .header(API_TOKEN_HTTP_HEADER, apiToken) .get(urlWithToken); @@ -1507,7 +1507,7 @@ public void testPrivateUrl() { assertEquals("Darwin's Finches - " + dataverseAlias, title); */ - + Response junkPrivateUrlToken = given() .header(API_TOKEN_HTTP_HEADER, apiToken) .get("/privateurl.xhtml?token=" + "junk"); @@ -1666,15 +1666,15 @@ public void testPrivateUrl() { * @todo Should the Search API work with the Private URL token? */ } - + @Test - public void testAddRoles(){ - + public void testAddRoles() { + Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); @@ -1686,61 +1686,81 @@ public void testAddRoles(){ Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken); datasetAsJson.then().assertThat() .statusCode(OK.getStatusCode()); - + String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); assertEquals(10, identifier.length()); - + String protocol1 = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.protocol"); String authority1 = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.authority"); String identifier1 = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); String datasetPersistentId = protocol1 + ":" + authority1 + "/" + identifier1; - - + // Create another random user: - + Response createRandomUser = UtilIT.createRandomUser(); createRandomUser.prettyPrint(); String randomUsername = UtilIT.getUsernameFromResponse(createRandomUser); String randomUserApiToken = UtilIT.getApiTokenFromResponse(createRandomUser); - + //Give that random user permission //(String definitionPoint, String role, String roleAssignee, String apiToken) //Can't give yourself permission Response giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, randomUserApiToken); - giveRandoPermission.prettyPrint(); + giveRandoPermission.prettyPrint(); assertEquals(401, giveRandoPermission.getStatusCode()); - + giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); - giveRandoPermission.prettyPrint(); + giveRandoPermission.prettyPrint(); assertEquals(200, giveRandoPermission.getStatusCode()); - - String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); + + // Create another random user to become curator: + + Response createCuratorUser = UtilIT.createRandomUser(); + createCuratorUser.prettyPrint(); + String curatorUsername = UtilIT.getUsernameFromResponse(createCuratorUser); + String curatorUserApiToken = UtilIT.getApiTokenFromResponse(createCuratorUser); + + Response giveCuratorPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "curator", "@" + curatorUsername, apiToken); + giveCuratorPermission.prettyPrint(); + assertEquals(200, giveCuratorPermission.getStatusCode()); + + // Test if privilege escalation is possible: curator should not be able to assign admin rights + Response giveTooMuchPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "admin", "@" + curatorUsername, curatorUserApiToken); + giveTooMuchPermission.prettyPrint(); + assertEquals(401, giveTooMuchPermission.getStatusCode()); + + giveTooMuchPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "admin", "@" + randomUsername, curatorUserApiToken); + giveTooMuchPermission.prettyPrint(); + assertEquals(401, giveTooMuchPermission.getStatusCode()); + + + String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "designatedHitter", "@" + randomUsername, apiToken); - giveRandoPermission.prettyPrint(); - giveRandoPermission.then().assertThat() + giveRandoPermission.prettyPrint(); + giveRandoPermission.then().assertThat() .contentType(ContentType.JSON) .body("message", containsString("Cannot find role named 'designatedHitter' in dataverse ")) .statusCode(400); assertEquals(400, giveRandoPermission.getStatusCode()); - + //Try to delete Role with Id saved above //Fails for lack of perms Response deleteGrantedAccess = UtilIT.revokeRoleOnDataset(datasetPersistentId, new Long(idToDelete), randomUserApiToken); deleteGrantedAccess.prettyPrint(); assertEquals(401, deleteGrantedAccess.getStatusCode()); - + //Should be able to delete with proper apiToken deleteGrantedAccess = UtilIT.revokeRoleOnDataset(datasetPersistentId, new Long(idToDelete), apiToken); deleteGrantedAccess.prettyPrint(); assertEquals(200, deleteGrantedAccess.getStatusCode()); - - Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); + + Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); @@ -1836,7 +1856,7 @@ private static void validateAssignExistingRole(String datasetPersistentId, Strin final Response failedGrantPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); failedGrantPermission.prettyPrint(); failedGrantPermission.then().assertThat() - .body("message",containsString("User already has this role for this object")) + .body("message", containsString("User already has this role for this object")) .statusCode(FORBIDDEN.getStatusCode()); } @@ -1940,7 +1960,7 @@ public void testDeleteDatasetWhileFileIngesting() { Response uploadIngestableFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFileThatGoesThroughIngest, apiToken); uploadIngestableFile.then().assertThat() .statusCode(OK.getStatusCode()); - + Response deleteDataset = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDataset.prettyPrint(); deleteDataset.then().assertThat() @@ -2095,7 +2115,7 @@ public void testCreateDatasetWithDcmDependency() { if (stopEarlyBecauseYouDoNotHaveDcmInstalled) { return; } - + boolean stopEarlyToVerifyTheScriptWasCreated = false; if (stopEarlyToVerifyTheScriptWasCreated) { logger.info("On the DCM, does /deposit/gen/upload-" + datasetId + ".bash exist? It should! Creating the dataset should be enough to create it."); @@ -2152,7 +2172,7 @@ public void testDcmChecksumValidationMessages() throws IOException, InterruptedE the CreateDatasetCommand is not getting the rsync script so the dataset is not being created so the whole test is failing */ - + boolean disabled = true; if (disabled) { @@ -2370,14 +2390,14 @@ public void testDcmChecksumValidationMessages() throws IOException, InterruptedE } logger.info("username/password: " + username); } - + @Test public void testCreateDeleteDatasetLink() { Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response superuserResponse = UtilIT.makeSuperUser(username); Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); @@ -2387,7 +2407,7 @@ public void testCreateDeleteDatasetLink() { Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); createDatasetResponse.prettyPrint(); Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); - + // This should fail, because we are attempting to link the dataset // to its own dataverse: Response publishTargetDataverse = UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken); @@ -2399,13 +2419,13 @@ public void testCreateDeleteDatasetLink() { publishDatasetForLinking.prettyPrint(); publishDatasetForLinking.then().assertThat() .statusCode(OK.getStatusCode()); - + Response createLinkingDatasetResponse = UtilIT.createDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); createLinkingDatasetResponse.prettyPrint(); createLinkingDatasetResponse.then().assertThat() .body("message", equalTo("Can't link a dataset to its dataverse")) .statusCode(FORBIDDEN.getStatusCode()); - + // OK, let's create a different random dataverse: createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); @@ -2414,23 +2434,23 @@ public void testCreateDeleteDatasetLink() { publishDatasetForLinking.prettyPrint(); publishTargetDataverse.then().assertThat() .statusCode(OK.getStatusCode()); - + // And link the dataset to this new dataverse: createLinkingDatasetResponse = UtilIT.createDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); createLinkingDatasetResponse.prettyPrint(); createLinkingDatasetResponse.then().assertThat() - .body("data.message", equalTo("Dataset " + datasetId +" linked successfully to " + dataverseAlias)) + .body("data.message", equalTo("Dataset " + datasetId + " linked successfully to " + dataverseAlias)) .statusCode(200); - + // And now test deleting it: Response deleteLinkingDatasetResponse = UtilIT.deleteDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); deleteLinkingDatasetResponse.prettyPrint(); - + deleteLinkingDatasetResponse.then().assertThat() .body("data.message", equalTo("Link from Dataset " + datasetId + " to linked Dataverse " + dataverseAlias + " deleted")) .statusCode(200); } - + @Test @Disabled public void testApiErrors() { @@ -2472,7 +2492,7 @@ public void testApiErrors() { Response deleteFile = UtilIT.deleteFile(907, apiToken); deleteFile.prettyPrint(); assertEquals(BAD_REQUEST.getStatusCode(), deleteFile.getStatusCode()); - + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPid, "major", apiToken); publishDataset.prettyPrint(); assertEquals(409, publishDataset.getStatusCode()); @@ -2480,14 +2500,14 @@ public void testApiErrors() { } - + @Test public void testDatasetLocksApi() { Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response superuserResponse = UtilIT.makeSuperUser(username); Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); @@ -2498,7 +2518,7 @@ public void testDatasetLocksApi() { createDatasetResponse.prettyPrint(); Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); String persistentIdentifier = UtilIT.getDatasetPersistentIdFromResponse(createDatasetResponse); - + // This should return an empty list, as the dataset should have no locks just yet: Response checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), null, apiToken); checkDatasetLocks.prettyPrint(); @@ -2506,14 +2526,14 @@ public void testDatasetLocksApi() { checkDatasetLocks.then().assertThat() .body("data", equalTo(emptyArray)) .statusCode(200); - + // Lock the dataset with an ingest lock: Response lockDatasetResponse = UtilIT.lockDataset(datasetId.longValue(), "Ingest", apiToken); lockDatasetResponse.prettyPrint(); lockDatasetResponse.then().assertThat() .body("data.message", equalTo("dataset locked with lock type Ingest")) .statusCode(200); - + // Check again: // This should return an empty list, as the dataset should have no locks just yet: checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken); @@ -2521,7 +2541,7 @@ public void testDatasetLocksApi() { checkDatasetLocks.then().assertThat() .body("data[0].lockType", equalTo("Ingest")) .statusCode(200); - + // Try to lock the dataset with the same type lock, AGAIN // (this should fail, of course!) lockDatasetResponse = UtilIT.lockDataset(datasetId.longValue(), "Ingest", apiToken); @@ -2529,29 +2549,29 @@ public void testDatasetLocksApi() { lockDatasetResponse.then().assertThat() .body("message", equalTo("dataset already locked with lock type Ingest")) .statusCode(FORBIDDEN.getStatusCode()); - + // Let's also test the new (as of 5.10) API that lists the locks // present across all datasets. - + // First, we'll try listing ALL locks currently in the system, and make sure that the ingest lock // for this dataset is on the list: checkDatasetLocks = UtilIT.listAllLocks(apiToken); checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .statusCode(200); - + boolean lockListedCorrectly = false; List> listedLockEntries = checkDatasetLocks.body().jsonPath().getList("data"); for (int i = 0; i < listedLockEntries.size(); i++) { if ("Ingest".equals(listedLockEntries.get(i).get("lockType")) && username.equals(listedLockEntries.get(i).get("user")) && persistentIdentifier.equals(listedLockEntries.get(i).get("dataset"))) { - lockListedCorrectly = true; + lockListedCorrectly = true; break; - } + } } assertTrue(lockListedCorrectly, "Lock missing from the output of /api/datasets/locks"); - + // Try the same, but with an api token of a random, non-super user // (this should get rejected): createUser = UtilIT.createRandomUser(); @@ -2561,7 +2581,7 @@ public void testDatasetLocksApi() { checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()); - + // Try to narrow the listing down to the lock of type=Ingest specifically; // verify that the lock in question is still being listed: checkDatasetLocks = UtilIT.listLocksByType("Ingest", apiToken); @@ -2576,20 +2596,20 @@ public void testDatasetLocksApi() { if ("Ingest".equals(listedLockEntries.get(i).get("lockType")) && username.equals(listedLockEntries.get(i).get("user")) && persistentIdentifier.equals(listedLockEntries.get(i).get("dataset"))) { - lockListedCorrectly = true; + lockListedCorrectly = true; break; - } + } } assertTrue(lockListedCorrectly, "Lock missing from the output of /api/datasets/locks?type=Ingest"); - + // Try to list locks of an invalid type: checkDatasetLocks = UtilIT.listLocksByType("BadLockType", apiToken); checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .body("message", startsWith("Invalid lock type value: BadLockType")) .statusCode(BAD_REQUEST.getStatusCode()); - + // List the locks owned by the current user; verify that the lock above // is still listed: checkDatasetLocks = UtilIT.listLocksByUser(username, apiToken); @@ -2600,7 +2620,7 @@ public void testDatasetLocksApi() { .body("data[0].user", equalTo(username)) .body("data[0].dataset", equalTo(persistentIdentifier)) .statusCode(200); - + // Further narrow down the listing to both the type AND user: checkDatasetLocks = UtilIT.listLocksByTypeAndUser("Ingest", username, apiToken); checkDatasetLocks.prettyPrint(); @@ -2610,8 +2630,8 @@ public void testDatasetLocksApi() { .body("data[0].lockType", equalTo("Ingest")) .body("data[0].user", equalTo(username)) .body("data[0].dataset", equalTo(persistentIdentifier)); - - + + // Finally, try asking for the locks owned by this user AND of type "InReview". // This should produce an empty list: checkDatasetLocks = UtilIT.listLocksByTypeAndUser("InReview", username, apiToken); @@ -2619,15 +2639,15 @@ public void testDatasetLocksApi() { checkDatasetLocks.then().assertThat() .statusCode(200) .body("data", equalTo(emptyArray)); - + // And now test deleting the lock: Response unlockDatasetResponse = UtilIT.unlockDataset(datasetId.longValue(), "Ingest", apiToken); unlockDatasetResponse.prettyPrint(); - + unlockDatasetResponse.then().assertThat() .body("data.message", equalTo("lock type Ingest removed")) .statusCode(200); - + // ... and check for the lock on the dataset again, this time by specific lock type: // (should return an empty list, now that we have unlocked it) checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken); @@ -2636,7 +2656,7 @@ public void testDatasetLocksApi() { .body("data", equalTo(emptyArray)) .statusCode(200); } - + /** * This test requires the root dataverse to be published to pass. */ @@ -2673,8 +2693,9 @@ public void testUpdatePIDMetadataAPI() { //without it we've seen DB deadlocks try { Thread.sleep(3000l); - } catch (InterruptedException iex){} - + } catch (InterruptedException iex) { + } + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -2698,7 +2719,7 @@ public void testUpdatePIDMetadataAPI() { logger.info("datasetPersistentId: " + datasetPersistentId); } - + @Test public void testUpdateDatasetVersionWithFiles() throws InterruptedException { Response createCurator = UtilIT.createRandomUser(); @@ -2722,7 +2743,7 @@ public void testUpdateDatasetVersionWithFiles() throws InterruptedException { String authorUsername = UtilIT.getUsernameFromResponse(createAuthor); String authorApiToken = UtilIT.getApiTokenFromResponse(createAuthor); - + Response grantAuthorAddDataset = UtilIT.grantRoleOnDataverse(dataverseAlias, DataverseRole.DS_CONTRIBUTOR.toString(), "@" + authorUsername, curatorApiToken); grantAuthorAddDataset.prettyPrint(); grantAuthorAddDataset.then().assertThat() @@ -2747,7 +2768,7 @@ public void testUpdateDatasetVersionWithFiles() throws InterruptedException { String datasetPersistentId = protocol + ":" + authority + "/" + identifier; System.out.println("datasetPersistentId: " + datasetPersistentId); - String pathToJsonFile = "src/test/resources/json/update-dataset-version-with-files.json"; + String pathToJsonFile = "src/test/resources/json/update-dataset-version-with-files.json"; Response updateMetadataAddFilesViaNative = UtilIT.updateDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, authorApiToken); updateMetadataAddFilesViaNative.prettyPrint(); @@ -2917,13 +2938,13 @@ public void testUnrestrictedFileExportDdi() throws IOException { .body("codeBook.dataDscr.var[1].sumStat.find { it.@type == 'max' }", equalTo("40.0")) .body("codeBook.dataDscr.var[2].@name", equalTo("species")); } - + /** * In this test we are restricting a file and testing "export DDI" at the * dataset level as well as getting the DDI at the file level. - * + *

* Export at the dataset level is always the public version. - * + *

* At the file level, you can still get summary statistics (and friends, * "dataDscr") if you have access to download the file. If you don't have * access, you get an error. @@ -3067,7 +3088,7 @@ public void testSemanticMetadataAPIs() { } catch (NoSuchMethodError e) { logger.info(ExceptionUtils.getStackTrace(e)); } - + String expectedJsonLD = UtilIT.getDatasetJson("scripts/search/tests/data/dataset-finch1.jsonld"); jo = Json.createObjectBuilder(jo).remove("@id").remove("http://schema.org/dateModified").build(); @@ -3190,7 +3211,7 @@ public void testSemanticMetadataAPIs() { assertEquals(200, deleteUserResponse.getStatusCode()); } - + @Test public void testReCreateDataset() { @@ -3215,13 +3236,13 @@ public void testReCreateDataset() { response.then().assertThat().statusCode(OK.getStatusCode()); response.prettyPeek(); String expectedString = getData(response.getBody().asString()); - + // Delete the dataset via native API Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + logger.info("SENDING to reCreate Dataset: " + expectedString); // Now use the migrate API to recreate the dataset // Now use the migrate API to recreate the dataset @@ -3276,13 +3297,13 @@ public void testCurationLabelAPIs() { Response setCurationLabelSets = UtilIT.setSetting(SettingsServiceBean.Key.AllowedCurationLabels, "{\"StandardProcess\":[\"Author contacted\", \"Privacy Review\", \"Awaiting paper publication\", \"Final Approval\"],\"AlternateProcess\":[\"State 1\",\"State 2\",\"State 3\"]}"); setCurationLabelSets.then().assertThat() .statusCode(OK.getStatusCode()); - - + + //Set curation label set on dataverse //Valid option, bad user Response setDataverseCurationLabelSetResponse = UtilIT.setDataverseCurationLabelSet(dataverseAlias, apiToken, "AlternateProcess"); setDataverseCurationLabelSetResponse.then().assertThat().statusCode(FORBIDDEN.getStatusCode()); - + Response makeSuperUser = UtilIT.makeSuperUser(username); assertEquals(200, makeSuperUser.getStatusCode()); @@ -3293,7 +3314,7 @@ public void testCurationLabelAPIs() { Response setDataverseCurationLabelSetResponse3 = UtilIT.setDataverseCurationLabelSet(dataverseAlias, apiToken, "AlternateProcess"); setDataverseCurationLabelSetResponse3.then().assertThat().statusCode(OK.getStatusCode()); - + // Create a dataset using native api Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); createDatasetResponse.prettyPrint(); @@ -3305,7 +3326,7 @@ public void testCurationLabelAPIs() { String labelSetName = getData(response.getBody().asString()); // full should be {"message":"AlternateProcess"} assertTrue(labelSetName.contains("AlternateProcess")); - + // Now set a label //Option from the wrong set Response response2 = UtilIT.setDatasetCurationLabel(datasetId, apiToken, "Author contacted"); @@ -3367,24 +3388,23 @@ public void testFilesUnchangedAfterDatasetMetadataUpdate() throws IOException { .statusCode(OK.getStatusCode()) .body("data.latestVersion.files[0].label", equalTo("run.sh")) .body("data.latestVersion.files[0].directoryLabel", equalTo("code")); - + String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-update-metadata.json"; Response updateTitle = UtilIT.updateDatasetMetadataViaNative(datasetPid, pathToJsonFile, apiToken); updateTitle.prettyPrint(); updateTitle.then().assertThat() .statusCode(OK.getStatusCode()); - + Response getDatasetJsonAfterUpdate = UtilIT.nativeGet(datasetId, apiToken); getDatasetJsonAfterUpdate.prettyPrint(); getDatasetJsonAfterUpdate.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.latestVersion.files[0].label", equalTo("run.sh")) .body("data.latestVersion.files[0].directoryLabel", equalTo("code")); - + } - @Test public void testCuratePublishedDatasetVersionCommand() throws IOException { Response createUser = UtilIT.createRandomUser(); @@ -3393,8 +3413,8 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { .statusCode(OK.getStatusCode()); String apiToken = UtilIT.getApiTokenFromResponse(createUser); String username = UtilIT.getUsernameFromResponse(createUser); - - + + Response createDataverse = UtilIT.createRandomDataverse(apiToken); createDataverse.prettyPrint(); createDataverse.then().assertThat() @@ -3417,8 +3437,6 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { .add("description", "A script to reproduce results.") .add("directoryLabel", "code"); - - String pathToFileThatGoesThroughIngest = "src/test/resources/sav/dct.sav"; Response uploadIngestableFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFileThatGoesThroughIngest, apiToken); @@ -3432,12 +3450,12 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { logger.fine("Orig file id: " + origFileId); assertNotNull(origFileId); - assertNotEquals("",origFileId); + assertNotEquals("", origFileId); // Give file time to ingest - + assertTrue(UtilIT.sleepForLock(datasetId.longValue(), "Ingest", apiToken, UtilIT.MAXIMUM_INGEST_LOCK_DURATION), "Failed test if Ingest Lock exceeds max duration " + pathToFileThatGoesThroughIngest); - + Response origXml = UtilIT.getFileMetadata(origFileId, null, apiToken); assertEquals(200, origXml.getStatusCode()); @@ -3447,7 +3465,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { InputStream variableData = origXml.body().asInputStream(); Map mapVarToVarMet = new HashMap(); - Map varGroupMap = new HashMap(); + Map varGroupMap = new HashMap(); try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xmlr = factory.createXMLStreamReader(variableData); @@ -3457,7 +3475,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { } catch (XMLStreamException e) { logger.warning(e.getMessage()); - assertEquals(0,1); + assertEquals(0, 1); } @@ -3467,7 +3485,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { updatedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/xml/dct.xml"))); } catch (IOException e) { logger.warning(e.getMessage()); - assertEquals(0,1); + assertEquals(0, 1); } Long replV1168 = 0L; Long replV1169 = 0L; @@ -3476,20 +3494,20 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { for (VariableMetadata var : mapVarToVarMet.values()) { if (var.getLabel().equals("gender")) { replV1170 = var.getDataVariable().getId(); - numberVariables = numberVariables +1; + numberVariables = numberVariables + 1; } else if (var.getLabel().equals("weight")) { replV1168 = var.getDataVariable().getId(); - numberVariables = numberVariables +1; + numberVariables = numberVariables + 1; } else if (var.getLabel().equals("age_rollup")) { replV1169 = var.getDataVariable().getId(); - numberVariables = numberVariables +1; + numberVariables = numberVariables + 1; } } assertEquals(3, numberVariables); - updatedContent = updatedContent.replaceAll("v1168", "v" + replV1168 ); - updatedContent = updatedContent.replaceAll("v1169", "v" + replV1169 ); - updatedContent = updatedContent.replaceAll("v1170", "v" + replV1170 ); + updatedContent = updatedContent.replaceAll("v1168", "v" + replV1168); + updatedContent = updatedContent.replaceAll("v1169", "v" + replV1169); + updatedContent = updatedContent.replaceAll("v1170", "v" + replV1170); //edit draft vesrsion Response editDDIResponse = UtilIT.editDDI(updatedContent, origFileId, apiToken); @@ -3498,7 +3516,6 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { assertEquals(200, editDDIResponse.getStatusCode()); - UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); @@ -3507,36 +3524,35 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { getDatasetJsonBeforeUpdate.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.latestVersion.files[0].label", equalTo("dct.tab")); - + String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-update-metadata.json"; Response updateTitle = UtilIT.updateDatasetMetadataViaNative(datasetPid, pathToJsonFile, apiToken); updateTitle.prettyPrint(); updateTitle.then().assertThat() .statusCode(OK.getStatusCode()); - + // shouldn't be able to update current unless you're a super user UtilIT.publishDatasetViaNativeApi(datasetId, "updatecurrent", apiToken).then().assertThat().statusCode(FORBIDDEN.getStatusCode()); - + Response makeSuperUser = UtilIT.makeSuperUser(username); - + //should work after making super user - + UtilIT.publishDatasetViaNativeApi(datasetId, "updatecurrent", apiToken).then().assertThat().statusCode(OK.getStatusCode()); - + Response getDatasetJsonAfterUpdate = UtilIT.nativeGet(datasetId, apiToken); getDatasetJsonAfterUpdate.prettyPrint(); getDatasetJsonAfterUpdate.then().assertThat() .statusCode(OK.getStatusCode()); - + } - + /** * In this test we are restricting a file and testing that terms of accees * or request access is required - * + *

* Export at the dataset level is always the public version. - * */ @Test public void testRestrictFileTermsOfUseAndAccess() throws IOException { @@ -3586,21 +3602,21 @@ public void testRestrictFileTermsOfUseAndAccess() throws IOException { publishDataverse.then().assertThat().statusCode(OK.getStatusCode()); Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPid, "major", authorApiToken); publishDataset.then().assertThat().statusCode(OK.getStatusCode()); - - + + //not allowed to remove request access if there are retricted files - + Response disallowRequestAccess = UtilIT.allowAccessRequests(datasetPid, false, authorApiToken); disallowRequestAccess.prettyPrint(); disallowRequestAccess.then().assertThat().statusCode(BAD_REQUEST.getStatusCode()); - + } - + /** * In this test we are removing request access and showing that * files cannot be restricted - * Not testing legacy datasets that are out of compliance - * cannot be published or upload files + * Not testing legacy datasets that are out of compliance + * cannot be published or upload files * or have metadata updated - */ @Test @@ -3624,7 +3640,7 @@ public void testRestrictFilesWORequestAccess() throws IOException { Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset); String datasetPid = JsonPath.from(createDataset.asString()).getString("data.persistentId"); - + //should be allowed to remove Request access before restricting file Response disallowRequestAccess = UtilIT.allowAccessRequests(datasetPid, false, authorApiToken); disallowRequestAccess.prettyPrint(); @@ -3652,13 +3668,13 @@ public void testRestrictFilesWORequestAccess() throws IOException { restrictFile.prettyPrint(); //shouldn't be able to restrict a file restrictFile.then().assertThat().statusCode(CONFLICT.getStatusCode()); - + // OK, let's delete this dataset as well, and then delete the dataverse... - + Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, authorApiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, authorApiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); @@ -3673,7 +3689,7 @@ public void testRestrictFilesWORequestAccess() throws IOException { * In this test we do CRUD of archivalStatus (Note this and other archiving * related tests are part of * https://github.com/harvard-lts/hdc-integration-tests) - * + *

* This test requires the root dataverse to be published to pass. */ @Test @@ -3730,7 +3746,7 @@ public void testArchivalStatusAPI() throws IOException { addSubjectSingleViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + // Now change the title // Response response = UtilIT.updateDatasetJsonLDMetadata(datasetId, apiToken, // "{\"title\": \"New Title\", \"@context\":{\"title\": \"http://purl.org/dc/terms/title\"}}", true); @@ -3750,7 +3766,8 @@ public void testArchivalStatusAPI() throws IOException { //Verify the status is empty Response nullStatus = UtilIT.getDatasetVersionArchivalStatus(datasetId, "1.0", apiToken); - nullStatus.then().assertThat().statusCode(NO_CONTENT.getStatusCode()); + nullStatus.prettyPrint(); + nullStatus.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); //Set it Response setStatus = UtilIT.setDatasetVersionArchivalStatus(datasetId, "1.0", apiToken, "pending", @@ -3910,7 +3927,7 @@ public void getDatasetVersionCitation() { getDatasetVersionCitationNotDeaccessioned.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); // includeDeaccessioned true - Response getDatasetVersionCitationDeaccessioned = UtilIT.getDatasetVersionCitation(datasetId, DS_VERSION_LATEST_PUBLISHED, true, apiToken); + Response getDatasetVersionCitationDeaccessioned = UtilIT.getDatasetVersionCitation(datasetId, DS_VERSION_LATEST_PUBLISHED, true, apiToken); getDatasetVersionCitationDeaccessioned.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.message", containsString("DEACCESSIONED VERSION")); @@ -4681,7 +4698,7 @@ public void testGetGlobusUploadParameters() { for (int i = 0; i < signedUrls.size(); i++) { JsonObject signedUrl = signedUrls.getJsonObject(i); if (signedUrl.getString("name").equals("requestGlobusReferencePaths")) { - found=true; + found = true; break; } } From cb9b55ad40de6abf2d109425b03920632b9b8dac Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Tue, 9 Apr 2024 20:19:51 -0300 Subject: [PATCH 08/12] 9375: Refactoring and adding test --- .../dataverse/engine/command/impl/AssignRoleCommand.java | 4 +++- src/main/java/propertyFiles/Bundle.properties | 1 + src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java index dee567a83a2..7e0bc98e696 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java @@ -18,6 +18,8 @@ import edu.harvard.iq.dataverse.engine.command.DataverseRequest; import edu.harvard.iq.dataverse.engine.command.exception.CommandException; import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException; +import edu.harvard.iq.dataverse.util.BundleUtil; + import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -69,7 +71,7 @@ public RoleAssignment execute(CommandContext ctxt) throws CommandException { } } if(isExistingRole(ctxt)){ - throw new IllegalCommandException("User already has this role for this object", this); + throw new IllegalCommandException(BundleUtil.getStringFromBundle("externalTools.error.roleAlreadyExistent"), this); } // TODO make sure the role is defined on the dataverse. RoleAssignment roleAssignment = new RoleAssignment(role, grantee, defPoint, privateUrlToken, anonymizedAccess); diff --git a/src/main/java/propertyFiles/Bundle.properties b/src/main/java/propertyFiles/Bundle.properties index 692ab9e0686..231de623adb 100644 --- a/src/main/java/propertyFiles/Bundle.properties +++ b/src/main/java/propertyFiles/Bundle.properties @@ -2947,6 +2947,7 @@ externaltools.dct.displayname=Data Curation Tool externaltools.dct.description=Data Curation Tool for curation of variables externaltools.explorer.displayname=Data Explorer externaltools.explorer.description=The Data Explorer provides a GUI which lists the variables in a tabular data file allowing searching, charting and cross tabulation analysis. +externalTools.error.roleAlreadyExistent="User already has this role for this object" # api/admin/datasetfield/load api.admin.datasetfield.load.ArrayIndexOutOfBoundMessage=Error parsing metadata block in {0} part, line #{1}: missing ''{2}'' column (#{3}) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 61ec8cfde14..78bad3a15cf 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -1715,6 +1715,9 @@ public void testAddRoles() { giveRandoPermission.prettyPrint(); assertEquals(200, giveRandoPermission.getStatusCode()); + //Asserting same role creation is covered + validateAssignExistingRole(datasetPersistentId,randomUsername,apiToken, "fileDownloader"); + // Create another random user to become curator: Response createCuratorUser = UtilIT.createRandomUser(); @@ -1852,8 +1855,8 @@ public void testListRoleAssignments() { assertEquals(UNAUTHORIZED.getStatusCode(), notPermittedToListRoleAssignmentOnDataverse.getStatusCode()); } - private static void validateAssignExistingRole(String datasetPersistentId, String randomUsername, String apiToken) { - final Response failedGrantPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); + private static void validateAssignExistingRole(String datasetPersistentId, String randomUsername, String apiToken, String role) { + final Response failedGrantPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, role, "@" + randomUsername, apiToken); failedGrantPermission.prettyPrint(); failedGrantPermission.then().assertThat() .body("message", containsString("User already has this role for this object")) From 6d777a4722b6ad737c80c84d7bc8bcccfed5b5ee Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Tue, 9 Apr 2024 20:30:50 -0300 Subject: [PATCH 09/12] 9375: Changing message to use property file --- .../iq/dataverse/engine/command/impl/AssignRoleCommand.java | 3 +-- src/main/java/propertyFiles/Bundle.properties | 2 +- src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java index 7e0bc98e696..121af765737 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AssignRoleCommand.java @@ -3,7 +3,6 @@ */ package edu.harvard.iq.dataverse.engine.command.impl; -import edu.harvard.iq.dataverse.DataFile; import edu.harvard.iq.dataverse.Dataset; import edu.harvard.iq.dataverse.Dataverse; import edu.harvard.iq.dataverse.authorization.DataverseRole; @@ -71,7 +70,7 @@ public RoleAssignment execute(CommandContext ctxt) throws CommandException { } } if(isExistingRole(ctxt)){ - throw new IllegalCommandException(BundleUtil.getStringFromBundle("externalTools.error.roleAlreadyExistent"), this); + throw new IllegalCommandException(BundleUtil.getStringFromBundle("datasets.api.grant.role.assignee.has.role.error"), this); } // TODO make sure the role is defined on the dataverse. RoleAssignment roleAssignment = new RoleAssignment(role, grantee, defPoint, privateUrlToken, anonymizedAccess); diff --git a/src/main/java/propertyFiles/Bundle.properties b/src/main/java/propertyFiles/Bundle.properties index 231de623adb..9357b3a3f1d 100644 --- a/src/main/java/propertyFiles/Bundle.properties +++ b/src/main/java/propertyFiles/Bundle.properties @@ -2669,6 +2669,7 @@ datasets.api.datasize.ioerror=Fatal IO error while trying to determine the total datasets.api.grant.role.not.found.error=Cannot find role named ''{0}'' in dataverse {1} datasets.api.grant.role.cant.create.assignment.error=Cannot create assignment: {0} datasets.api.grant.role.assignee.not.found.error=Assignee not found +datasets.api.grant.role.assignee.has.role.error=User already has this role for this dataset datasets.api.revoke.role.not.found.error="Role assignment {0} not found" datasets.api.revoke.role.success=Role {0} revoked for assignee {1} in {2} datasets.api.privateurl.error.datasetnotfound=Could not find dataset. @@ -2947,7 +2948,6 @@ externaltools.dct.displayname=Data Curation Tool externaltools.dct.description=Data Curation Tool for curation of variables externaltools.explorer.displayname=Data Explorer externaltools.explorer.description=The Data Explorer provides a GUI which lists the variables in a tabular data file allowing searching, charting and cross tabulation analysis. -externalTools.error.roleAlreadyExistent="User already has this role for this object" # api/admin/datasetfield/load api.admin.datasetfield.load.ArrayIndexOutOfBoundMessage=Error parsing metadata block in {0} part, line #{1}: missing ''{2}'' column (#{3}) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 78bad3a15cf..54b79a60dcf 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -1859,7 +1859,7 @@ private static void validateAssignExistingRole(String datasetPersistentId, Strin final Response failedGrantPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, role, "@" + randomUsername, apiToken); failedGrantPermission.prettyPrint(); failedGrantPermission.then().assertThat() - .body("message", containsString("User already has this role for this object")) + .body("message", containsString("User already has this role for this dataset")) .statusCode(FORBIDDEN.getStatusCode()); } From 00fcef843151385931db2d06eeaee780c6866859 Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Fri, 19 Apr 2024 17:36:26 -0300 Subject: [PATCH 10/12] 9887: rolling back formatting --- .../harvard/iq/dataverse/api/DatasetsIT.java | 235 +++++++++--------- 1 file changed, 120 insertions(+), 115 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 54b79a60dcf..0dba20231ec 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -89,7 +89,7 @@ public static void setUpClass() { UtilIT.deleteSetting(SettingsServiceBean.Key.MaxEmbargoDurationInMonths); /* With Dual mode, we can no longer mess with upload methods since native is now required for anything to work - + Response removeDcmUrl = UtilIT.deleteSetting(SettingsServiceBean.Key.DataCaptureModuleUrl); removeDcmUrl.then().assertThat() .statusCode(200); @@ -130,7 +130,7 @@ public static void afterClass() { } @Test - public void testCollectionSchema() { + public void testCollectionSchema(){ Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); @@ -141,7 +141,7 @@ public void testCollectionSchema() { createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); - Response getCollectionSchemaResponse = UtilIT.getCollectionSchema(dataverseAlias, apiToken); + Response getCollectionSchemaResponse = UtilIT.getCollectionSchema(dataverseAlias, apiToken); getCollectionSchemaResponse.prettyPrint(); getCollectionSchemaResponse.then().assertThat() .statusCode(200); @@ -209,24 +209,24 @@ public void testCreateDataset() { deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - // Now, let's allow anyone with a Dataverse account (any "random user") - // to create datasets in this dataverse: + // Now, let's allow anyone with a Dataverse account (any "random user") + // to create datasets in this dataverse: Response grantRole = UtilIT.grantRoleOnDataverse(dataverseAlias, DataverseRole.DS_CONTRIBUTOR, AuthenticatedUsers.get().getIdentifier(), apiToken); grantRole.prettyPrint(); assertEquals(OK.getStatusCode(), grantRole.getStatusCode()); - // Create another random user: + // Create another random user: Response createRandomUser = UtilIT.createRandomUser(); createRandomUser.prettyPrint(); String randomUsername = UtilIT.getUsernameFromResponse(createRandomUser); String randomUserApiToken = UtilIT.getApiTokenFromResponse(createRandomUser); - // This random user should be able to create a dataset in the dataverse + // This random user should be able to create a dataset in the dataverse // above, because we've set it up so, right? - Not exactly: the dataverse - // hasn't been published yet! So if this random user tries to create - // a dataset now, it should fail: + // hasn't been published yet! So if this random user tries to create + // a dataset now, it should fail: /* - this test removed because the perms for create dataset have been reverted createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, randomUserApiToken); createDatasetResponse.prettyPrint(); @@ -242,11 +242,10 @@ public void testCreateDataset() { try { Thread.sleep(1000l); - } catch (InterruptedException iex) { - } + } catch (InterruptedException iex) {} - // ... And now that it's published, try to create a dataset again, - // as the "random", not specifically authorized user: + // ... And now that it's published, try to create a dataset again, + // as the "random", not specifically authorized user: // (this time around, it should work!) createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, randomUserApiToken); @@ -311,6 +310,7 @@ public void testAddUpdateDatasetViaNativeAPI() { .statusCode(OK.getStatusCode()); + RestAssured.registerParser("text/plain", Parser.JSON); Response exportDatasetAsJson = UtilIT.exportDataset(datasetPersistentId, "dataverse_json", apiToken); exportDatasetAsJson.prettyPrint(); @@ -329,6 +329,7 @@ public void testAddUpdateDatasetViaNativeAPI() { .statusCode(OK.getStatusCode()).body(containsString("Mathematical Sciences")).body(containsString("Social Sciences")); + //Trying to blank out required field should fail... String pathToJsonFileBadData = "doc/sphinx-guides/source/_static/api/dataset-update-with-blank-metadata.json"; Response deleteTitleViaNative = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileBadData, apiToken); @@ -341,7 +342,7 @@ public void testAddUpdateDatasetViaNativeAPI() { Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); //post publish update - String pathToJsonFilePostPub = "doc/sphinx-guides/source/_static/api/dataset-add-metadata-after-pub.json"; + String pathToJsonFilePostPub= "doc/sphinx-guides/source/_static/api/dataset-add-metadata-after-pub.json"; Response addDataToPublishedVersion = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFilePostPub, apiToken); addDataToPublishedVersion.prettyPrint(); addDataToPublishedVersion.then().assertThat().statusCode(OK.getStatusCode()); @@ -438,7 +439,7 @@ public void testCreatePublishDestroyDataset() { Response createNoAccessUser = UtilIT.createRandomUser(); createNoAccessUser.prettyPrint(); - String apiTokenNoAccess = UtilIT.getApiTokenFromResponse(createNoAccessUser); + String apiTokenNoAccess= UtilIT.getApiTokenFromResponse(createNoAccessUser); Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); @@ -475,8 +476,7 @@ public void testCreatePublishDestroyDataset() { try { Thread.sleep(3000l); - } catch (InterruptedException iex) { - } + } catch (InterruptedException iex) {} Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -602,6 +602,7 @@ public void testCreatePublishDestroyDataset() { */ @Test public void testDatasetVersionsAPI() { + // Create user String apiToken = UtilIT.createRandomUserGetToken(); @@ -630,8 +631,8 @@ public void testDatasetVersionsAPI() { unpublishedDraft.then().assertThat() .statusCode(OK.getStatusCode()); - // Now check that the file is NOT shown, when we ask the versions api to - // skip files: + // Now check that the file is NOT shown, when we ask the versions api to + // skip files: boolean excludeFiles = true; unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_DRAFT, apiToken, excludeFiles, false); unpublishedDraft.prettyPrint(); @@ -691,11 +692,11 @@ public void testDatasetVersionsAPI() { .body("data.versionState", equalTo("RELEASED")) .body("data.latestVersionPublishingState", equalTo("DRAFT")); - // We should now have a published version, and a draft. + // We should now have a published version, and a draft. - // Call /versions api, *with the owner api token*, make sure both - // versions are listed; also check that the correct numbers of files - // are shown in each version (2 in the draft, 1 in the published). + // Call /versions api, *with the owner api token*, make sure both + // 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() @@ -717,7 +718,7 @@ public void testDatasetVersionsAPI() { .body("data.versionState[0]", equalTo("DRAFT")) .body("data[0].files.size()", equalTo(2)); - // And now call it with an un-privileged token, to make sure only one + // And now call it with an un-privileged token, to make sure only one // (the published) version is shown: versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms); versionsResponse.prettyPrint(); @@ -735,6 +736,10 @@ public void testDatasetVersionsAPI() { .body("data[0].files", equalTo(null)); + + + + excludeFiles = true; //Latest published authorized token //Latest published requested, draft exists and user has access to draft @@ -1043,13 +1048,12 @@ public void testExport() { logger.info("In testExport; attempting to publish, as major version"); //Return random sleep 9/13/2019 - // 3 second sleep, to allow the indexing to finish: + // 3 second sleep, to allow the indexing to finish: // Without it we've seen som DB dealocks try { Thread.sleep(3000l); - } catch (InterruptedException iex) { - } + } catch (InterruptedException iex) {} Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -1187,8 +1191,7 @@ public void testExcludeEmail() { try { Thread.sleep(3000l); - } catch (InterruptedException iex) { - } + } catch (InterruptedException iex) {} Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -1263,17 +1266,17 @@ public void testExcludeEmail() { @Test public void testStoredProcGeneratedAsIdentifierGenerationStyle() { // Please note that this test only works if the stored procedure - // named generateIdentifierFromStoredProcedure() has been created in the + // named generateIdentifierFromStoredProcedure() has been created in the // database (see the documentation for the "IdentifierGenerationStyle" option // in the Configuration section of the Installation guide). // Furthermore, the test below expects the identifier generated by the stored - // procedure to be a numeric string. The "sequential numerical values" procedure, - // documented as the first example in the guide above, will satisfy the test. + // procedure to be a numeric string. The "sequential numerical values" procedure, + // documented as the first example in the guide above, will satisfy the test. // If your installation is using a stored procedure that generates the identifiers - // in any other format, the test below will fail. - // (The test is mainly used by the Dataverse Project's automated API test system - // to verify the integrity of this framework for generating the identifiers on the - // database side). + // in any other format, the test below will fail. + // (The test is mainly used by the Dataverse Project's automated API test system + // to verify the integrity of this framework for generating the identifiers on the + // database side). Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); @@ -1299,13 +1302,11 @@ public void testStoredProcGeneratedAsIdentifierGenerationStyle() { logger.info("identifier: " + identifier); String numericPart = identifier.replace("FK2/", ""); //remove shoulder from identifier assertTrue(StringUtils.isNumeric(numericPart)); - //Return random sleep 9/13/2019 + //Return random sleep 9/13/2019 try { Thread.sleep(3000l); - } catch (Exception ex) { - logger.warning("failed to execute sleep 3 sec."); - } + } catch (Exception ex) {logger.warning("failed to execute sleep 3 sec.");} Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); @@ -1445,67 +1446,67 @@ public void testPrivateUrl() { assertEquals(OK.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode()); /* - * NOTE, this is what happens when we attempt to access the dataset via the - * private url, as implemented above: - * - * The private url page authorizes the user to view the dataset - * by issuing a new jsession, and issuing a 302 redirect to the dataset - * page WITH THE JSESSIONID ADDED TO THE URL - as in + * NOTE, this is what happens when we attempt to access the dataset via the + * private url, as implemented above: + * + * The private url page authorizes the user to view the dataset + * by issuing a new jsession, and issuing a 302 redirect to the dataset + * page WITH THE JSESSIONID ADDED TO THE URL - as in * dataset.xhtml?persistentId=xxx&jsessionid=yyy - * RestAssured's .get() method follows redirects by default - so in the - * end the above works and we get the correct dataset. - * But note that this relies on the jsessionid in the url. We've - * experimented with disabling url-supplied jsessions (in PR #5316); - * then the above stopped working - because now jsession is supplied - * AS A COOKIE, which the RestAssured code above does not use, so - * the dataset page refuses to show the dataset to the user. (So the - * assertEquals code above fails, because the page title is not "Darwin's Finches", + * RestAssured's .get() method follows redirects by default - so in the + * end the above works and we get the correct dataset. + * But note that this relies on the jsessionid in the url. We've + * experimented with disabling url-supplied jsessions (in PR #5316); + * then the above stopped working - because now jsession is supplied + * AS A COOKIE, which the RestAssured code above does not use, so + * the dataset page refuses to show the dataset to the user. (So the + * assertEquals code above fails, because the page title is not "Darwin's Finches", * but "Login Page") - * Below is an implementation of the test above that uses the jsession - * cookie, instead of relying on the jsessionid in the URL: - - // This should redirect us to the actual dataset page, and - // give us a valid session cookie: - + * Below is an implementation of the test above that uses the jsession + * cookie, instead of relying on the jsessionid in the URL: + + // This should redirect us to the actual dataset page, and + // give us a valid session cookie: + Response getDatasetAsUserWhoClicksPrivateUrl = given() .header(API_TOKEN_HTTP_HEADER, apiToken) .redirects().follow(false) .get(urlWithToken); - // (note that we have purposefully asked not to follow redirects + // (note that we have purposefully asked not to follow redirects // automatically; this way we can test that we are being redirected // to the right place, that we've been given the session cookie, etc. - + assertEquals(FOUND.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode()); // Yes, javax.ws.rs.core.Response.Status.FOUND is 302! String title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title"); assertEquals("Document moved", title); - + String redirectLink = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.body.a.@href"); assertNotNull(redirectLink); assertTrue(redirectLink.contains("dataset.xhtml")); - + String jsessionid = getDatasetAsUserWhoClicksPrivateUrl.cookie("jsessionid"); assertNotNull(jsessionid); - - // ... and now we can try and access the dataset, with another HTTP GET, + + // ... and now we can try and access the dataset, with another HTTP GET, // sending the jsession cookie along: - - try { + + try { redirectLink = URLDecoder.decode(redirectLink, "UTF-8"); } catch (UnsupportedEncodingException ex) { - // do nothing - try to redirect to the url as is? + // do nothing - try to redirect to the url as is? } - + logger.info("redirecting to "+redirectLink+", using jsession "+jsessionid); - + getDatasetAsUserWhoClicksPrivateUrl = given() .cookies("JSESSIONID", jsessionid) .get(redirectLink); - + assertEquals(OK.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode()); title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title"); assertEquals("Darwin's Finches - " + dataverseAlias, title); - + */ Response junkPrivateUrlToken = given() @@ -1668,7 +1669,7 @@ public void testPrivateUrl() { } @Test - public void testAddRoles() { + public void testAddRoles(){ Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); @@ -1696,7 +1697,8 @@ public void testAddRoles() { String datasetPersistentId = protocol1 + ":" + authority1 + "/" + identifier1; - // Create another random user: + + // Create another random user: Response createRandomUser = UtilIT.createRandomUser(); createRandomUser.prettyPrint(); @@ -1738,7 +1740,6 @@ public void testAddRoles() { giveTooMuchPermission.prettyPrint(); assertEquals(401, giveTooMuchPermission.getStatusCode()); - String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "designatedHitter", "@" + randomUsername, apiToken); @@ -2168,7 +2169,7 @@ public void testCreateDatasetWithDcmDependency() { */ @Test public void testDcmChecksumValidationMessages() throws IOException, InterruptedException { - + /*SEK 3/28/2018 This test needs more work Currently it is failing at around line 1114 Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); @@ -2411,7 +2412,7 @@ public void testCreateDeleteDatasetLink() { createDatasetResponse.prettyPrint(); Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); - // This should fail, because we are attempting to link the dataset + // This should fail, because we are attempting to link the dataset // to its own dataverse: Response publishTargetDataverse = UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken); publishTargetDataverse.prettyPrint(); @@ -2442,7 +2443,7 @@ public void testCreateDeleteDatasetLink() { createLinkingDatasetResponse = UtilIT.createDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); createLinkingDatasetResponse.prettyPrint(); createLinkingDatasetResponse.then().assertThat() - .body("data.message", equalTo("Dataset " + datasetId + " linked successfully to " + dataverseAlias)) + .body("data.message", equalTo("Dataset " + datasetId +" linked successfully to " + dataverseAlias)) .statusCode(200); // And now test deleting it: @@ -2463,7 +2464,7 @@ public void testApiErrors() { This test excerises the issue where the update apis fail when the dataset is out of compliance with the requirement that datasets containing restricted files must allow reuest access or have terms of access. It's impossible to get a dataset into this state via the version 5.11.1 or later so if you needc to - run this test you must set it up manually by setting requestAccess on TermsOfUseAccess to false + run this test you must set it up manually by setting requestAccess on TermsOfUseAccess to false with an update query. Update the decalarations below with values from your test environment */ @@ -2530,14 +2531,14 @@ public void testDatasetLocksApi() { .body("data", equalTo(emptyArray)) .statusCode(200); - // Lock the dataset with an ingest lock: + // Lock the dataset with an ingest lock: Response lockDatasetResponse = UtilIT.lockDataset(datasetId.longValue(), "Ingest", apiToken); lockDatasetResponse.prettyPrint(); lockDatasetResponse.then().assertThat() .body("data.message", equalTo("dataset locked with lock type Ingest")) .statusCode(200); - // Check again: + // Check again: // This should return an empty list, as the dataset should have no locks just yet: checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken); checkDatasetLocks.prettyPrint(); @@ -2545,7 +2546,7 @@ public void testDatasetLocksApi() { .body("data[0].lockType", equalTo("Ingest")) .statusCode(200); - // Try to lock the dataset with the same type lock, AGAIN + // Try to lock the dataset with the same type lock, AGAIN // (this should fail, of course!) lockDatasetResponse = UtilIT.lockDataset(datasetId.longValue(), "Ingest", apiToken); lockDatasetResponse.prettyPrint(); @@ -2553,10 +2554,10 @@ public void testDatasetLocksApi() { .body("message", equalTo("dataset already locked with lock type Ingest")) .statusCode(FORBIDDEN.getStatusCode()); - // Let's also test the new (as of 5.10) API that lists the locks - // present across all datasets. + // Let's also test the new (as of 5.10) API that lists the locks + // present across all datasets. - // First, we'll try listing ALL locks currently in the system, and make sure that the ingest lock + // First, we'll try listing ALL locks currently in the system, and make sure that the ingest lock // for this dataset is on the list: checkDatasetLocks = UtilIT.listAllLocks(apiToken); checkDatasetLocks.prettyPrint(); @@ -2575,7 +2576,7 @@ public void testDatasetLocksApi() { } assertTrue(lockListedCorrectly, "Lock missing from the output of /api/datasets/locks"); - // Try the same, but with an api token of a random, non-super user + // Try the same, but with an api token of a random, non-super user // (this should get rejected): createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); @@ -2585,14 +2586,14 @@ public void testDatasetLocksApi() { checkDatasetLocks.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()); - // Try to narrow the listing down to the lock of type=Ingest specifically; + // Try to narrow the listing down to the lock of type=Ingest specifically; // verify that the lock in question is still being listed: checkDatasetLocks = UtilIT.listLocksByType("Ingest", apiToken); checkDatasetLocks.prettyPrint(); - // We'll again assume that it's possible that the API is going to list - // *multiple* locks; i.e. that there are other datasets with the lock + // We'll again assume that it's possible that the API is going to list + // *multiple* locks; i.e. that there are other datasets with the lock // of type "Ingest" on them. So we'll go through the list and look for the - // lock for this specific dataset again. + // lock for this specific dataset again. lockListedCorrectly = false; listedLockEntries = checkDatasetLocks.body().jsonPath().getList("data"); for (int i = 0; i < listedLockEntries.size(); i++) { @@ -2613,7 +2614,7 @@ public void testDatasetLocksApi() { .body("message", startsWith("Invalid lock type value: BadLockType")) .statusCode(BAD_REQUEST.getStatusCode()); - // List the locks owned by the current user; verify that the lock above + // List the locks owned by the current user; verify that the lock above // is still listed: checkDatasetLocks = UtilIT.listLocksByUser(username, apiToken); checkDatasetLocks.prettyPrint(); @@ -2624,7 +2625,7 @@ public void testDatasetLocksApi() { .body("data[0].dataset", equalTo(persistentIdentifier)) .statusCode(200); - // Further narrow down the listing to both the type AND user: + // Further narrow down the listing to both the type AND user: checkDatasetLocks = UtilIT.listLocksByTypeAndUser("Ingest", username, apiToken); checkDatasetLocks.prettyPrint(); // Even safer to assume there should be only one: @@ -2635,7 +2636,7 @@ public void testDatasetLocksApi() { .body("data[0].dataset", equalTo(persistentIdentifier)); - // Finally, try asking for the locks owned by this user AND of type "InReview". + // Finally, try asking for the locks owned by this user AND of type "InReview". // This should produce an empty list: checkDatasetLocks = UtilIT.listLocksByTypeAndUser("InReview", username, apiToken); checkDatasetLocks.prettyPrint(); @@ -2651,7 +2652,7 @@ public void testDatasetLocksApi() { .body("data.message", equalTo("lock type Ingest removed")) .statusCode(200); - // ... and check for the lock on the dataset again, this time by specific lock type: + // ... and check for the lock on the dataset again, this time by specific lock type: // (should return an empty list, now that we have unlocked it) checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken); checkDatasetLocks.prettyPrint(); @@ -2696,8 +2697,7 @@ public void testUpdatePIDMetadataAPI() { //without it we've seen DB deadlocks try { Thread.sleep(3000l); - } catch (InterruptedException iex) { - } + } catch (InterruptedException iex){} Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -2856,7 +2856,7 @@ public void testLinkingDatasets() { Integer datasetId2 = UtilIT.getDatasetIdFromResponse(createDataset); String datasetPid2 = JsonPath.from(createDataset.asString()).getString("data.persistentId"); - + linkDataset = UtilIT.linkDataset(datasetPid2, dataverse2Alias, superuserApiToken); linkDataset.prettyPrint(); linkDataset.then().assertThat() @@ -2869,7 +2869,7 @@ public void testLinkingDatasets() { entityManager.getTransaction().commit(); entityManager.close(); - + UtilIT.linkDataset(datasetId2.toString(), dataverse2Alias, superuserApiToken); linkDataset.prettyPrint(); linkDataset.then().assertThat() @@ -2945,9 +2945,9 @@ public void testUnrestrictedFileExportDdi() throws IOException { /** * In this test we are restricting a file and testing "export DDI" at the * dataset level as well as getting the DDI at the file level. - *

+ * * Export at the dataset level is always the public version. - *

+ * * At the file level, you can still get summary statistics (and friends, * "dataDscr") if you have access to download the file. If you don't have * access, you get an error. @@ -3408,6 +3408,7 @@ public void testFilesUnchangedAfterDatasetMetadataUpdate() throws IOException { } + @Test public void testCuratePublishedDatasetVersionCommand() throws IOException { Response createUser = UtilIT.createRandomUser(); @@ -3441,6 +3442,8 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { .add("directoryLabel", "code"); + + String pathToFileThatGoesThroughIngest = "src/test/resources/sav/dct.sav"; Response uploadIngestableFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFileThatGoesThroughIngest, apiToken); uploadIngestableFile.then().assertThat() @@ -3453,7 +3456,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { logger.fine("Orig file id: " + origFileId); assertNotNull(origFileId); - assertNotEquals("", origFileId); + assertNotEquals("",origFileId); // Give file time to ingest @@ -3468,7 +3471,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { InputStream variableData = origXml.body().asInputStream(); Map mapVarToVarMet = new HashMap(); - Map varGroupMap = new HashMap(); + Map varGroupMap = new HashMap(); try { XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xmlr = factory.createXMLStreamReader(variableData); @@ -3478,7 +3481,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { } catch (XMLStreamException e) { logger.warning(e.getMessage()); - assertEquals(0, 1); + assertEquals(0,1); } @@ -3488,7 +3491,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { updatedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/xml/dct.xml"))); } catch (IOException e) { logger.warning(e.getMessage()); - assertEquals(0, 1); + assertEquals(0,1); } Long replV1168 = 0L; Long replV1169 = 0L; @@ -3497,20 +3500,20 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { for (VariableMetadata var : mapVarToVarMet.values()) { if (var.getLabel().equals("gender")) { replV1170 = var.getDataVariable().getId(); - numberVariables = numberVariables + 1; + numberVariables = numberVariables +1; } else if (var.getLabel().equals("weight")) { replV1168 = var.getDataVariable().getId(); - numberVariables = numberVariables + 1; + numberVariables = numberVariables +1; } else if (var.getLabel().equals("age_rollup")) { replV1169 = var.getDataVariable().getId(); - numberVariables = numberVariables + 1; + numberVariables = numberVariables +1; } } assertEquals(3, numberVariables); - updatedContent = updatedContent.replaceAll("v1168", "v" + replV1168); - updatedContent = updatedContent.replaceAll("v1169", "v" + replV1169); - updatedContent = updatedContent.replaceAll("v1170", "v" + replV1170); + updatedContent = updatedContent.replaceAll("v1168", "v" + replV1168 ); + updatedContent = updatedContent.replaceAll("v1169", "v" + replV1169 ); + updatedContent = updatedContent.replaceAll("v1170", "v" + replV1170 ); //edit draft vesrsion Response editDDIResponse = UtilIT.editDDI(updatedContent, origFileId, apiToken); @@ -3519,6 +3522,7 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { assertEquals(200, editDDIResponse.getStatusCode()); + UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); @@ -3554,8 +3558,9 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { /** * In this test we are restricting a file and testing that terms of accees * or request access is required - *

+ * * Export at the dataset level is always the public version. + * */ @Test public void testRestrictFileTermsOfUseAndAccess() throws IOException { @@ -3692,7 +3697,7 @@ public void testRestrictFilesWORequestAccess() throws IOException { * In this test we do CRUD of archivalStatus (Note this and other archiving * related tests are part of * https://github.com/harvard-lts/hdc-integration-tests) - *

+ * * This test requires the root dataverse to be published to pass. */ @Test @@ -3930,7 +3935,7 @@ public void getDatasetVersionCitation() { getDatasetVersionCitationNotDeaccessioned.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); // includeDeaccessioned true - Response getDatasetVersionCitationDeaccessioned = UtilIT.getDatasetVersionCitation(datasetId, DS_VERSION_LATEST_PUBLISHED, true, apiToken); + Response getDatasetVersionCitationDeaccessioned = UtilIT.getDatasetVersionCitation(datasetId, DS_VERSION_LATEST_PUBLISHED, true, apiToken); getDatasetVersionCitationDeaccessioned.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.message", containsString("DEACCESSIONED VERSION")); @@ -4701,7 +4706,7 @@ public void testGetGlobusUploadParameters() { for (int i = 0; i < signedUrls.size(); i++) { JsonObject signedUrl = signedUrls.getJsonObject(i); if (signedUrl.getString("name").equals("requestGlobusReferencePaths")) { - found = true; + found=true; break; } } From f2c94b558c9e95ddf053f2d5a871204509a841d6 Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Fri, 19 Apr 2024 18:01:19 -0300 Subject: [PATCH 11/12] 9729: rolling back formatting --- .../harvard/iq/dataverse/api/DatasetsIT.java | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index 0dba20231ec..afd715f8c81 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -343,7 +343,7 @@ public void testAddUpdateDatasetViaNativeAPI() { assertEquals(200, publishDataset.getStatusCode()); //post publish update String pathToJsonFilePostPub= "doc/sphinx-guides/source/_static/api/dataset-add-metadata-after-pub.json"; - Response addDataToPublishedVersion = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFilePostPub, apiToken); + Response addDataToPublishedVersion = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFilePostPub, apiToken); addDataToPublishedVersion.prettyPrint(); addDataToPublishedVersion.then().assertThat().statusCode(OK.getStatusCode()); @@ -358,12 +358,12 @@ public void testAddUpdateDatasetViaNativeAPI() { .body("message", equalToCI("Error parsing dataset update: Invalid value submitted for Subtitle. It should be a single value.")) .statusCode(400); - addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); + addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - String pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-subject-metadata.json"; + String pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-subject-metadata.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() @@ -599,7 +599,7 @@ public void testCreatePublishDestroyDataset() { * are already called from other RestAssured tests, in this class and also in FilesIT. * But this test is dedicated to this api specifically, and focuses on the * functionality added to it in 6.1. - */ + */ @Test public void testDatasetVersionsAPI() { @@ -746,48 +746,48 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Latest published unauthorized token //Latest published requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Latest authorized token //Latest requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files", equalTo(null)); //Latest unauthorized token //Latest requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Specific version authorized token //Specific version requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); //Specific version unauthorized token //Specific version requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files", equalTo(null)); excludeFiles = false; @@ -796,48 +796,48 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Latest published unauthorized token //Latest published requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Latest authorized token, user is authenticated should get the Draft version //Latest requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files.size()", equalTo(2)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files.size()", equalTo(2)); //Latest unauthorized token, user has no permissions should get the latest Published version //Latest requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Specific version authorized token //Specific version requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //Specific version unauthorized token //Specific version requested, draft exists but user doesn't have access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("RELEASED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("RELEASED")) + .body("data.files.size()", equalTo(1)); //We deaccession the dataset Response deaccessionDatasetResponse = UtilIT.deaccessionDataset(datasetId, DS_VERSION_LATEST_PUBLISHED, "Test deaccession reason.", null, apiToken); @@ -852,8 +852,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files.size()", equalTo(1)); //Latest published requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -864,8 +864,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files.size()", equalTo(2)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files.size()", equalTo(2)); //Latest unauthorized token requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -876,8 +876,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files.size()", equalTo(1)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files.size()", equalTo(1)); //Specific version unauthorized token requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets. datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -891,48 +891,48 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Latest published exclude files, should get the DEACCESSIONED version //Latest published requested, that version was deaccessioned but a draft exist but the user doesn't have access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Latest authorized token should get the DRAFT version with no files //Latest requested there is a draft and the user has access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files", equalTo(null)); //Latest unauthorized token excluding files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets //Latest requested and latest version is deaccessioned and the user doesn't have access to the draft. datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Specific version authorized token //Specific version requested (deaccesioned), the latest version is on draft amd the user has access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Specific version unauthorized token requesting files, one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets. //Specific version requested (deaccesioned), the latest version is on draft but the user doesn't have access to it. datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DEACCESSIONED")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DEACCESSIONED")) + .body("data.files", equalTo(null)); //Set of test when we have a deaccessioned dataset but we don't include deaccessioned includeDeaccessioned = false; @@ -953,8 +953,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files.size()", equalTo(2)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files.size()", equalTo(2)); //Latest unauthorized token one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -987,8 +987,8 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(OK.getStatusCode()) - .body("data.versionState", equalTo("DRAFT")) - .body("data.files", equalTo(null)); + .body("data.versionState", equalTo("DRAFT")) + .body("data.files", equalTo(null)); //Latest unauthorized token one version is DEACCESSIONED the second is DRAFT so shouldn't get any datasets datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiTokenNoPerms, excludeFiles, includeDeaccessioned); @@ -1436,7 +1436,7 @@ public void testPrivateUrl() { * authorized to view the draft - and make sure they get the dataset page: * * MAKE SURE TO READ the note below, about jsessions and cookies! - */ + */ Response getDatasetAsUserWhoClicksPrivateUrl = given() .header(API_TOKEN_HTTP_HEADER, apiToken) @@ -1710,11 +1710,11 @@ public void testAddRoles(){ //(String definitionPoint, String role, String roleAssignee, String apiToken) //Can't give yourself permission Response giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, randomUserApiToken); - giveRandoPermission.prettyPrint(); + giveRandoPermission.prettyPrint(); assertEquals(401, giveRandoPermission.getStatusCode()); giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); - giveRandoPermission.prettyPrint(); + giveRandoPermission.prettyPrint(); assertEquals(200, giveRandoPermission.getStatusCode()); //Asserting same role creation is covered @@ -1743,8 +1743,8 @@ public void testAddRoles(){ String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "designatedHitter", "@" + randomUsername, apiToken); - giveRandoPermission.prettyPrint(); - giveRandoPermission.then().assertThat() + giveRandoPermission.prettyPrint(); + giveRandoPermission.then().assertThat() .contentType(ContentType.JSON) .body("message", containsString("Cannot find role named 'designatedHitter' in dataverse ")) .statusCode(400); @@ -2771,7 +2771,7 @@ public void testUpdateDatasetVersionWithFiles() throws InterruptedException { String datasetPersistentId = protocol + ":" + authority + "/" + identifier; System.out.println("datasetPersistentId: " + datasetPersistentId); - String pathToJsonFile = "src/test/resources/json/update-dataset-version-with-files.json"; + String pathToJsonFile = "src/test/resources/json/update-dataset-version-with-files.json"; Response updateMetadataAddFilesViaNative = UtilIT.updateDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, authorApiToken); updateMetadataAddFilesViaNative.prettyPrint(); From 3c755be5ed848d32e531ac1519de233f445393cf Mon Sep 17 00:00:00 2001 From: zearaujo25 Date: Fri, 19 Apr 2024 18:04:50 -0300 Subject: [PATCH 12/12] 9729: rolling back formatting --- .../harvard/iq/dataverse/api/DatasetsIT.java | 566 +++++++++--------- 1 file changed, 283 insertions(+), 283 deletions(-) diff --git a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java index afd715f8c81..7169ca3d526 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java @@ -67,11 +67,11 @@ public class DatasetsIT { private static final Logger logger = Logger.getLogger(DatasetsIT.class.getCanonicalName()); - + @BeforeAll public static void setUpClass() { - - + + RestAssured.baseURI = UtilIT.getRestAssuredBaseUri(); Response removeIdentifierGenerationStyle = UtilIT.deleteSetting(SettingsServiceBean.Key.IdentifierGenerationStyle); @@ -89,7 +89,7 @@ public static void setUpClass() { UtilIT.deleteSetting(SettingsServiceBean.Key.MaxEmbargoDurationInMonths); /* With Dual mode, we can no longer mess with upload methods since native is now required for anything to work - + Response removeDcmUrl = UtilIT.deleteSetting(SettingsServiceBean.Key.DataCaptureModuleUrl); removeDcmUrl.then().assertThat() .statusCode(200); @@ -128,19 +128,19 @@ public static void afterClass() { .statusCode(200); */ } - + @Test public void testCollectionSchema(){ - + Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); - + Response getCollectionSchemaResponse = UtilIT.getCollectionSchema(dataverseAlias, apiToken); getCollectionSchemaResponse.prettyPrint(); getCollectionSchemaResponse.then().assertThat() @@ -153,33 +153,33 @@ public void testCollectionSchema(){ } assertEquals(JsonUtil.prettyPrint(expectedSchema), JsonUtil.prettyPrint(getCollectionSchemaResponse.body().asString())); - + String expectedJson = UtilIT.getDatasetJson("scripts/search/tests/data/dataset-finch1.json"); - + Response validateDatasetJsonResponse = UtilIT.validateDatasetJson(dataverseAlias, expectedJson, apiToken); validateDatasetJsonResponse.prettyPrint(); validateDatasetJsonResponse.then().assertThat() .statusCode(200); - - - String pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; - + + + String pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; + String jsonIn = UtilIT.getDatasetJson(pathToJsonFile); - + Response validateBadDatasetJsonResponse = UtilIT.validateDatasetJson(dataverseAlias, jsonIn, apiToken); validateBadDatasetJsonResponse.prettyPrint(); validateBadDatasetJsonResponse.then().assertThat() .statusCode(200); - + validateBadDatasetJsonResponse.then().assertThat() .statusCode(OK.getStatusCode()) .body(containsString("failed validation")); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); - + } @Test @@ -189,7 +189,7 @@ public void testCreateDataset() { createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); @@ -201,39 +201,39 @@ public void testCreateDataset() { Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken); datasetAsJson.then().assertThat() .statusCode(OK.getStatusCode()); - + String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); assertEquals(10, identifier.length()); Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - - // Now, let's allow anyone with a Dataverse account (any "random user") - // to create datasets in this dataverse: - + + // Now, let's allow anyone with a Dataverse account (any "random user") + // to create datasets in this dataverse: + Response grantRole = UtilIT.grantRoleOnDataverse(dataverseAlias, DataverseRole.DS_CONTRIBUTOR, AuthenticatedUsers.get().getIdentifier(), apiToken); grantRole.prettyPrint(); assertEquals(OK.getStatusCode(), grantRole.getStatusCode()); - - // Create another random user: - + + // Create another random user: + Response createRandomUser = UtilIT.createRandomUser(); createRandomUser.prettyPrint(); String randomUsername = UtilIT.getUsernameFromResponse(createRandomUser); String randomUserApiToken = UtilIT.getApiTokenFromResponse(createRandomUser); - - // This random user should be able to create a dataset in the dataverse + + // This random user should be able to create a dataset in the dataverse // above, because we've set it up so, right? - Not exactly: the dataverse - // hasn't been published yet! So if this random user tries to create - // a dataset now, it should fail: + // hasn't been published yet! So if this random user tries to create + // a dataset now, it should fail: /* - this test removed because the perms for create dataset have been reverted createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, randomUserApiToken); createDatasetResponse.prettyPrint(); assertEquals(UNAUTHORIZED.getStatusCode(), createDatasetResponse.getStatusCode()); */ // Now, let's publish this dataverse... - + Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); assertEquals(OK.getStatusCode(), publishDataverse.getStatusCode()); @@ -244,10 +244,10 @@ public void testCreateDataset() { Thread.sleep(1000l); } catch (InterruptedException iex) {} - // ... And now that it's published, try to create a dataset again, - // as the "random", not specifically authorized user: + // ... And now that it's published, try to create a dataset again, + // as the "random", not specifically authorized user: // (this time around, it should work!) - + createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, randomUserApiToken); createDatasetResponse.prettyPrint(); datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); @@ -257,11 +257,11 @@ public void testCreateDataset() { .statusCode(OK.getStatusCode()); // OK, let's delete this dataset as well, and then delete the dataverse... - + deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); @@ -271,7 +271,7 @@ public void testCreateDataset() { assertEquals(200, deleteUserResponse.getStatusCode()); } - + @Test public void testAddUpdateDatasetViaNativeAPI() { @@ -279,7 +279,7 @@ public void testAddUpdateDatasetViaNativeAPI() { createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); @@ -291,43 +291,43 @@ public void testAddUpdateDatasetViaNativeAPI() { Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken); datasetAsJson.then().assertThat() .statusCode(OK.getStatusCode()); - + String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); - + //Test Add Data - - + + Response getDatasetJsonBeforePublishing = UtilIT.nativeGet(datasetId, apiToken); getDatasetJsonBeforePublishing.prettyPrint(); String protocol = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.protocol"); String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority"); - + String datasetPersistentId = protocol + ":" + authority + "/" + identifier; String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-add-metadata.json"; Response addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); + - - + RestAssured.registerParser("text/plain", Parser.JSON); Response exportDatasetAsJson = UtilIT.exportDataset(datasetPersistentId, "dataverse_json", apiToken); exportDatasetAsJson.prettyPrint(); - + pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-add-subject-metadata.json"; addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()).body(containsString("Mathematical Sciences")); - + String pathToJsonFileSingle = "doc/sphinx-guides/source/_static/api/dataset-simple-update-metadata.json"; Response addSubjectSingleViaNative = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileSingle, apiToken); String responseString = addSubjectSingleViaNative.prettyPrint(); addSubjectSingleViaNative.then().assertThat() .statusCode(OK.getStatusCode()).body(containsString("Mathematical Sciences")).body(containsString("Social Sciences")); - + //Trying to blank out required field should fail... @@ -338,7 +338,7 @@ public void testAddUpdateDatasetViaNativeAPI() { Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); - + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); //post publish update @@ -353,34 +353,34 @@ public void testAddUpdateDatasetViaNativeAPI() { String pathToJsonFileBadDataSubtitle = "doc/sphinx-guides/source/_static/api/dataset-edit-metadata-subtitle.json"; Response addDataToBadData = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileBadDataSubtitle, apiToken); addDataToBadData.prettyPrint(); - + addDataToBadData.then().assertThat() .body("message", equalToCI("Error parsing dataset update: Invalid value submitted for Subtitle. It should be a single value.")) .statusCode(400); - + addSubjectViaNative = UtilIT.addDatasetMetadataViaNative(datasetPersistentId, pathToJsonFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + String pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-subject-metadata.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-author-metadata.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + pathToJsonDeleteFile = "doc/sphinx-guides/source/_static/api/dataset-delete-author-no-match.json"; addSubjectViaNative = UtilIT.deleteDatasetMetadataViaNative(datasetPersistentId, pathToJsonDeleteFile, apiToken); addSubjectViaNative.prettyPrint(); addSubjectViaNative.then().assertThat().body("message", equalTo("Delete metadata failed: Author: Spruce, Sabrina not found.")) .statusCode(400); - + publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); //6078 @@ -388,11 +388,11 @@ public void testAddUpdateDatasetViaNativeAPI() { Response editPublishedVersion = UtilIT.updateFieldLevelDatasetMetadataViaNative(datasetPersistentId, pathToJsonFileEditPostPub, apiToken); editPublishedVersion.prettyPrint(); editPublishedVersion.then().assertThat().statusCode(OK.getStatusCode()); - + publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); //"Delete metadata failed: " + updateField.getDatasetFieldType().getDisplayName() + ": " + displayValue + " not found." } - + @Test public void testAddEmptyDatasetViaNativeAPI() { @@ -400,27 +400,27 @@ public void testAddEmptyDatasetViaNativeAPI() { createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); - String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); - + String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); + String pathToJsonFile = "scripts/search/tests/data/emptyDataset.json"; Response createDatasetResponse = UtilIT.createDatasetViaNativeApi(dataverseAlias, pathToJsonFile, apiToken); createDatasetResponse.prettyPrint(); createDatasetResponse.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()) - .body("message", startsWith("Validation Failed: ")); - - pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; + .body("message", startsWith("Validation Failed: ")); + + pathToJsonFile = "scripts/search/tests/data/datasetMissingReqFields.json"; createDatasetResponse = UtilIT.createDatasetViaNativeApi(dataverseAlias, pathToJsonFile, apiToken); createDatasetResponse.prettyPrint(); - + createDatasetResponse.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()) .body("message", startsWith("Validation Failed: ")); - + } /** @@ -436,7 +436,7 @@ public void testCreatePublishDestroyDataset() { String apiToken = UtilIT.getApiTokenFromResponse(createUser); Response makeSuperUser = UtilIT.makeSuperUser(username); assertEquals(200, makeSuperUser.getStatusCode()); - + Response createNoAccessUser = UtilIT.createRandomUser(); createNoAccessUser.prettyPrint(); String apiTokenNoAccess= UtilIT.getApiTokenFromResponse(createNoAccessUser); @@ -455,11 +455,11 @@ public void testCreatePublishDestroyDataset() { String authority = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.authority"); String identifier = JsonPath.from(getDatasetJsonBeforePublishing.getBody().asString()).getString("data.identifier"); String datasetPersistentId = protocol + ":" + authority + "/" + identifier; - + Response datasetAsJsonNoAccess = UtilIT.nativeGet(datasetId, apiTokenNoAccess); datasetAsJsonNoAccess.then().assertThat() - .statusCode(UNAUTHORIZED.getStatusCode()); - + .statusCode(UNAUTHORIZED.getStatusCode()); + Response publishDataverse = UtilIT.publishDataverseViaSword(dataverseAlias, apiToken); assertEquals(200, publishDataverse.getStatusCode()); Response attemptToPublishZeroDotOne = UtilIT.publishDatasetViaNativeApiDeprecated(datasetPersistentId, "minor", apiToken); @@ -468,7 +468,7 @@ public void testCreatePublishDestroyDataset() { attemptToPublishZeroDotOne.then().assertThat() .body("message", equalTo("Cannot publish as minor version. Re-try as major release.")) .statusCode(403); - + logger.info("Attempting to publish a major version"); // Return random sleep 9/13/2019 // Without it we've seen some DB deadlocks @@ -489,10 +489,10 @@ public void testCreatePublishDestroyDataset() { // FIXME: make this less brittle by removing "2" and "0". See also test below. .body("data.latestVersion.metadataBlocks.citation.fields[2].value[0].datasetContactEmail.value", equalTo("finch@mailinator.com")) .statusCode(OK.getStatusCode()); - + Response datasetAsJsonNoAccessPostPublish = UtilIT.nativeGet(datasetId, apiTokenNoAccess); datasetAsJsonNoAccessPostPublish.then().assertThat() - .statusCode(OK.getStatusCode()); + .statusCode(OK.getStatusCode()); assertTrue(datasetAsJsonNoAccessPostPublish.body().asString().contains(identifier)); List datasetContactsFromNativeGet = with(getDatasetJsonAfterPublishing.body().asString()).param("datasetContact", "datasetContact") @@ -596,13 +596,13 @@ public void testCreatePublishDestroyDataset() { /** * The apis (/api/datasets/{id}/versions and /api/datasets/{id}/versions/{vid} - * are already called from other RestAssured tests, in this class and also in FilesIT. - * But this test is dedicated to this api specifically, and focuses on the - * functionality added to it in 6.1. + * are already called from other RestAssured tests, in this class and also in FilesIT. + * But this test is dedicated to this api specifically, and focuses on the + * functionality added to it in 6.1. */ @Test public void testDatasetVersionsAPI() { - + // Create user String apiToken = UtilIT.createRandomUserGetToken(); @@ -624,16 +624,16 @@ 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()); - + // Check that the file we just uploaded is shown by the versions api: Response unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, ":draft", apiToken); unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() .statusCode(OK.getStatusCode()); - - // Now check that the file is NOT shown, when we ask the versions api to - // skip files: - boolean excludeFiles = true; + + // Now check that the file is NOT shown, when we ask the versions api to + // skip files: + boolean excludeFiles = true; unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_DRAFT, apiToken, excludeFiles, false); unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() @@ -644,8 +644,8 @@ public void testDatasetVersionsAPI() { unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() .statusCode(UNAUTHORIZED.getStatusCode()); - - excludeFiles = false; + + excludeFiles = false; unpublishedDraft = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_DRAFT, apiToken, excludeFiles, false); unpublishedDraft.prettyPrint(); unpublishedDraft.then().assertThat() @@ -662,8 +662,8 @@ public void testDatasetVersionsAPI() { UtilIT.publishDataverseViaNativeApi(collectionAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); - //Set of tests on non-deaccesioned dataset - String specificVersion = "1.0"; + //Set of tests on non-deaccesioned dataset + String specificVersion = "1.0"; boolean includeDeaccessioned = false; Response datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST, apiToken, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); @@ -672,7 +672,7 @@ public void testDatasetVersionsAPI() { .body("data.versionState", equalTo("RELEASED")) .body("data.latestVersionPublishingState", equalTo("RELEASED")); - // Upload another file: + // Upload another file: String pathToFile2 = "src/main/webapp/resources/images/cc0.png"; Response uploadResponse2 = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile2, apiToken); uploadResponse2.prettyPrint(); @@ -691,12 +691,12 @@ public void testDatasetVersionsAPI() { .statusCode(OK.getStatusCode()) .body("data.versionState", equalTo("RELEASED")) .body("data.latestVersionPublishingState", equalTo("DRAFT")); - - // We should now have a published version, and a draft. - - // Call /versions api, *with the owner api token*, make sure both - // versions are listed; also check that the correct numbers of files - // are shown in each version (2 in the draft, 1 in the published). + + // We should now have a published version, and a draft. + + // Call /versions api, *with the owner api token*, make sure both + // 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() @@ -717,16 +717,16 @@ public void testDatasetVersionsAPI() { .body("data.size()", equalTo(1)) .body("data.versionState[0]", equalTo("DRAFT")) .body("data[0].files.size()", equalTo(2)); - - // And now call it with an un-privileged token, to make sure only one - // (the published) version is shown: + + // And now call it with an un-privileged token, to make sure only one + // (the published) version is shown: versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms); versionsResponse.prettyPrint(); versionsResponse.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.versionState[0]", not("DRAFT")) .body("data.size()", equalTo(1)); - + // And now call the "short", no-files version of the same api excludeFiles = true; versionsResponse = UtilIT.getDatasetVersions(datasetPid, apiTokenNoPerms, excludeFiles); @@ -736,10 +736,10 @@ public void testDatasetVersionsAPI() { .body("data[0].files", equalTo(null)); + - - - + + excludeFiles = true; //Latest published authorized token //Latest published requested, draft exists and user has access to draft @@ -790,7 +790,7 @@ public void testDatasetVersionsAPI() { .body("data.files", equalTo(null)); excludeFiles = false; - + //Latest published authorized token //Latest published requested, draft exists and user has access to draft datasetVersion = UtilIT.getDatasetVersion(datasetPid, DS_VERSION_LATEST_PUBLISHED, apiToken, excludeFiles, includeDeaccessioned); @@ -1004,10 +1004,10 @@ public void testDatasetVersionsAPI() { datasetVersion = UtilIT.getDatasetVersion(datasetPid, specificVersion, apiTokenNoPerms, excludeFiles, includeDeaccessioned); datasetVersion.prettyPrint(); datasetVersion.then().assertThat().statusCode(NOT_FOUND.getStatusCode()); - + } - + /** * This test requires the root dataverse to be published to pass. */ @@ -1048,7 +1048,7 @@ public void testExport() { logger.info("In testExport; attempting to publish, as major version"); //Return random sleep 9/13/2019 - // 3 second sleep, to allow the indexing to finish: + // 3 second sleep, to allow the indexing to finish: // Without it we've seen som DB dealocks try { @@ -1266,17 +1266,17 @@ public void testExcludeEmail() { @Test public void testStoredProcGeneratedAsIdentifierGenerationStyle() { // Please note that this test only works if the stored procedure - // named generateIdentifierFromStoredProcedure() has been created in the + // named generateIdentifierFromStoredProcedure() has been created in the // database (see the documentation for the "IdentifierGenerationStyle" option // in the Configuration section of the Installation guide). // Furthermore, the test below expects the identifier generated by the stored - // procedure to be a numeric string. The "sequential numerical values" procedure, - // documented as the first example in the guide above, will satisfy the test. + // procedure to be a numeric string. The "sequential numerical values" procedure, + // documented as the first example in the guide above, will satisfy the test. // If your installation is using a stored procedure that generates the identifiers - // in any other format, the test below will fail. - // (The test is mainly used by the Dataverse Project's automated API test system - // to verify the integrity of this framework for generating the identifiers on the - // database side). + // in any other format, the test below will fail. + // (The test is mainly used by the Dataverse Project's automated API test system + // to verify the integrity of this framework for generating the identifiers on the + // database side). Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); @@ -1302,13 +1302,13 @@ public void testStoredProcGeneratedAsIdentifierGenerationStyle() { logger.info("identifier: " + identifier); String numericPart = identifier.replace("FK2/", ""); //remove shoulder from identifier assertTrue(StringUtils.isNumeric(numericPart)); - //Return random sleep 9/13/2019 + //Return random sleep 9/13/2019 try { Thread.sleep(3000l); } catch (Exception ex) {logger.warning("failed to execute sleep 3 sec.");} - + Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); @@ -1430,14 +1430,14 @@ public void testPrivateUrl() { * asadmin create-jvm-options * "-Ddataverse.siteUrl=http\://localhost\:8080" */ - - /* - * Attempt to follow the private link url; as a user not otherwise + + /* + * Attempt to follow the private link url; as a user not otherwise * authorized to view the draft - and make sure they get the dataset page: - * + * * MAKE SURE TO READ the note below, about jsessions and cookies! */ - + Response getDatasetAsUserWhoClicksPrivateUrl = given() .header(API_TOKEN_HTTP_HEADER, apiToken) .get(urlWithToken); @@ -1446,69 +1446,69 @@ public void testPrivateUrl() { assertEquals(OK.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode()); /* - * NOTE, this is what happens when we attempt to access the dataset via the - * private url, as implemented above: - * - * The private url page authorizes the user to view the dataset - * by issuing a new jsession, and issuing a 302 redirect to the dataset - * page WITH THE JSESSIONID ADDED TO THE URL - as in + * NOTE, this is what happens when we attempt to access the dataset via the + * private url, as implemented above: + * + * The private url page authorizes the user to view the dataset + * by issuing a new jsession, and issuing a 302 redirect to the dataset + * page WITH THE JSESSIONID ADDED TO THE URL - as in * dataset.xhtml?persistentId=xxx&jsessionid=yyy - * RestAssured's .get() method follows redirects by default - so in the - * end the above works and we get the correct dataset. - * But note that this relies on the jsessionid in the url. We've - * experimented with disabling url-supplied jsessions (in PR #5316); - * then the above stopped working - because now jsession is supplied - * AS A COOKIE, which the RestAssured code above does not use, so - * the dataset page refuses to show the dataset to the user. (So the - * assertEquals code above fails, because the page title is not "Darwin's Finches", + * RestAssured's .get() method follows redirects by default - so in the + * end the above works and we get the correct dataset. + * But note that this relies on the jsessionid in the url. We've + * experimented with disabling url-supplied jsessions (in PR #5316); + * then the above stopped working - because now jsession is supplied + * AS A COOKIE, which the RestAssured code above does not use, so + * the dataset page refuses to show the dataset to the user. (So the + * assertEquals code above fails, because the page title is not "Darwin's Finches", * but "Login Page") - * Below is an implementation of the test above that uses the jsession - * cookie, instead of relying on the jsessionid in the URL: - - // This should redirect us to the actual dataset page, and - // give us a valid session cookie: - + * Below is an implementation of the test above that uses the jsession + * cookie, instead of relying on the jsessionid in the URL: + + // This should redirect us to the actual dataset page, and + // give us a valid session cookie: + Response getDatasetAsUserWhoClicksPrivateUrl = given() .header(API_TOKEN_HTTP_HEADER, apiToken) .redirects().follow(false) .get(urlWithToken); - // (note that we have purposefully asked not to follow redirects + // (note that we have purposefully asked not to follow redirects // automatically; this way we can test that we are being redirected // to the right place, that we've been given the session cookie, etc. - + assertEquals(FOUND.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode()); // Yes, javax.ws.rs.core.Response.Status.FOUND is 302! String title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title"); assertEquals("Document moved", title); - + String redirectLink = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.body.a.@href"); assertNotNull(redirectLink); assertTrue(redirectLink.contains("dataset.xhtml")); - + String jsessionid = getDatasetAsUserWhoClicksPrivateUrl.cookie("jsessionid"); assertNotNull(jsessionid); - - // ... and now we can try and access the dataset, with another HTTP GET, + + // ... and now we can try and access the dataset, with another HTTP GET, // sending the jsession cookie along: - - try { + + try { redirectLink = URLDecoder.decode(redirectLink, "UTF-8"); } catch (UnsupportedEncodingException ex) { - // do nothing - try to redirect to the url as is? + // do nothing - try to redirect to the url as is? } - + logger.info("redirecting to "+redirectLink+", using jsession "+jsessionid); - + getDatasetAsUserWhoClicksPrivateUrl = given() .cookies("JSESSIONID", jsessionid) .get(redirectLink); - + assertEquals(OK.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode()); title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title"); assertEquals("Darwin's Finches - " + dataverseAlias, title); - + */ - + Response junkPrivateUrlToken = given() .header(API_TOKEN_HTTP_HEADER, apiToken) .get("/privateurl.xhtml?token=" + "junk"); @@ -1667,15 +1667,15 @@ public void testPrivateUrl() { * @todo Should the Search API work with the Private URL token? */ } - + @Test public void testAddRoles(){ - + Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); String dataverseAlias = UtilIT.getAliasFromResponse(createDataverseResponse); @@ -1687,24 +1687,24 @@ public void testAddRoles(){ Response datasetAsJson = UtilIT.nativeGet(datasetId, apiToken); datasetAsJson.then().assertThat() .statusCode(OK.getStatusCode()); - + String identifier = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); assertEquals(10, identifier.length()); - + String protocol1 = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.protocol"); String authority1 = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.authority"); String identifier1 = JsonPath.from(datasetAsJson.getBody().asString()).getString("data.identifier"); String datasetPersistentId = protocol1 + ":" + authority1 + "/" + identifier1; - - - // Create another random user: - + + + // Create another random user: + Response createRandomUser = UtilIT.createRandomUser(); createRandomUser.prettyPrint(); String randomUsername = UtilIT.getUsernameFromResponse(createRandomUser); String randomUserApiToken = UtilIT.getApiTokenFromResponse(createRandomUser); - + //Give that random user permission //(String definitionPoint, String role, String roleAssignee, String apiToken) @@ -1712,7 +1712,7 @@ public void testAddRoles(){ Response giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, randomUserApiToken); giveRandoPermission.prettyPrint(); assertEquals(401, giveRandoPermission.getStatusCode()); - + giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "fileDownloader", "@" + randomUsername, apiToken); giveRandoPermission.prettyPrint(); assertEquals(200, giveRandoPermission.getStatusCode()); @@ -1739,8 +1739,8 @@ public void testAddRoles(){ giveTooMuchPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "admin", "@" + randomUsername, curatorUserApiToken); giveTooMuchPermission.prettyPrint(); assertEquals(401, giveTooMuchPermission.getStatusCode()); - - String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); + + String idToDelete = JsonPath.from(giveRandoPermission.getBody().asString()).getString("data.id"); giveRandoPermission = UtilIT.grantRoleOnDataset(datasetPersistentId, "designatedHitter", "@" + randomUsername, apiToken); giveRandoPermission.prettyPrint(); @@ -1749,22 +1749,22 @@ public void testAddRoles(){ .body("message", containsString("Cannot find role named 'designatedHitter' in dataverse ")) .statusCode(400); assertEquals(400, giveRandoPermission.getStatusCode()); - + //Try to delete Role with Id saved above //Fails for lack of perms Response deleteGrantedAccess = UtilIT.revokeRoleOnDataset(datasetPersistentId, new Long(idToDelete), randomUserApiToken); deleteGrantedAccess.prettyPrint(); assertEquals(401, deleteGrantedAccess.getStatusCode()); - + //Should be able to delete with proper apiToken deleteGrantedAccess = UtilIT.revokeRoleOnDataset(datasetPersistentId, new Long(idToDelete), apiToken); deleteGrantedAccess.prettyPrint(); assertEquals(200, deleteGrantedAccess.getStatusCode()); - + Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, apiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); @@ -1780,7 +1780,7 @@ public void testAddRoles(){ deleteUserResponse = UtilIT.deleteUser(curatorUsername); deleteUserResponse.prettyPrint(); assertEquals(200, deleteUserResponse.getStatusCode()); - + } @Test @@ -1964,7 +1964,7 @@ public void testDeleteDatasetWhileFileIngesting() { Response uploadIngestableFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFileThatGoesThroughIngest, apiToken); uploadIngestableFile.then().assertThat() .statusCode(OK.getStatusCode()); - + Response deleteDataset = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDataset.prettyPrint(); deleteDataset.then().assertThat() @@ -1972,7 +1972,7 @@ public void testDeleteDatasetWhileFileIngesting() { .statusCode(FORBIDDEN.getStatusCode()); } - + @Test public void testGetDatasetOwners() { @@ -1998,8 +1998,8 @@ public void testGetDatasetOwners() { Response getDatasetWithOwners = UtilIT.getDatasetWithOwners(persistentId, apiToken, true); getDatasetWithOwners.prettyPrint(); - getDatasetWithOwners.then().assertThat().body("data.isPartOf.identifier", equalTo(dataverseAlias)); - + getDatasetWithOwners.then().assertThat().body("data.isPartOf.identifier", equalTo(dataverseAlias)); + Response destroyDatasetResponse = UtilIT.destroyDataset(datasetId, apiToken); assertEquals(200, destroyDatasetResponse.getStatusCode()); @@ -2007,7 +2007,7 @@ public void testGetDatasetOwners() { assertEquals(200, deleteDataverseResponse.getStatusCode()); Response deleteUserResponse = UtilIT.deleteUser(username); - assertEquals(200, deleteUserResponse.getStatusCode()); + assertEquals(200, deleteUserResponse.getStatusCode()); } /** @@ -2119,7 +2119,7 @@ public void testCreateDatasetWithDcmDependency() { if (stopEarlyBecauseYouDoNotHaveDcmInstalled) { return; } - + boolean stopEarlyToVerifyTheScriptWasCreated = false; if (stopEarlyToVerifyTheScriptWasCreated) { logger.info("On the DCM, does /deposit/gen/upload-" + datasetId + ".bash exist? It should! Creating the dataset should be enough to create it."); @@ -2169,14 +2169,14 @@ public void testCreateDatasetWithDcmDependency() { */ @Test public void testDcmChecksumValidationMessages() throws IOException, InterruptedException { - + /*SEK 3/28/2018 This test needs more work Currently it is failing at around line 1114 Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); the CreateDatasetCommand is not getting the rsync script so the dataset is not being created so the whole test is failing */ - + boolean disabled = true; if (disabled) { @@ -2394,14 +2394,14 @@ public void testDcmChecksumValidationMessages() throws IOException, InterruptedE } logger.info("username/password: " + username); } - + @Test public void testCreateDeleteDatasetLink() { Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response superuserResponse = UtilIT.makeSuperUser(username); Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); @@ -2411,8 +2411,8 @@ public void testCreateDeleteDatasetLink() { Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); createDatasetResponse.prettyPrint(); Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); - - // This should fail, because we are attempting to link the dataset + + // This should fail, because we are attempting to link the dataset // to its own dataverse: Response publishTargetDataverse = UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken); publishTargetDataverse.prettyPrint(); @@ -2423,13 +2423,13 @@ public void testCreateDeleteDatasetLink() { publishDatasetForLinking.prettyPrint(); publishDatasetForLinking.then().assertThat() .statusCode(OK.getStatusCode()); - + Response createLinkingDatasetResponse = UtilIT.createDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); createLinkingDatasetResponse.prettyPrint(); createLinkingDatasetResponse.then().assertThat() .body("message", equalTo("Can't link a dataset to its dataverse")) .statusCode(FORBIDDEN.getStatusCode()); - + // OK, let's create a different random dataverse: createDataverseResponse = UtilIT.createRandomDataverse(apiToken); createDataverseResponse.prettyPrint(); @@ -2438,23 +2438,23 @@ public void testCreateDeleteDatasetLink() { publishDatasetForLinking.prettyPrint(); publishTargetDataverse.then().assertThat() .statusCode(OK.getStatusCode()); - + // And link the dataset to this new dataverse: createLinkingDatasetResponse = UtilIT.createDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); createLinkingDatasetResponse.prettyPrint(); createLinkingDatasetResponse.then().assertThat() .body("data.message", equalTo("Dataset " + datasetId +" linked successfully to " + dataverseAlias)) .statusCode(200); - + // And now test deleting it: Response deleteLinkingDatasetResponse = UtilIT.deleteDatasetLink(datasetId.longValue(), dataverseAlias, apiToken); deleteLinkingDatasetResponse.prettyPrint(); - + deleteLinkingDatasetResponse.then().assertThat() .body("data.message", equalTo("Link from Dataset " + datasetId + " to linked Dataverse " + dataverseAlias + " deleted")) .statusCode(200); } - + @Test @Disabled public void testApiErrors() { @@ -2464,7 +2464,7 @@ public void testApiErrors() { This test excerises the issue where the update apis fail when the dataset is out of compliance with the requirement that datasets containing restricted files must allow reuest access or have terms of access. It's impossible to get a dataset into this state via the version 5.11.1 or later so if you needc to - run this test you must set it up manually by setting requestAccess on TermsOfUseAccess to false + run this test you must set it up manually by setting requestAccess on TermsOfUseAccess to false with an update query. Update the decalarations below with values from your test environment */ @@ -2496,7 +2496,7 @@ public void testApiErrors() { Response deleteFile = UtilIT.deleteFile(907, apiToken); deleteFile.prettyPrint(); assertEquals(BAD_REQUEST.getStatusCode(), deleteFile.getStatusCode()); - + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPid, "major", apiToken); publishDataset.prettyPrint(); assertEquals(409, publishDataset.getStatusCode()); @@ -2504,14 +2504,14 @@ public void testApiErrors() { } - + @Test public void testDatasetLocksApi() { Response createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); String username = UtilIT.getUsernameFromResponse(createUser); String apiToken = UtilIT.getApiTokenFromResponse(createUser); - + Response superuserResponse = UtilIT.makeSuperUser(username); Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken); @@ -2522,7 +2522,7 @@ public void testDatasetLocksApi() { createDatasetResponse.prettyPrint(); Integer datasetId = UtilIT.getDatasetIdFromResponse(createDatasetResponse); String persistentIdentifier = UtilIT.getDatasetPersistentIdFromResponse(createDatasetResponse); - + // This should return an empty list, as the dataset should have no locks just yet: Response checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), null, apiToken); checkDatasetLocks.prettyPrint(); @@ -2530,53 +2530,53 @@ public void testDatasetLocksApi() { checkDatasetLocks.then().assertThat() .body("data", equalTo(emptyArray)) .statusCode(200); - - // Lock the dataset with an ingest lock: + + // Lock the dataset with an ingest lock: Response lockDatasetResponse = UtilIT.lockDataset(datasetId.longValue(), "Ingest", apiToken); lockDatasetResponse.prettyPrint(); lockDatasetResponse.then().assertThat() .body("data.message", equalTo("dataset locked with lock type Ingest")) .statusCode(200); - - // Check again: + + // Check again: // This should return an empty list, as the dataset should have no locks just yet: checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken); checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .body("data[0].lockType", equalTo("Ingest")) .statusCode(200); - - // Try to lock the dataset with the same type lock, AGAIN + + // Try to lock the dataset with the same type lock, AGAIN // (this should fail, of course!) lockDatasetResponse = UtilIT.lockDataset(datasetId.longValue(), "Ingest", apiToken); lockDatasetResponse.prettyPrint(); lockDatasetResponse.then().assertThat() .body("message", equalTo("dataset already locked with lock type Ingest")) .statusCode(FORBIDDEN.getStatusCode()); - - // Let's also test the new (as of 5.10) API that lists the locks - // present across all datasets. - - // First, we'll try listing ALL locks currently in the system, and make sure that the ingest lock + + // Let's also test the new (as of 5.10) API that lists the locks + // present across all datasets. + + // First, we'll try listing ALL locks currently in the system, and make sure that the ingest lock // for this dataset is on the list: checkDatasetLocks = UtilIT.listAllLocks(apiToken); checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .statusCode(200); - + boolean lockListedCorrectly = false; List> listedLockEntries = checkDatasetLocks.body().jsonPath().getList("data"); for (int i = 0; i < listedLockEntries.size(); i++) { if ("Ingest".equals(listedLockEntries.get(i).get("lockType")) && username.equals(listedLockEntries.get(i).get("user")) && persistentIdentifier.equals(listedLockEntries.get(i).get("dataset"))) { - lockListedCorrectly = true; + lockListedCorrectly = true; break; - } + } } assertTrue(lockListedCorrectly, "Lock missing from the output of /api/datasets/locks"); - - // Try the same, but with an api token of a random, non-super user + + // Try the same, but with an api token of a random, non-super user // (this should get rejected): createUser = UtilIT.createRandomUser(); createUser.prettyPrint(); @@ -2585,36 +2585,36 @@ public void testDatasetLocksApi() { checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .statusCode(FORBIDDEN.getStatusCode()); - - // Try to narrow the listing down to the lock of type=Ingest specifically; + + // Try to narrow the listing down to the lock of type=Ingest specifically; // verify that the lock in question is still being listed: checkDatasetLocks = UtilIT.listLocksByType("Ingest", apiToken); checkDatasetLocks.prettyPrint(); - // We'll again assume that it's possible that the API is going to list - // *multiple* locks; i.e. that there are other datasets with the lock + // We'll again assume that it's possible that the API is going to list + // *multiple* locks; i.e. that there are other datasets with the lock // of type "Ingest" on them. So we'll go through the list and look for the - // lock for this specific dataset again. + // lock for this specific dataset again. lockListedCorrectly = false; listedLockEntries = checkDatasetLocks.body().jsonPath().getList("data"); for (int i = 0; i < listedLockEntries.size(); i++) { if ("Ingest".equals(listedLockEntries.get(i).get("lockType")) && username.equals(listedLockEntries.get(i).get("user")) && persistentIdentifier.equals(listedLockEntries.get(i).get("dataset"))) { - lockListedCorrectly = true; + lockListedCorrectly = true; break; - } + } } assertTrue(lockListedCorrectly, "Lock missing from the output of /api/datasets/locks?type=Ingest"); - + // Try to list locks of an invalid type: checkDatasetLocks = UtilIT.listLocksByType("BadLockType", apiToken); checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .body("message", startsWith("Invalid lock type value: BadLockType")) .statusCode(BAD_REQUEST.getStatusCode()); - - // List the locks owned by the current user; verify that the lock above + + // List the locks owned by the current user; verify that the lock above // is still listed: checkDatasetLocks = UtilIT.listLocksByUser(username, apiToken); checkDatasetLocks.prettyPrint(); @@ -2624,8 +2624,8 @@ public void testDatasetLocksApi() { .body("data[0].user", equalTo(username)) .body("data[0].dataset", equalTo(persistentIdentifier)) .statusCode(200); - - // Further narrow down the listing to both the type AND user: + + // Further narrow down the listing to both the type AND user: checkDatasetLocks = UtilIT.listLocksByTypeAndUser("Ingest", username, apiToken); checkDatasetLocks.prettyPrint(); // Even safer to assume there should be only one: @@ -2634,25 +2634,25 @@ public void testDatasetLocksApi() { .body("data[0].lockType", equalTo("Ingest")) .body("data[0].user", equalTo(username)) .body("data[0].dataset", equalTo(persistentIdentifier)); - - - // Finally, try asking for the locks owned by this user AND of type "InReview". + + + // Finally, try asking for the locks owned by this user AND of type "InReview". // This should produce an empty list: checkDatasetLocks = UtilIT.listLocksByTypeAndUser("InReview", username, apiToken); checkDatasetLocks.prettyPrint(); checkDatasetLocks.then().assertThat() .statusCode(200) .body("data", equalTo(emptyArray)); - + // And now test deleting the lock: Response unlockDatasetResponse = UtilIT.unlockDataset(datasetId.longValue(), "Ingest", apiToken); unlockDatasetResponse.prettyPrint(); - + unlockDatasetResponse.then().assertThat() .body("data.message", equalTo("lock type Ingest removed")) .statusCode(200); - - // ... and check for the lock on the dataset again, this time by specific lock type: + + // ... and check for the lock on the dataset again, this time by specific lock type: // (should return an empty list, now that we have unlocked it) checkDatasetLocks = UtilIT.checkDatasetLocks(datasetId.longValue(), "Ingest", apiToken); checkDatasetLocks.prettyPrint(); @@ -2660,7 +2660,7 @@ public void testDatasetLocksApi() { .body("data", equalTo(emptyArray)) .statusCode(200); } - + /** * This test requires the root dataverse to be published to pass. */ @@ -2698,7 +2698,7 @@ public void testUpdatePIDMetadataAPI() { try { Thread.sleep(3000l); } catch (InterruptedException iex){} - + Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPersistentId, "major", apiToken); assertEquals(200, publishDataset.getStatusCode()); @@ -2722,7 +2722,7 @@ public void testUpdatePIDMetadataAPI() { logger.info("datasetPersistentId: " + datasetPersistentId); } - + @Test public void testUpdateDatasetVersionWithFiles() throws InterruptedException { Response createCurator = UtilIT.createRandomUser(); @@ -2746,7 +2746,7 @@ public void testUpdateDatasetVersionWithFiles() throws InterruptedException { String authorUsername = UtilIT.getUsernameFromResponse(createAuthor); String authorApiToken = UtilIT.getApiTokenFromResponse(createAuthor); - + Response grantAuthorAddDataset = UtilIT.grantRoleOnDataverse(dataverseAlias, DataverseRole.DS_CONTRIBUTOR.toString(), "@" + authorUsername, curatorApiToken); grantAuthorAddDataset.prettyPrint(); grantAuthorAddDataset.then().assertThat() @@ -2783,7 +2783,7 @@ public void testUpdateDatasetVersionWithFiles() throws InterruptedException { System.out.println("Author username/password: " + authorUsername); } - + @Test public void testLinkingDatasets() { @@ -2856,7 +2856,7 @@ public void testLinkingDatasets() { Integer datasetId2 = UtilIT.getDatasetIdFromResponse(createDataset); String datasetPid2 = JsonPath.from(createDataset.asString()).getString("data.persistentId"); - + linkDataset = UtilIT.linkDataset(datasetPid2, dataverse2Alias, superuserApiToken); linkDataset.prettyPrint(); linkDataset.then().assertThat() @@ -2869,7 +2869,7 @@ public void testLinkingDatasets() { entityManager.getTransaction().commit(); entityManager.close(); - + UtilIT.linkDataset(datasetId2.toString(), dataverse2Alias, superuserApiToken); linkDataset.prettyPrint(); linkDataset.then().assertThat() @@ -2941,7 +2941,7 @@ public void testUnrestrictedFileExportDdi() throws IOException { .body("codeBook.dataDscr.var[1].sumStat.find { it.@type == 'max' }", equalTo("40.0")) .body("codeBook.dataDscr.var[2].@name", equalTo("species")); } - + /** * In this test we are restricting a file and testing "export DDI" at the * dataset level as well as getting the DDI at the file level. @@ -3091,7 +3091,7 @@ public void testSemanticMetadataAPIs() { } catch (NoSuchMethodError e) { logger.info(ExceptionUtils.getStackTrace(e)); } - + String expectedJsonLD = UtilIT.getDatasetJson("scripts/search/tests/data/dataset-finch1.jsonld"); jo = Json.createObjectBuilder(jo).remove("@id").remove("http://schema.org/dateModified").build(); @@ -3135,11 +3135,11 @@ public void testSemanticMetadataAPIs() { response = UtilIT.updateDatasetJsonLDMetadata(datasetId, apiToken, badTerms, false); response.then().assertThat().statusCode(BAD_REQUEST.getStatusCode()); - - //We publish the dataset and dataverse - UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); + + //We publish the dataset and dataverse + UtilIT.publishDataverseViaNativeApi(dataverseAlias, apiToken).then().assertThat().statusCode(OK.getStatusCode()); UtilIT.publishDatasetViaNativeApi(datasetId, "major", apiToken).then().assertThat().statusCode(OK.getStatusCode()); - + //We check the version is published response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiToken); response.prettyPrint(); @@ -3154,14 +3154,14 @@ public void testSemanticMetadataAPIs() { uploadResponse.prettyPrint(); uploadResponse.then().assertThat().statusCode(OK.getStatusCode()); int fileID = uploadResponse.jsonPath().getInt("data.files[0].dataFile.id"); - + //We check the authenticated user gets DRAFT response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiToken); - response.prettyPrint(); + response.prettyPrint(); jsonLDString = getData(response.getBody().asString()); jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString); assertEquals("DRAFT", jsonLDObject.getString("http://schema.org/version")); - + // Create user with no permission and check they get published version String apiTokenNoPerms = UtilIT.createRandomUserGetToken(); response = UtilIT.getDatasetJsonLDMetadata(datasetId, apiTokenNoPerms); @@ -3169,7 +3169,7 @@ public void testSemanticMetadataAPIs() { jsonLDString = getData(response.getBody().asString()); jsonLDObject = JSONLDUtil.decontextualizeJsonLD(jsonLDString); assertNotEquals("DRAFT", jsonLDObject.getString("http://schema.org/version")); - + // Delete the file Response deleteFileResponse = UtilIT.deleteFileInDataset(fileID, apiToken); deleteFileResponse.prettyPrint(); @@ -3214,7 +3214,7 @@ public void testSemanticMetadataAPIs() { assertEquals(200, deleteUserResponse.getStatusCode()); } - + @Test public void testReCreateDataset() { @@ -3239,13 +3239,13 @@ public void testReCreateDataset() { response.then().assertThat().statusCode(OK.getStatusCode()); response.prettyPeek(); String expectedString = getData(response.getBody().asString()); - + // Delete the dataset via native API Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, apiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + logger.info("SENDING to reCreate Dataset: " + expectedString); // Now use the migrate API to recreate the dataset // Now use the migrate API to recreate the dataset @@ -3300,13 +3300,13 @@ public void testCurationLabelAPIs() { Response setCurationLabelSets = UtilIT.setSetting(SettingsServiceBean.Key.AllowedCurationLabels, "{\"StandardProcess\":[\"Author contacted\", \"Privacy Review\", \"Awaiting paper publication\", \"Final Approval\"],\"AlternateProcess\":[\"State 1\",\"State 2\",\"State 3\"]}"); setCurationLabelSets.then().assertThat() .statusCode(OK.getStatusCode()); - - + + //Set curation label set on dataverse //Valid option, bad user Response setDataverseCurationLabelSetResponse = UtilIT.setDataverseCurationLabelSet(dataverseAlias, apiToken, "AlternateProcess"); setDataverseCurationLabelSetResponse.then().assertThat().statusCode(FORBIDDEN.getStatusCode()); - + Response makeSuperUser = UtilIT.makeSuperUser(username); assertEquals(200, makeSuperUser.getStatusCode()); @@ -3317,7 +3317,7 @@ public void testCurationLabelAPIs() { Response setDataverseCurationLabelSetResponse3 = UtilIT.setDataverseCurationLabelSet(dataverseAlias, apiToken, "AlternateProcess"); setDataverseCurationLabelSetResponse3.then().assertThat().statusCode(OK.getStatusCode()); - + // Create a dataset using native api Response createDatasetResponse = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias, apiToken); createDatasetResponse.prettyPrint(); @@ -3329,7 +3329,7 @@ public void testCurationLabelAPIs() { String labelSetName = getData(response.getBody().asString()); // full should be {"message":"AlternateProcess"} assertTrue(labelSetName.contains("AlternateProcess")); - + // Now set a label //Option from the wrong set Response response2 = UtilIT.setDatasetCurationLabel(datasetId, apiToken, "Author contacted"); @@ -3391,24 +3391,24 @@ public void testFilesUnchangedAfterDatasetMetadataUpdate() throws IOException { .statusCode(OK.getStatusCode()) .body("data.latestVersion.files[0].label", equalTo("run.sh")) .body("data.latestVersion.files[0].directoryLabel", equalTo("code")); - + String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-update-metadata.json"; Response updateTitle = UtilIT.updateDatasetMetadataViaNative(datasetPid, pathToJsonFile, apiToken); updateTitle.prettyPrint(); updateTitle.then().assertThat() .statusCode(OK.getStatusCode()); - + Response getDatasetJsonAfterUpdate = UtilIT.nativeGet(datasetId, apiToken); getDatasetJsonAfterUpdate.prettyPrint(); getDatasetJsonAfterUpdate.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.latestVersion.files[0].label", equalTo("run.sh")) .body("data.latestVersion.files[0].directoryLabel", equalTo("code")); - + } - + @Test public void testCuratePublishedDatasetVersionCommand() throws IOException { Response createUser = UtilIT.createRandomUser(); @@ -3417,8 +3417,8 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { .statusCode(OK.getStatusCode()); String apiToken = UtilIT.getApiTokenFromResponse(createUser); String username = UtilIT.getUsernameFromResponse(createUser); - - + + Response createDataverse = UtilIT.createRandomDataverse(apiToken); createDataverse.prettyPrint(); createDataverse.then().assertThat() @@ -3441,8 +3441,8 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { .add("description", "A script to reproduce results.") .add("directoryLabel", "code"); - - + + String pathToFileThatGoesThroughIngest = "src/test/resources/sav/dct.sav"; Response uploadIngestableFile = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFileThatGoesThroughIngest, apiToken); @@ -3459,9 +3459,9 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { assertNotEquals("",origFileId); // Give file time to ingest - + assertTrue(UtilIT.sleepForLock(datasetId.longValue(), "Ingest", apiToken, UtilIT.MAXIMUM_INGEST_LOCK_DURATION), "Failed test if Ingest Lock exceeds max duration " + pathToFileThatGoesThroughIngest); - + Response origXml = UtilIT.getFileMetadata(origFileId, null, apiToken); assertEquals(200, origXml.getStatusCode()); @@ -3531,30 +3531,30 @@ public void testCuratePublishedDatasetVersionCommand() throws IOException { getDatasetJsonBeforeUpdate.then().assertThat() .statusCode(OK.getStatusCode()) .body("data.latestVersion.files[0].label", equalTo("dct.tab")); - + String pathToJsonFile = "doc/sphinx-guides/source/_static/api/dataset-update-metadata.json"; Response updateTitle = UtilIT.updateDatasetMetadataViaNative(datasetPid, pathToJsonFile, apiToken); updateTitle.prettyPrint(); updateTitle.then().assertThat() .statusCode(OK.getStatusCode()); - + // shouldn't be able to update current unless you're a super user UtilIT.publishDatasetViaNativeApi(datasetId, "updatecurrent", apiToken).then().assertThat().statusCode(FORBIDDEN.getStatusCode()); - + Response makeSuperUser = UtilIT.makeSuperUser(username); - + //should work after making super user - + UtilIT.publishDatasetViaNativeApi(datasetId, "updatecurrent", apiToken).then().assertThat().statusCode(OK.getStatusCode()); - + Response getDatasetJsonAfterUpdate = UtilIT.nativeGet(datasetId, apiToken); getDatasetJsonAfterUpdate.prettyPrint(); getDatasetJsonAfterUpdate.then().assertThat() .statusCode(OK.getStatusCode()); - + } - + /** * In this test we are restricting a file and testing that terms of accees * or request access is required @@ -3610,21 +3610,21 @@ public void testRestrictFileTermsOfUseAndAccess() throws IOException { publishDataverse.then().assertThat().statusCode(OK.getStatusCode()); Response publishDataset = UtilIT.publishDatasetViaNativeApi(datasetPid, "major", authorApiToken); publishDataset.then().assertThat().statusCode(OK.getStatusCode()); - - + + //not allowed to remove request access if there are retricted files - + Response disallowRequestAccess = UtilIT.allowAccessRequests(datasetPid, false, authorApiToken); disallowRequestAccess.prettyPrint(); disallowRequestAccess.then().assertThat().statusCode(BAD_REQUEST.getStatusCode()); - + } - + /** * In this test we are removing request access and showing that * files cannot be restricted - * Not testing legacy datasets that are out of compliance - * cannot be published or upload files + * Not testing legacy datasets that are out of compliance + * cannot be published or upload files * or have metadata updated - */ @Test @@ -3648,7 +3648,7 @@ public void testRestrictFilesWORequestAccess() throws IOException { Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset); String datasetPid = JsonPath.from(createDataset.asString()).getString("data.persistentId"); - + //should be allowed to remove Request access before restricting file Response disallowRequestAccess = UtilIT.allowAccessRequests(datasetPid, false, authorApiToken); disallowRequestAccess.prettyPrint(); @@ -3676,13 +3676,13 @@ public void testRestrictFilesWORequestAccess() throws IOException { restrictFile.prettyPrint(); //shouldn't be able to restrict a file restrictFile.then().assertThat().statusCode(CONFLICT.getStatusCode()); - + // OK, let's delete this dataset as well, and then delete the dataverse... - + Response deleteDatasetResponse = UtilIT.deleteDatasetViaNativeApi(datasetId, authorApiToken); deleteDatasetResponse.prettyPrint(); assertEquals(200, deleteDatasetResponse.getStatusCode()); - + Response deleteDataverseResponse = UtilIT.deleteDataverse(dataverseAlias, authorApiToken); deleteDataverseResponse.prettyPrint(); assertEquals(200, deleteDataverseResponse.getStatusCode()); @@ -3754,7 +3754,7 @@ public void testArchivalStatusAPI() throws IOException { addSubjectSingleViaNative.then().assertThat() .statusCode(OK.getStatusCode()); - + // Now change the title // Response response = UtilIT.updateDatasetJsonLDMetadata(datasetId, apiToken, // "{\"title\": \"New Title\", \"@context\":{\"title\": \"http://purl.org/dc/terms/title\"}}", true);