Skip to content

Commit

Permalink
IQSS#3702 - Added test on null or empty comment for ReturnDatasetToAu…
Browse files Browse the repository at this point in the history
…thorCommand
  • Loading branch information
luddaniel committed Nov 29, 2023
1 parent 36a259f commit 136d42b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ public Response returnToAuthor(@Context ContainerRequestContext crc, @PathParam(
reasonForReturn = json.getString("reasonForReturn");
// TODO: Once we add a box for the curator to type into, pass the reason for return to the ReturnDatasetToAuthorCommand and delete this check and call to setReturnReason on the API side.
if (reasonForReturn == null || reasonForReturn.isEmpty()) {
return error(Response.Status.BAD_REQUEST, "You must enter a reason for returning a dataset to the author(s).");
return error(Response.Status.BAD_REQUEST, BundleUtil.getStringFromBundle("dataset.reject.datasetNotInReview"));
}
AuthenticatedUser authenticatedUser = getRequestAuthenticatedUserOrDie(crc);
Dataset updatedDataset = execCommand(new ReturnDatasetToAuthorCommand(createDataverseRequest(authenticatedUser), dataset, reasonForReturn ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public class ReturnDatasetToAuthorCommand extends AbstractDatasetCommand<Dataset

public ReturnDatasetToAuthorCommand(DataverseRequest aRequest, Dataset anAffectedDvObject, String comment) {
super(aRequest, anAffectedDvObject);

if (comment == null || comment.isEmpty()) {
throw new IllegalArgumentException(BundleUtil.getStringFromBundle("dataset.reject.commentNull"));
}

this.comment = comment;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ dataset.reject.success=This dataset has been sent back to the contributor.
dataset.reject.failure=Dataset Submission Return Failed - {0}
dataset.reject.datasetNull=Cannot return the dataset to the author(s) because it is null.
dataset.reject.datasetNotInReview=This dataset cannot be return to the author(s) because the latest version is not In Review. The author(s) needs to click Submit for Review first.
dataset.reject.commentNull=You must enter a reason for returning a dataset to the author(s).
dataset.publish.tip=Are you sure you want to publish this dataset? Once you do so it must remain published.
dataset.publish.terms.tip=This version of the dataset will be published with the following terms:
dataset.publish.terms.help.tip=To change the terms for this version, click the Cancel button and go to the Terms tab for this dataset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,29 +178,26 @@ public void testNotInReviewDataset() {
assertEquals(expected, actual);
}

/*
FIXME - Empty Comments won't be allowed in future
@Test
public void testEmptyComments(){
dataset.setIdentifier("DUMMY");
public void testEmptyOrNullComment(){
dataset.getLatestVersion().setVersionState(DatasetVersion.VersionState.DRAFT);
dataset.getLatestVersion().setInReview(true);
dataset.getLatestVersion().setReturnReason(null);
Dataset updatedDataset = null;
String expected = "You must enter a reason for returning a dataset to the author(s).";
String actual = null;
Dataset updatedDataset = null;
try {
updatedDataset = testEngine.submit(new ReturnDatasetToAuthorCommand(dataverseRequest, dataset));
} catch (CommandException ex) {
testEngine.submit( new AddLockCommand(dataverseRequest, dataset,
new DatasetLock(DatasetLock.Reason.InReview, dataverseRequest.getAuthenticatedUser())));

assertThrowsExactly(IllegalArgumentException.class,
() -> new ReturnDatasetToAuthorCommand(dataverseRequest, dataset, null), expected);
assertThrowsExactly(IllegalArgumentException.class,
() -> new ReturnDatasetToAuthorCommand(dataverseRequest, dataset, ""), expected);
updatedDataset = testEngine.submit(new ReturnDatasetToAuthorCommand(dataverseRequest, dataset, ""));
} catch (IllegalArgumentException | CommandException ex) {
actual = ex.getMessage();
}
assertEquals(expected, actual);
assertEquals(expected, actual);
}
*/

@Test
public void testAllGood() {
Expand Down

0 comments on commit 136d42b

Please sign in to comment.