Search in sources :

Example 66 with DatasetVersion

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

the class BriefJsonPrinterTest method testJson_DatasetVersion.

/**
 * Test of json method, of class BriefJsonPrinter.
 */
@Test
public void testJson_DatasetVersion() {
    Dataset ds = MocksFactory.makeDataset();
    DatasetVersion dsv = MocksFactory.makeDatasetVersion(ds.getCategories());
    dsv.setId(1L);
    dsv.setVersion(2l);
    dsv.setVersionState(DatasetVersion.VersionState.DEACCESSIONED);
    DatasetField titleFld = new DatasetField();
    titleFld.setDatasetFieldType(new DatasetFieldType(DatasetFieldConstant.title, DatasetFieldType.FieldType.TEXT, false));
    titleFld.setSingleValue("Dataset Title");
    dsv.setDatasetFields(Collections.singletonList(titleFld));
    BriefJsonPrinter sut = new BriefJsonPrinter();
    JsonObject res = sut.json(dsv).build();
    assertEquals("Dataset Title", res.getString("title"));
    assertEquals(DatasetVersion.VersionState.DEACCESSIONED.name(), res.getString("versionState"));
    assertEquals(1, res.getInt("id"));
}
Also used : DatasetField(edu.harvard.iq.dataverse.DatasetField) Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) JsonObject(javax.json.JsonObject) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) Test(org.junit.Test)

Example 67 with DatasetVersion

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

the class JsonParserTest method testParseOvercompleteDatasetVersion.

/**
 * Expect an exception when the dataset version JSON contains fields
 * that the {@link DatasetFieldService} doesn't know about.
 * @throws JsonParseException as expected
 * @throws IOException when test file IO goes wrong - this is bad.
 */
@Test(expected = JsonParseException.class)
public void testParseOvercompleteDatasetVersion() throws JsonParseException, IOException {
    JsonObject dsJson;
    try (InputStream jsonFile = ClassLoader.getSystemResourceAsStream("json/complete-dataset-version.json")) {
        InputStreamReader reader = new InputStreamReader(jsonFile, "UTF-8");
        dsJson = Json.createReader(reader).readObject();
        System.out.println(dsJson != null);
        DatasetVersion actual = sut.parseDatasetVersion(dsJson);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonObject(javax.json.JsonObject) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 68 with DatasetVersion

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

the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentSuccess.

@Test
public void testGetDraftDatasetVersionFromRoleAssignmentSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    List<DatasetVersion> versions = new ArrayList<>();
    DatasetVersion datasetVersionIn = new DatasetVersion();
    datasetVersionIn.setVersionState(DatasetVersion.VersionState.DRAFT);
    versions.add(datasetVersionIn);
    dataset.setVersions(versions);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    DatasetVersion datasetVersionOut = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
    assertNotNull(datasetVersionOut);
    assertEquals("#42", ra.getAssigneeIdentifier());
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 69 with DatasetVersion

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

the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentLastestIsNotDraft.

@Test
public void testGetDraftDatasetVersionFromRoleAssignmentLastestIsNotDraft() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    List<DatasetVersion> versions = new ArrayList<>();
    DatasetVersion datasetVersionIn = new DatasetVersion();
    datasetVersionIn.setVersionState(DatasetVersion.VersionState.RELEASED);
    versions.add(datasetVersionIn);
    dataset.setVersions(versions);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    DatasetVersion datasetVersionOut = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
    assertNull(datasetVersionOut);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 70 with DatasetVersion

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

the class PrivateUrlUtilTest method testGetDraftUrlDatasetNull.

@Test
public void testGetDraftUrlDatasetNull() {
    DatasetVersion draft = new DatasetVersion();
    draft.setDataset(null);
    assertEquals("UNKNOWN", PrivateUrlUtil.getDraftUrl(draft));
}
Also used : DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) 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