Search in sources :

Example 71 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method testAllGood.

/*
    FIXME - Empty Comments won't be allowed in future
    @Test
    public void testEmptyComments(){
               
        dataset.setIdentifier("DUMMY");
        dataset.getLatestVersion().setVersionState(DatasetVersion.VersionState.DRAFT);
        dataset.getLatestVersion().setInReview(true);
        dataset.getLatestVersion().setReturnReason(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) {
            actual = ex.getMessage();
        }
        assertEquals(expected, actual);      
        
        
    }
     */
@Test
public void testAllGood() {
    dataset.getLatestVersion().setVersionState(DatasetVersion.VersionState.DRAFT);
    Dataset updatedDataset = null;
    try {
        testEngine.submit(new AddLockCommand(dataverseRequest, dataset, new DatasetLock(DatasetLock.Reason.InReview, dataverseRequest.getAuthenticatedUser())));
        updatedDataset = testEngine.submit(new ReturnDatasetToAuthorCommand(dataverseRequest, dataset, "Update Your Files, Dummy"));
    } catch (CommandException ex) {
        System.out.println("Error updating dataset: " + ex.getMessage());
    }
    assertNotNull(updatedDataset);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetLock(edu.harvard.iq.dataverse.DatasetLock) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 72 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method testReleasedDataset.

@Test
public void testReleasedDataset() {
    dataset.getLatestVersion().setVersionState(DatasetVersion.VersionState.RELEASED);
    // dataset.getLatestVersion().setInReview(true);
    String expected = "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.";
    String actual = null;
    Dataset updatedDataset = null;
    try {
        updatedDataset = testEngine.submit(new ReturnDatasetToAuthorCommand(dataverseRequest, dataset, ""));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 73 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method testNotInReviewDataset.

@Test
public void testNotInReviewDataset() {
    dataset.getLatestVersion().setVersionState(DatasetVersion.VersionState.DRAFT);
    // dataset.getLatestVersion().setInReview(false);
    String expected = "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.";
    String actual = null;
    Dataset updatedDataset = null;
    try {
        updatedDataset = testEngine.submit(new ReturnDatasetToAuthorCommand(dataverseRequest, dataset, ""));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 74 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class UpdateDatasetThumbnailCommandTest method testIntentNull.

@Test
public void testIntentNull() {
    String expected = "No changes to save.";
    String actual = null;
    DatasetThumbnail datasetThumbnail = null;
    try {
        datasetThumbnail = testEngine.submit(new UpdateDatasetThumbnailCommand(null, dataset, null, Long.MIN_VALUE, null));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(datasetThumbnail);
}
Also used : DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Example 75 with CommandException

use of edu.harvard.iq.dataverse.engine.command.exception.CommandException in project dataverse by IQSS.

the class UpdateDatasetThumbnailCommandTest method testSetDatasetFileAsThumbnailFileNotFound.

@Test
public void testSetDatasetFileAsThumbnailFileNotFound() {
    String expected = "Could not find file based on id supplied: 1.";
    String actual = null;
    DatasetThumbnail datasetThumbnail = null;
    try {
        datasetThumbnail = testEngine.submit(new UpdateDatasetThumbnailCommand(null, dataset, UpdateDatasetThumbnailCommand.UserIntent.setDatasetFileAsThumbnail, unfindableFile, null));
    } catch (CommandException ex) {
        actual = ex.getMessage();
    }
    assertEquals(expected, actual);
    assertNull(datasetThumbnail);
}
Also used : DatasetThumbnail(edu.harvard.iq.dataverse.dataset.DatasetThumbnail) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) Test(org.junit.Test)

Aggregations

CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)86 Dataset (edu.harvard.iq.dataverse.Dataset)21 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)20 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)19 Test (org.junit.Test)16 PermissionException (edu.harvard.iq.dataverse.engine.command.exception.PermissionException)15 EJBException (javax.ejb.EJBException)13 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)12 DataFile (edu.harvard.iq.dataverse.DataFile)11 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 UpdateDatasetCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetCommand)9 ConstraintViolation (javax.validation.ConstraintViolation)9 DatasetThumbnail (edu.harvard.iq.dataverse.dataset.DatasetThumbnail)8 IOException (java.io.IOException)8 Timestamp (java.sql.Timestamp)8 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 FacesMessage (javax.faces.application.FacesMessage)7 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 SwordError (org.swordapp.server.SwordError)6