Search in sources :

Example 11 with Dataset

use of edu.harvard.iq.dataverse.Dataset 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 12 with Dataset

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

the class DatasetUtilTest method testGetThumbnailCandidates.

/**
 * Test of getThumbnailCandidates method, of class DatasetUtil.
 */
@Test
public void testGetThumbnailCandidates() {
    assertEquals(new ArrayList<>(), DatasetUtil.getThumbnailCandidates(null, false));
    Dataset dataset = MocksFactory.makeDataset();
    DataFile dataFile = MocksFactory.makeDataFile();
    dataFile.setContentType("image/");
    dataFile.setOwner(dataset);
    dataFile.setStorageIdentifier("file://src/test/resources/images/coffeeshop.png");
    System.out.println(ImageThumbConverter.isThumbnailAvailable(dataFile));
    DatasetVersion version = dataset.getCreateVersion();
    List<FileMetadata> fmds = new ArrayList<>();
    fmds.add(MocksFactory.addFileMetadata(dataFile));
    version.setFileMetadatas(fmds);
    assertEquals(new ArrayList<>(), DatasetUtil.getThumbnailCandidates(dataset, false));
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) Dataset(edu.harvard.iq.dataverse.Dataset) FileMetadata(edu.harvard.iq.dataverse.FileMetadata) ArrayList(java.util.ArrayList) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Test(org.junit.Test)

Example 13 with Dataset

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

the class DatasetUtilTest method testIsDatasetLogoPresent.

/**
 * Test of isDatasetLogoPresent method, of class DatasetUtil.
 */
@Test
public void testIsDatasetLogoPresent() {
    Dataset dataset = MocksFactory.makeDataset();
    assertEquals(false, DatasetUtil.isDatasetLogoPresent(dataset));
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) Test(org.junit.Test)

Example 14 with Dataset

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

the class CreatePrivateUrlCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public PrivateUrlServiceBean privateUrl() {
            return new PrivateUrlServiceBean() {

                @Override
                public PrivateUrl getPrivateUrlFromDatasetId(long datasetId) {
                    if (datasetId == privateUrlAlreadyExists) {
                        Dataset dataset = new Dataset();
                        dataset.setId(privateUrlAlreadyExists);
                        String token = null;
                        PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
                        RoleAssignment roleAssignment = new RoleAssignment(null, privateUrlUser, dataset, token);
                        return new PrivateUrl(roleAssignment, dataset, "FIXME");
                    } else if (datasetId == latestVersionIsNotDraft) {
                        return null;
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public SystemConfig systemConfig() {
            return new SystemConfig() {

                @Override
                public String getDataverseSiteUrl() {
                    return "https://dataverse.example.edu";
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) SystemConfig(edu.harvard.iq.dataverse.util.SystemConfig) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Before(org.junit.Before)

Example 15 with Dataset

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

the class DataCaptureModuleUtilTest method testGenerateJsonForUploadRequest.

@Test
public void testGenerateJsonForUploadRequest() {
    System.out.println("generateJsonForUploadRequest");
    AuthenticatedUser user = makeAuthenticatedUser("Ralph", "Rsync");
    Dataset dataset = new Dataset();
    dataset.setIdentifier("42");
    JsonObject result = DataCaptureModuleUtil.generateJsonForUploadRequest(user, dataset);
    assertEquals("42", result.getString("datasetIdentifier"));
    int userId = result.getInt("userId");
    assertTrue(Integer.MIN_VALUE <= userId && userId <= Integer.MAX_VALUE);
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) JsonObject(javax.json.JsonObject) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) MocksFactory.makeAuthenticatedUser(edu.harvard.iq.dataverse.mocks.MocksFactory.makeAuthenticatedUser) 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