Search in sources :

Example 71 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDraftUrlNoGlobalId.

@Test
public void testGetDraftUrlNoGlobalId() throws Exception {
    DatasetVersion draft = new DatasetVersion();
    Dataset dataset = new Dataset();
    draft.setDataset(dataset);
    assertEquals("UNKNOWN", PrivateUrlUtil.getDraftUrl(draft));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 72 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class GetLatestPublishedDatasetVersionCommandTest method make10Versions.

private List<DatasetVersion> make10Versions(Dataset ds) {
    // setup: make 10 versions.
    List<DatasetVersion> versions = new ArrayList<>(10);
    for (int i = 10; i > 0; i--) {
        DatasetVersion v = MocksFactory.makeDatasetVersion(ds.getCategories());
        v.setVersionNumber((long) i);
        v.setMinorVersionNumber(0l);
        v.setReleaseTime(MocksFactory.date(1990, i, 1));
        v.setVersionState(DatasetVersion.VersionState.RELEASED);
        versions.add(v);
    }
    return versions;
}
Also used : ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion)

Example 73 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class DatasetUtilTest method testGetThumbnailNullDataset.

@Test
public void testGetThumbnailNullDataset() {
    assertNull(DatasetUtil.getThumbnail(null));
    assertNull(DatasetUtil.getThumbnail(null, null));
    Dataset dataset = MocksFactory.makeDataset();
    dataset.setStorageIdentifier("file://");
    dataset.setUseGenericThumbnail(true);
    assertNull(DatasetUtil.getThumbnail(dataset));
    assertNull(DatasetUtil.getThumbnail(dataset, new DatasetVersion()));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 74 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class CreateDatasetVersionCommandTest method testSimpleVersionAddition.

@Test
public void testSimpleVersionAddition() throws Exception {
    SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
    // Create Dataset
    Dataset ds = makeDataset();
    // Populate the Initial version
    DatasetVersion dsvInitial = ds.getEditVersion();
    dsvInitial.setCreateTime(dateFmt.parse("20001012"));
    dsvInitial.setLastUpdateTime(dsvInitial.getLastUpdateTime());
    dsvInitial.setId(MocksFactory.nextId());
    dsvInitial.setReleaseTime(dateFmt.parse("20010101"));
    dsvInitial.setVersionState(DatasetVersion.VersionState.RELEASED);
    dsvInitial.setMinorVersionNumber(0l);
    dsvInitial.setVersionNumber(1l);
    // Create version to be added
    DatasetVersion dsvNew = new DatasetVersion();
    dsvNew.setVersionState(DatasetVersion.VersionState.DRAFT);
    // Execute
    CreateDatasetVersionCommand sut = new CreateDatasetVersionCommand(makeRequest(), ds, dsvNew);
    final MockDatasetServiceBean serviceBean = new MockDatasetServiceBean();
    TestDataverseEngine testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public DatasetServiceBean datasets() {
            return serviceBean;
        }
    });
    testEngine.submit(sut);
    // asserts
    assertTrue(serviceBean.storeVersionCalled);
    Date dsvCreationDate = dsvNew.getCreateTime();
    assertEquals(dsvCreationDate, dsvNew.getLastUpdateTime());
    assertEquals(dsvCreationDate.getTime(), ds.getModificationTime().getTime());
    assertEquals(ds, dsvNew.getDataset());
    assertEquals(dsvNew, ds.getEditVersion());
    Map<DvObject, Set<Permission>> expected = new HashMap<>();
    expected.put(ds, Collections.singleton(Permission.AddDataset));
    assertEquals(expected, testEngine.getReqiredPermissionsForObjects());
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) Set(java.util.Set) DvObject(edu.harvard.iq.dataverse.DvObject) HashMap(java.util.HashMap) Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Date(java.util.Date) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 75 with DatasetVersion

use of edu.harvard.iq.dataverse.DatasetVersion in project dataverse by IQSS.

the class CreateDatasetVersionCommandTest method testCantCreateTwoDraftVersions.

@Test(expected = IllegalCommandException.class)
public void testCantCreateTwoDraftVersions() throws Exception {
    DatasetVersion dsvNew = new DatasetVersion();
    dsvNew.setVersionState(DatasetVersion.VersionState.DRAFT);
    // Execute
    CreateDatasetVersionCommand sut = new CreateDatasetVersionCommand(makeRequest(), makeDataset(), dsvNew);
    TestDataverseEngine testEngine = new TestDataverseEngine(new TestCommandContext());
    testEngine.submit(sut);
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) Test(org.junit.Test)

Aggregations

DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)85 Dataset (edu.harvard.iq.dataverse.Dataset)43 Test (org.junit.Test)36 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)25 ArrayList (java.util.ArrayList)24 DataFile (edu.harvard.iq.dataverse.DataFile)19 JsonObject (javax.json.JsonObject)15 Date (java.util.Date)13 StringReader (java.io.StringReader)11 IOException (java.io.IOException)10 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)9 Timestamp (java.sql.Timestamp)9 EJBException (javax.ejb.EJBException)9 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)8 JsonObjectBuilder (javax.json.JsonObjectBuilder)8 JsonReader (javax.json.JsonReader)8 DatasetField (edu.harvard.iq.dataverse.DatasetField)7 Dataverse (edu.harvard.iq.dataverse.Dataverse)7 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)7 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)7