Search in sources :

Example 41 with Dataset

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

the class JsonParserTest method testParseEmptyDataset.

/**
 * Expect an exception when the dataset JSON is empty.
 * @throws JsonParseException when the test is broken
 */
@Test(expected = NullPointerException.class)
public void testParseEmptyDataset() throws JsonParseException {
    JsonObject dsJson;
    try (InputStream jsonFile = ClassLoader.getSystemResourceAsStream("json/empty-dataset.json")) {
        InputStreamReader reader = new InputStreamReader(jsonFile, "UTF-8");
        dsJson = Json.createReader(reader).readObject();
        System.out.println(dsJson != null);
        Dataset actual = sut.parseDataset(dsJson);
        assertEquals("10.5072/FK2", actual.getAuthority());
        assertEquals("/", actual.getDoiSeparator());
        assertEquals("doi", actual.getProtocol());
    } catch (IOException ioe) {
        throw new JsonParseException("Couldn't read test file", ioe);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Dataset(edu.harvard.iq.dataverse.Dataset) JsonObject(javax.json.JsonObject) IOException(java.io.IOException) Test(org.junit.Test)

Example 42 with Dataset

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

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser() {
    DataverseRole aRole = null;
    RoleAssignee assignee = GuestUser.get();
    DvObject dataset = new Dataset();
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 43 with Dataset

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

the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentSuccess.

@Test
public void testGetPrivateUrlFromRoleAssignmentSuccess() {
    String dataverseSiteUrl = "https://dataverse.example.edu";
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject dataset = new Dataset();
    dataset.setId(42l);
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
    assertNotNull(privateUrl);
    assertEquals(new Long(42), privateUrl.getDataset().getId());
    assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=cd71e9d7-73a7-4ec8-b890-3d00499e8693", privateUrl.getLink());
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 44 with Dataset

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

the class PrivateUrlUtilTest method testGetDraftUrlSuccess.

@Test
public void testGetDraftUrlSuccess() throws Exception {
    DatasetVersion draft = new DatasetVersion();
    Dataset dataset = new Dataset();
    dataset.setProtocol("doi");
    dataset.setAuthority("10.5072/FK2");
    dataset.setIdentifier("3L33T");
    draft.setDataset(dataset);
    assertEquals("/dataset.xhtml?persistentId=doi:10.5072/FK2/3L33T&version=DRAFT", PrivateUrlUtil.getDraftUrl(draft));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 45 with Dataset

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

the class PrivateUrlUtilTest method testGetPrivateUrlRedirectDataFail.

@Test
public void testGetPrivateUrlRedirectDataFail() {
    DataverseRole aRole = null;
    long datasetId = 42;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    ra.setDefinitionPoint(null);
    PrivateUrlRedirectData privateUrlRedirectData = null;
    privateUrlRedirectData = PrivateUrlUtil.getPrivateUrlRedirectData(ra);
    assertNull(privateUrlRedirectData);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Aggregations

Dataset (edu.harvard.iq.dataverse.Dataset)142 Test (org.junit.Test)53 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)44 DataFile (edu.harvard.iq.dataverse.DataFile)41 Dataverse (edu.harvard.iq.dataverse.Dataverse)34 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)27 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)23 IOException (java.io.IOException)22 ArrayList (java.util.ArrayList)22 Path (javax.ws.rs.Path)22 FileMetadata (edu.harvard.iq.dataverse.FileMetadata)17 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)17 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)16 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)16 Date (java.util.Date)16 JsonObjectBuilder (javax.json.JsonObjectBuilder)16 JsonObject (javax.json.JsonObject)15 DvObject (edu.harvard.iq.dataverse.DvObject)14 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)14 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)14