Search in sources :

Example 1 with Dataverse

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));
}
Also used : Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 2 with Dataverse

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;
}
Also used : MetadataBlock(edu.harvard.iq.dataverse.MetadataBlock) Dataverse(edu.harvard.iq.dataverse.Dataverse) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType)

Example 3 with Dataverse

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());
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) Dataset(edu.harvard.iq.dataverse.Dataset) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 4 with Dataverse

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));
}
Also used : Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Example 5 with Dataverse

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);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) Dataverse(edu.harvard.iq.dataverse.Dataverse) Test(org.junit.Test)

Aggregations

Dataverse (edu.harvard.iq.dataverse.Dataverse)94 Dataset (edu.harvard.iq.dataverse.Dataset)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)31 Test (org.junit.Test)27 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)22 DataFile (edu.harvard.iq.dataverse.DataFile)18 IOException (java.io.IOException)18 Path (javax.ws.rs.Path)16 JsonObject (javax.json.JsonObject)15 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)11 ArrayList (java.util.ArrayList)11 EJBException (javax.ejb.EJBException)11 JsonObjectBuilder (javax.json.JsonObjectBuilder)11 InputStream (java.io.InputStream)10 Date (java.util.Date)10 JsonArrayBuilder (javax.json.JsonArrayBuilder)10 POST (javax.ws.rs.POST)10 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 SwordError (org.swordapp.server.SwordError)9