Search in sources :

Example 6 with TestCommandContext

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

the class RestrictFileCommandTest method setUp.

@Before
public void setUp() {
    dataset = makeDataset();
    file = makeDataFile();
    engine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public SettingsServiceBean settings() {
            return new SettingsServiceBean() {

                // override for a public install,
                // assume false
                @Override
                public boolean isTrueForKey(SettingsServiceBean.Key key, boolean defaultValue) {
                    return publicInstall;
                }
            };
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) SettingsServiceBean(edu.harvard.iq.dataverse.settings.SettingsServiceBean) Before(org.junit.Before)

Example 7 with TestCommandContext

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

the class DeletePrivateUrlCommandTest method setUp.

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

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

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

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

                @Override
                public List<RoleAssignment> directRoleAssignments(RoleAssignee roas, DvObject dvo) {
                    RoleAssignment roleAssignment = new RoleAssignment();
                    List<RoleAssignment> list = new ArrayList<>();
                    list.add(roleAssignment);
                    return list;
                }

                @Override
                public void revoke(RoleAssignment ra) {
                // no-op
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) 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) ArrayList(java.util.ArrayList) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Before(org.junit.Before)

Example 8 with TestCommandContext

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

the class MoveDatasetCommandTest method setUp.

@Before
public void setUp() {
    auth = makeAuthenticatedUser("Super", "User");
    auth.setSuperuser(true);
    nobody = makeAuthenticatedUser("Nick", "Nobody");
    nobody.setSuperuser(false);
    root = new Dataverse();
    root.setName("root");
    root.setId(1l);
    root.setPublicationDate(new Timestamp(new Date().getTime()));
    childA = new Dataverse();
    childA.setName("childA");
    childA.setId(2l);
    childA.setPublicationDate(new Timestamp(new Date().getTime()));
    childB = new Dataverse();
    childB.setName("childB");
    childB.setId(3l);
    childB.setPublicationDate(new Timestamp(new Date().getTime()));
    grandchildAA = new Dataverse();
    grandchildAA.setName("grandchildAA");
    grandchildAA.setId(4l);
    grandchildAA.setPublicationDate(new Timestamp(new Date().getTime()));
    childDraft = new Dataverse();
    childDraft.setName("childDraft");
    childDraft.setId(5l);
    grandchildBB = new Dataverse();
    grandchildBB.setName("grandchildBB");
    grandchildBB.setId(6l);
    grandchildBB.setPublicationDate(new Timestamp(new Date().getTime()));
    moved = new Dataset();
    moved.setOwner(root);
    moved.setPublicationDate(new Timestamp(new Date().getTime()));
    moved.setId(1l);
    movedResponses = new Dataset();
    movedResponses.setOwner(root);
    movedResponses.setPublicationDate(new Timestamp(new Date().getTime()));
    movedResponses.setId(2l);
    childA.setOwner(root);
    childB.setOwner(root);
    grandchildAA.setOwner(childA);
    grandchildBB.setOwner(childA);
    childDraft.setOwner(childA);
    gbA = new Guestbook();
    gbA.setId(1l);
    gbB = new Guestbook();
    gbB.setId(2l);
    gbC = new Guestbook();
    gbC.setId(3l);
    moved.setGuestbook(gbA);
    movedResponses.setGuestbook(gbA);
    GuestbookResponse gbResp = new GuestbookResponse();
    gbResp.setGuestbook(gbA);
    gbResp.setDataset(movedResponses);
    List<Guestbook> includeA = new ArrayList();
    includeA.add(gbA);
    includeA.add(gbB);
    grandchildAA.setGuestbooks(includeA);
    List<Guestbook> notIncludeA = new ArrayList();
    notIncludeA.add(gbC);
    notIncludeA.add(gbB);
    childB.setGuestbooks(notIncludeA);
    List<Guestbook> none = new ArrayList();
    root.setGuestbooks(none);
    grandchildBB.setGuestbooks(none);
    grandchildBB.setGuestbookRoot(false);
    childA.setGuestbooks(includeA);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public DataverseServiceBean dataverses() {
            return new DataverseServiceBean() {

                @Override
                public Dataverse save(Dataverse dataverse) {
                    // no-op. The superclass accesses databases which we don't have.
                    return dataverse;
                }
            };
        }

        @Override
        public GuestbookServiceBean guestbooks() {
            return new GuestbookServiceBean() {

                @Override
                public Long findCountResponsesForGivenDataset(Long guestbookId, Long datasetId) {
                    // We're going to fake a response for a dataset with responses
                    if (datasetId == 1) {
                        return new Long(0);
                    } else {
                        return new Long(1);
                    }
                }
            };
        }

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

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

        @Override
        public EntityManager em() {
            return new MockEntityManager() {
            };
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) GuestbookServiceBean(edu.harvard.iq.dataverse.GuestbookServiceBean) GuestbookResponse(edu.harvard.iq.dataverse.GuestbookResponse) Dataset(edu.harvard.iq.dataverse.Dataset) Guestbook(edu.harvard.iq.dataverse.Guestbook) ArrayList(java.util.ArrayList) Dataverse(edu.harvard.iq.dataverse.Dataverse) Timestamp(java.sql.Timestamp) DataverseServiceBean(edu.harvard.iq.dataverse.DataverseServiceBean) Date(java.util.Date) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 9 with TestCommandContext

use of edu.harvard.iq.dataverse.engine.TestCommandContext 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 10 with TestCommandContext

use of edu.harvard.iq.dataverse.engine.TestCommandContext 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)

Aggregations

TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)13 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)12 Before (org.junit.Before)11 Dataset (edu.harvard.iq.dataverse.Dataset)7 DatasetServiceBean (edu.harvard.iq.dataverse.DatasetServiceBean)4 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)4 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)4 DvObject (edu.harvard.iq.dataverse.DvObject)4 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)4 Dataverse (edu.harvard.iq.dataverse.Dataverse)3 DataverseServiceBean (edu.harvard.iq.dataverse.DataverseServiceBean)3 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)3 IndexServiceBean (edu.harvard.iq.dataverse.search.IndexServiceBean)3 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)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 User (edu.harvard.iq.dataverse.authorization.users.User)2