Search in sources :

Example 1 with TestDataverseEngine

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

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

the class UpdateDatasetThumbnailCommandTest method setUp.

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

        @Override
        public DataFileServiceBean files() {
            return new DataFileServiceBean() {

                @Override
                public DataFile find(Object object) {
                    if (object == unfindableFile) {
                        return null;
                    } else if (object == thumbnailUnexpectedlyAbsent) {
                        return new DataFile();
                    } else {
                        return null;
                    }
                }
            };
        }

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

                @Override
                public Dataset setDatasetFileAsThumbnail(Dataset dataset, DataFile datasetFileThumbnailToSwitchTo) {
                    return dataset;
                }
            };
        }

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

                @Override
                public String getDataverseSiteUrl() {
                    return "https://dataverse.example.edu";
                }
            };
        }
    });
}
Also used : DataFile(edu.harvard.iq.dataverse.DataFile) SystemConfig(edu.harvard.iq.dataverse.util.SystemConfig) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) DataFileServiceBean(edu.harvard.iq.dataverse.DataFileServiceBean) Dataset(edu.harvard.iq.dataverse.Dataset) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) Before(org.junit.Before)

Example 3 with TestDataverseEngine

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

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

the class CreateDataverseCommandTest method setUp.

@Before
public void setUp() {
    indexCalled = false;
    dvStore.clear();
    dvByAliasStore.clear();
    isRootDvExists = true;
    facetsDeleted = false;
    createdDftils = new ArrayList<>();
    createdFacets = new ArrayList<>();
    engine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public IndexServiceBean index() {
            return index;
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return roles;
        }

        @Override
        public DataverseServiceBean dataverses() {
            return dataverses;
        }

        @Override
        public DataverseFacetServiceBean facets() {
            return facets;
        }

        @Override
        public DataverseFieldTypeInputLevelServiceBean fieldTypeInputLevels() {
            return dfils;
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) Before(org.junit.Before)

Example 5 with TestDataverseEngine

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

the class MoveDataverseCommandTest method setUp.

@Before
public void setUp() {
    root = new Dataverse();
    root.setName("root");
    root.setId(1l);
    childA = new Dataverse();
    childA.setName("childA");
    childA.setId(2l);
    childB = new Dataverse();
    childB.setName("childB");
    childB.setId(3l);
    grandchildAA = new Dataverse();
    grandchildAA.setName("grandchildAA");
    grandchildAA.setId(4l);
    childA.setOwner(root);
    childB.setOwner(root);
    grandchildAA.setOwner(childA);
    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;
                }
            };
        }
    });
}
Also used : TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseServiceBean(edu.harvard.iq.dataverse.DataverseServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) 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