use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.
the class ExplicitGroupTest method addGroup.
@Test
public void addGroup() throws GroupException {
Dataverse dvParent = makeDataverse();
Dataverse dvSub = makeDataverse();
dvSub.setOwner(dvParent);
ExplicitGroup g1 = new ExplicitGroup(prv);
ExplicitGroup g2 = new ExplicitGroup(prv);
g1.setOwner(dvSub);
g2.setOwner(dvParent);
g1.add(g2);
assertTrue(g1.structuralContains(g2));
}
use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.
the class MocksFactory method makeDataverse.
public static Dataverse makeDataverse() {
Dataverse retVal = new Dataverse();
retVal.setId(nextId());
retVal.setAffiliation("Unit Test U");
retVal.setAlias("unitTest" + retVal.getId());
retVal.setCreateDate(timestamp(2012, 4, 5));
retVal.setMetadataBlockRoot(true);
retVal.setName("UnitTest Dataverse #" + retVal.getId());
MetadataBlock mtb = new MetadataBlock();
mtb.setDisplayName("Test Block #1-" + retVal.getId());
mtb.setId(nextId());
mtb.setDatasetFieldTypes(Arrays.asList(new DatasetFieldType("JustAString", DatasetFieldType.FieldType.TEXT, false), new DatasetFieldType("ManyStrings", DatasetFieldType.FieldType.TEXT, true), new DatasetFieldType("AnEmail", DatasetFieldType.FieldType.EMAIL, false)));
retVal.setMetadataBlocks(Arrays.asList(mtb));
return retVal;
}
use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.
the class StorageIOTest method testGetDvObject.
@Test
public void testGetDvObject() {
assertEquals(null, instance.getDvObject());
instance.setDvObject(new Dataset());
assertEquals(new Dataset(), instance.getDataset());
try {
instance.getDataFile();
fail("This should have thrown");
} catch (ClassCastException ex) {
assertEquals(ex.getMessage(), "edu.harvard.iq.dataverse.Dataset cannot be cast to edu.harvard.iq.dataverse.DataFile");
}
try {
instance.getDataverse();
fail("This should have thrown");
} catch (ClassCastException ex) {
assertEquals(ex.getMessage(), "edu.harvard.iq.dataverse.Dataset cannot be cast to edu.harvard.iq.dataverse.Dataverse");
}
assertEquals(new DataFile(), new FileAccessIO<>(new DataFile()).getDataFile());
assertEquals(new Dataverse(), new FileAccessIO<>(new Dataverse()).getDataverse());
}
use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.
the class CreateDataverseCommandTest method testCantCreateAnotherWithSameAlias.
@Test(expected = IllegalCommandException.class)
public void testCantCreateAnotherWithSameAlias() throws Exception {
String alias = "alias";
final Dataverse dvFirst = makeDataverse();
dvFirst.setAlias(alias);
dvFirst.setOwner(makeDataverse());
engine.submit(new CreateDataverseCommand(dvFirst, makeRequest(), null, null));
final Dataverse dv = makeDataverse();
dv.setOwner(makeDataverse());
dv.setAlias(alias);
engine.submit(new CreateDataverseCommand(dv, makeRequest(), null, null));
}
use of edu.harvard.iq.dataverse.Dataverse in project dataverse by IQSS.
the class CreateDataverseCommandTest method testDefaultOptions.
@Test
public void testDefaultOptions() throws CommandException {
Dataverse dv = makeDataverse();
dv.setCreateDate(null);
dv.setId(null);
dv.setCreator(null);
dv.setDefaultContributorRole(null);
dv.setOwner(makeDataverse());
final DataverseRequest request = makeRequest(makeAuthenticatedUser("jk", "rollin'"));
CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, null, null);
Dataverse result = engine.submit(sut);
assertNotNull(result.getCreateDate());
assertNotNull(result.getId());
assertEquals(result.getCreator(), request.getUser());
assertEquals(Dataverse.DataverseType.UNCATEGORIZED, result.getDataverseType());
assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.EDITOR), result.getDefaultContributorRole());
// Assert that the creator is admin.
final RoleAssignment roleAssignment = roles.directRoleAssignments(dv).get(0);
assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.ADMIN), roleAssignment.getRole());
assertEquals(dv, roleAssignment.getDefinitionPoint());
assertEquals(roleAssignment.getAssigneeIdentifier(), request.getUser().getIdentifier());
// The following is a pretty wierd way to test that the create date defaults to
// now, but it works across date changes.
assertTrue("When the supplied creation date is null, date shuld default to command execution time", Math.abs(System.currentTimeMillis() - result.getCreateDate().toInstant().toEpochMilli()) < 1000);
assertTrue(result.isPermissionRoot());
assertTrue(result.isThemeRoot());
assertTrue(indexCalled);
}
Aggregations