Search in sources :

Example 11 with TestDataverseEngine

use of edu.harvard.iq.dataverse.engine.TestDataverseEngine in project dataverse by IQSS.

the class RequestRsyncScriptCommandTest method setUp.

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

        @Override
        public DataCaptureModuleServiceBean dataCaptureModule() {
            return new DataCaptureModuleServiceBean() {

                @Override
                public UploadRequestResponse requestRsyncScriptCreation(String jsonString, String dcmBaseUrl) {
                    return new UploadRequestResponse(200, "myResponse");
                }

                @Override
                public ScriptRequestResponse retreiveRequestedRsyncScript(String datasetIdentifier, String dcmBaseUrl) {
                    int httpStatusCode = 200;
                    long userId = 123l;
                    String script = "theScript";
                    ScriptRequestResponse scriptRequestResponse = new ScriptRequestResponse(httpStatusCode, datasetIdentifier, userId, script);
                    return scriptRequestResponse;
                }
            };
        }

        @Override
        public SettingsServiceBean settings() {
            return new MockSettingsSvc();
        }
    });
}
Also used : ScriptRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.ScriptRequestResponse) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) UploadRequestResponse(edu.harvard.iq.dataverse.datacapturemodule.UploadRequestResponse) DataCaptureModuleServiceBean(edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) Before(org.junit.Before)

Example 12 with TestDataverseEngine

use of edu.harvard.iq.dataverse.engine.TestDataverseEngine in project dataverse by IQSS.

the class CreateDatasetVersionCommandTest method testSimpleVersionAddition.

@Test
public void testSimpleVersionAddition() throws Exception {
    SimpleDateFormat dateFmt = new SimpleDateFormat("yyyyMMdd");
    // Create Dataset
    Dataset ds = makeDataset();
    // Populate the Initial version
    DatasetVersion dsvInitial = ds.getEditVersion();
    dsvInitial.setCreateTime(dateFmt.parse("20001012"));
    dsvInitial.setLastUpdateTime(dsvInitial.getLastUpdateTime());
    dsvInitial.setId(MocksFactory.nextId());
    dsvInitial.setReleaseTime(dateFmt.parse("20010101"));
    dsvInitial.setVersionState(DatasetVersion.VersionState.RELEASED);
    dsvInitial.setMinorVersionNumber(0l);
    dsvInitial.setVersionNumber(1l);
    // Create version to be added
    DatasetVersion dsvNew = new DatasetVersion();
    dsvNew.setVersionState(DatasetVersion.VersionState.DRAFT);
    // Execute
    CreateDatasetVersionCommand sut = new CreateDatasetVersionCommand(makeRequest(), ds, dsvNew);
    final MockDatasetServiceBean serviceBean = new MockDatasetServiceBean();
    TestDataverseEngine testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public DatasetServiceBean datasets() {
            return serviceBean;
        }
    });
    testEngine.submit(sut);
    // asserts
    assertTrue(serviceBean.storeVersionCalled);
    Date dsvCreationDate = dsvNew.getCreateTime();
    assertEquals(dsvCreationDate, dsvNew.getLastUpdateTime());
    assertEquals(dsvCreationDate.getTime(), ds.getModificationTime().getTime());
    assertEquals(ds, dsvNew.getDataset());
    assertEquals(dsvNew, ds.getEditVersion());
    Map<DvObject, Set<Permission>> expected = new HashMap<>();
    expected.put(ds, Collections.singleton(Permission.AddDataset));
    assertEquals(expected, testEngine.getReqiredPermissionsForObjects());
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) Set(java.util.Set) DvObject(edu.harvard.iq.dataverse.DvObject) HashMap(java.util.HashMap) Dataset(edu.harvard.iq.dataverse.Dataset) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) Date(java.util.Date) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 13 with TestDataverseEngine

use of edu.harvard.iq.dataverse.engine.TestDataverseEngine in project dataverse by IQSS.

the class CreateDatasetVersionCommandTest method testCantCreateTwoDraftVersions.

@Test(expected = IllegalCommandException.class)
public void testCantCreateTwoDraftVersions() throws Exception {
    DatasetVersion dsvNew = new DatasetVersion();
    dsvNew.setVersionState(DatasetVersion.VersionState.DRAFT);
    // Execute
    CreateDatasetVersionCommand sut = new CreateDatasetVersionCommand(makeRequest(), makeDataset(), dsvNew);
    TestDataverseEngine testEngine = new TestDataverseEngine(new TestCommandContext());
    testEngine.submit(sut);
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) Test(org.junit.Test)

Example 14 with TestDataverseEngine

use of edu.harvard.iq.dataverse.engine.TestDataverseEngine in project dataverse by IQSS.

the class SubmitDatasetForReviewCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    HttpServletRequest aHttpServletRequest = null;
    dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public AuthenticationServiceBean authentication() {
            return new AuthenticationServiceBean() {

                @Override
                public AuthenticatedUser getAuthenticatedUser(String id) {
                    return MocksFactory.makeAuthenticatedUser("First", "Last");
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new TestEntityManager() {

                @Override
                public <T> T merge(T entity) {
                    return entity;
                }

                @Override
                public void flush() {
                // nothing to do here
                }
            };
        }

        @Override
        public DatasetServiceBean datasets() {
            return new DatasetServiceBean() {

                {
                    em = new NoOpTestEntityManager();
                }

                @Override
                public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
                    return null;
                }

                @Override
                public DatasetLock addDatasetLock(Long datasetId, DatasetLock.Reason reason, Long userId, String info) {
                    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 PermissionServiceBean permissions() {
            return new PermissionServiceBean() {

                @Override
                public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
                    // We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
                    return Collections.emptyList();
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) TestEntityManager(edu.harvard.iq.dataverse.engine.TestEntityManager) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) Permission(edu.harvard.iq.dataverse.authorization.Permission) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Aggregations

TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)14 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)12 Before (org.junit.Before)10 Dataset (edu.harvard.iq.dataverse.Dataset)7 DatasetServiceBean (edu.harvard.iq.dataverse.DatasetServiceBean)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)4 Dataverse (edu.harvard.iq.dataverse.Dataverse)4 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)4 DvObject (edu.harvard.iq.dataverse.DvObject)4 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)4 Test (org.junit.Test)4 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)3 IndexServiceBean (edu.harvard.iq.dataverse.search.IndexServiceBean)3 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)2 DataverseServiceBean (edu.harvard.iq.dataverse.DataverseServiceBean)2 PermissionServiceBean (edu.harvard.iq.dataverse.PermissionServiceBean)2 AuthenticationServiceBean (edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean)2 Permission (edu.harvard.iq.dataverse.authorization.Permission)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)2