use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser 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.authorization.users.PrivateUrlUser 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.authorization.users.PrivateUrlUser in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlRedirectDataSuccess.
@Test
public void testGetPrivateUrlRedirectDataSuccess() {
DataverseRole aRole = null;
long datasetId = 42;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
RoleAssignee anAssignee = privateUrlUser;
Dataset dataset = new Dataset();
dataset.setProtocol("doi");
dataset.setAuthority("10.5072/FK2");
dataset.setIdentifier("3L33T");
dataset.setId(datasetId);
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrlRedirectData privateUrlRedirectData = PrivateUrlUtil.getPrivateUrlRedirectData(ra);
assertNotNull(privateUrlRedirectData);
assertEquals("/dataset.xhtml?persistentId=doi:10.5072/FK2/3L33T&version=DRAFT", privateUrlRedirectData.getDraftDatasetPageToBeRedirectedTo());
assertEquals(privateUrlUser.getIdentifier(), privateUrlRedirectData.getPrivateUrlUser().getIdentifier());
}
use of edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser 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.authorization.users.PrivateUrlUser in project dataverse by IQSS.
the class CreatePrivateUrlCommandTest method testCreatePrivateUrlSuccessfully.
@Test
public void testCreatePrivateUrlSuccessfully() throws CommandException {
dataset = new Dataset();
dataset.setId(createDatasetLong);
PrivateUrl privateUrl = testEngine.submit(new CreatePrivateUrlCommand(null, dataset));
assertNotNull(privateUrl);
assertNotNull(privateUrl.getDataset());
assertNotNull(privateUrl.getRoleAssignment());
PrivateUrlUser expectedUser = new PrivateUrlUser(dataset.getId());
assertEquals(expectedUser.getIdentifier(), privateUrl.getRoleAssignment().getAssigneeIdentifier());
assertEquals(expectedUser.isSuperuser(), false);
assertEquals(expectedUser.isAuthenticated(), false);
assertEquals(expectedUser.getDisplayInfo().getTitle(), "Private URL Enabled");
assertNotNull(privateUrl.getToken());
assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=" + privateUrl.getToken(), privateUrl.getLink());
}
Aggregations