use of edu.harvard.iq.dataverse.engine.command.DataverseRequest 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();
}
};
}
});
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class CreateDataverseCommandTest method testGuestCantCreateDataverse.
@Test(expected = IllegalCommandException.class)
public void testGuestCantCreateDataverse() throws Exception {
final DataverseRequest request = new DataverseRequest(GuestUser.get(), IpAddress.valueOf("::"));
isRootDvExists = false;
engine.submit(new CreateDataverseCommand(makeDataverse(), request, null, null));
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class CreateDataverseCommandTest method testDefaultOptions.
@Test
public void testDefaultOptions() throws CommandException {
Dataverse dv = makeDataverse();
dv.setCreateDate(null);
dv.setId(null);
dv.setCreator(null);
dv.setDefaultContributorRole(null);
dv.setOwner(makeDataverse());
final DataverseRequest request = makeRequest(makeAuthenticatedUser("jk", "rollin'"));
CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, null, null);
Dataverse result = engine.submit(sut);
assertNotNull(result.getCreateDate());
assertNotNull(result.getId());
assertEquals(result.getCreator(), request.getUser());
assertEquals(Dataverse.DataverseType.UNCATEGORIZED, result.getDataverseType());
assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.EDITOR), result.getDefaultContributorRole());
// Assert that the creator is admin.
final RoleAssignment roleAssignment = roles.directRoleAssignments(dv).get(0);
assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.ADMIN), roleAssignment.getRole());
assertEquals(dv, roleAssignment.getDefinitionPoint());
assertEquals(roleAssignment.getAssigneeIdentifier(), request.getUser().getIdentifier());
// The following is a pretty wierd way to test that the create date defaults to
// now, but it works across date changes.
assertTrue("When the supplied creation date is null, date shuld default to command execution time", Math.abs(System.currentTimeMillis() - result.getCreateDate().toInstant().toEpochMilli()) < 1000);
assertTrue(result.isPermissionRoot());
assertTrue(result.isThemeRoot());
assertTrue(indexCalled);
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class CreateRoleCommandTest method testNonSuperUsersCantAddRoles.
@Test(expected = IllegalCommandException.class)
public void testNonSuperUsersCantAddRoles() throws CommandException {
DataverseRole dvr = new DataverseRole();
dvr.setAlias("roleTest");
dvr.setName("Tester Role");
dvr.addPermission(Permission.AddDataset);
Dataverse dv = MocksFactory.makeDataverse();
dvr.setOwner(dv);
AuthenticatedUser normalUser = new AuthenticatedUser();
normalUser.setSuperuser(false);
CreateRoleCommand sut = new CreateRoleCommand(dvr, new DataverseRequest(normalUser, IpAddress.valueOf("89.17.33.33")), dv);
engine.submit(sut);
}
use of edu.harvard.iq.dataverse.engine.command.DataverseRequest in project dataverse by IQSS.
the class CreateRoleCommandTest method testSuperUsersAddRoles.
@Test
public void testSuperUsersAddRoles() throws CommandException {
DataverseRole dvr = new DataverseRole();
dvr.setAlias("roleTest");
dvr.setName("Tester Role");
dvr.addPermission(Permission.AddDataset);
Dataverse dv = MocksFactory.makeDataverse();
dvr.setOwner(dv);
AuthenticatedUser normalUser = new AuthenticatedUser();
normalUser.setSuperuser(true);
CreateRoleCommand sut = new CreateRoleCommand(dvr, new DataverseRequest(normalUser, IpAddress.valueOf("89.17.33.33")), dv);
engine.submit(sut);
assertTrue("CreateRoleCommand did not call save on the created role.", saveCalled);
}
Aggregations