Search in sources :

Example 1 with IndexServiceBean

use of edu.harvard.iq.dataverse.search.IndexServiceBean in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest 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 NoOpTestEntityManager();
        }

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

                {
                    em = new NoOpTestEntityManager();
                }

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

                @Override
                public WorkflowComment addWorkflowComment(WorkflowComment comment) {
                    return comment;
                }

                @Override
                public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
                }
            };
        }

        @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) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) 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)

Example 2 with IndexServiceBean

use of edu.harvard.iq.dataverse.search.IndexServiceBean 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 3 with IndexServiceBean

use of edu.harvard.iq.dataverse.search.IndexServiceBean 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

Dataset (edu.harvard.iq.dataverse.Dataset)3 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)3 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)3 IndexServiceBean (edu.harvard.iq.dataverse.search.IndexServiceBean)3 Before (org.junit.Before)3 DatasetServiceBean (edu.harvard.iq.dataverse.DatasetServiceBean)2 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)2 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)2 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)2 DvObject (edu.harvard.iq.dataverse.DvObject)2 PermissionServiceBean (edu.harvard.iq.dataverse.PermissionServiceBean)2 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)2 AuthenticationServiceBean (edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean)2 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)2 Permission (edu.harvard.iq.dataverse.authorization.Permission)2 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 NoOpTestEntityManager (edu.harvard.iq.dataverse.engine.NoOpTestEntityManager)2 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2