use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentDatasetNull.
@Test
public void testGetPrivateUrlFromRoleAssignmentDatasetNull() {
String dataverseSiteUrl = "https://dataverse.example.edu";
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = null;
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
assertNull(privateUrl);
}
use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetDatasetFromRoleAssignmentSuccess.
@Test
public void testGetDatasetFromRoleAssignmentSuccess() {
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = new Dataset();
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
assertNotNull(PrivateUrlUtil.getDatasetFromRoleAssignment(ra));
assertEquals("#42", ra.getAssigneeIdentifier());
}
use of edu.harvard.iq.dataverse.DvObject 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
}
};
}
});
}
use of edu.harvard.iq.dataverse.DvObject 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());
}
use of edu.harvard.iq.dataverse.DvObject 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();
}
};
}
});
}
Aggregations