Skip to content

Commit

Permalink
Added: IT cases for testAttributesApi
Browse files Browse the repository at this point in the history
  • Loading branch information
GPortas committed Oct 23, 2024
1 parent 45cab75 commit e98ae05
Showing 1 changed file with 57 additions and 18 deletions.
75 changes: 57 additions & 18 deletions src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -819,10 +819,9 @@ public void testImport() throws IOException, InterruptedException {
Response deleteUserResponse = UtilIT.deleteUser(username);
assertEquals(200, deleteUserResponse.getStatusCode());
}

@Test
public void testAttributesApi() throws Exception {

@Test
public void testAttributesApi() {
Response createUser = UtilIT.createRandomUser();
String apiToken = UtilIT.getApiTokenFromResponse(createUser);

Expand All @@ -837,30 +836,70 @@ public void testAttributesApi() throws Exception {

String collectionAlias = UtilIT.getAliasFromResponse(createDataverseResponse);
String newCollectionAlias = collectionAlias + "RENAMED";

// Change the alias of the collection:

Response changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "alias", newCollectionAlias, apiToken);
changeAttributeResp.prettyPrint();


// Change the name of the collection:

String newCollectionName = "Renamed Name";
Response changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "name", newCollectionName, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));

// Check on the collection, under the new alias:


// Change the description of the collection:

String newDescription = "Renamed Description";
changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "description", newDescription, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));

// Change the affiliation of the collection:

String newAffiliation = "Renamed Affiliation";
changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "affiliation", newAffiliation, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));

// Cannot update filePIDsEnabled from a regular user:

changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "filePIDsEnabled", "true", apiToken);
changeAttributeResp.then().assertThat()
.statusCode(UNAUTHORIZED.getStatusCode());

// Change the alias of the collection:

changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "alias", newCollectionAlias, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(OK.getStatusCode())
.body("message.message", equalTo("Update successful"));

// Check on the collection, under the new alias:

Response collectionInfoResponse = UtilIT.exportDataverse(newCollectionAlias, apiToken);
collectionInfoResponse.prettyPrint();

collectionInfoResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.alias", equalTo(newCollectionAlias));

.body("data.alias", equalTo(newCollectionAlias))
.body("data.name", equalTo(newCollectionName))
.body("data.description", equalTo(newDescription))
.body("data.affiliation", equalTo(newAffiliation));

// Delete the collection (again, using its new alias):

Response deleteCollectionResponse = UtilIT.deleteDataverse(newCollectionAlias, apiToken);
deleteCollectionResponse.prettyPrint();
assertEquals(OK.getStatusCode(), deleteCollectionResponse.getStatusCode());

// Cannot update root collection from a regular user:

changeAttributeResp = UtilIT.setCollectionAttribute("root", "name", newCollectionName, apiToken);
changeAttributeResp.then().assertThat()
.statusCode(UNAUTHORIZED.getStatusCode());

collectionInfoResponse = UtilIT.exportDataverse("root", apiToken);

collectionInfoResponse.then().assertThat()
.statusCode(OK.getStatusCode())
.body("data.name", equalTo("Root"));
}

@Test
Expand Down

0 comments on commit e98ae05

Please sign in to comment.