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"));
}
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);
}
}
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());
}
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);
}
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));
}
Aggregations