Skip to content

Commit

Permalink
A simple test for the new collection attributes api; added comments i…
Browse files Browse the repository at this point in the history
…n the Dataverse class. #8889
  • Loading branch information
landreev committed May 31, 2023
1 parent 0704ae2 commit e337871
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/Dataverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,26 @@ public void setCitationDatasetFieldTypes(List<DatasetFieldType> citationDatasetF
this.citationDatasetFieldTypes = citationDatasetFieldTypes;
}

/**
* @Note: this setting is Nullable, with {@code null} indicating that the
* desired behavior is not explicitly configured for this specific collection.
* See the comment below.
*/
@Column(nullable = true)
private Boolean filePIDsEnabled;

/**
* Specifies whether the PIDs for Datafiles should be registered when publishing
* datasets in this Collection, if the behavior is explicitly configured.
* @return {@code Boolean.TRUE} if explicitly enabled, {@code Boolean.FALSE} if explicitly disabled.
* {@code null} indicates that the behavior is not explicitly defined, in which
* case the behavior should follow the explicit configuration of the first
* direct ancestor collection, or the instance-wide configuration, if none
* present.
* @Note: If present, this configuration therefore by default applies to all
* the sub-collections, unless explicitly overwritten there.
* @author landreev
*/
public Boolean getFilePIDsEnabled() {
return filePIDsEnabled;
}
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DataversesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,47 @@ public void testImportDDI() throws IOException, InterruptedException {
assertEquals(200, deleteUserResponse.getStatusCode());
}

@Test
public void testAttributesApi() throws Exception {

Response createUser = UtilIT.createRandomUser();
String apiToken = UtilIT.getApiTokenFromResponse(createUser);

Response createDataverseResponse = UtilIT.createRandomDataverse(apiToken);
if (createDataverseResponse.getStatusCode() != 201) {
System.out.println("A workspace for testing (a dataverse) couldn't be created in the root dataverse. The output was:\n\n" + createDataverseResponse.body().asString());
System.out.println("\nPlease ensure that users can created dataverses in the root in order for this test to run.");
} else {
createDataverseResponse.prettyPrint();
}
assertEquals(201, createDataverseResponse.getStatusCode());

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();

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));

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

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

}

0 comments on commit e337871

Please sign in to comment.