use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetDraftDatasetVersionFromRoleAssignmentNullDataset.
@Test
public void testGetDraftDatasetVersionFromRoleAssignmentNullDataset() {
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);
DatasetVersion datasetVersion = PrivateUrlUtil.getDraftDatasetVersionFromRoleAssignment(ra);
assertNull(datasetVersion);
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlFromRoleAssignmentSuccess.
@Test
public void testGetPrivateUrlFromRoleAssignmentSuccess() {
String dataverseSiteUrl = "https://dataverse.example.edu";
DataverseRole aRole = null;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUser;
DvObject dataset = new Dataset();
dataset.setId(42l);
String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
PrivateUrl privateUrl = PrivateUrlUtil.getPrivateUrlFromRoleAssignment(ra, dataverseSiteUrl);
assertNotNull(privateUrl);
assertEquals(new Long(42), privateUrl.getDataset().getId());
assertEquals("https://dataverse.example.edu/privateurl.xhtml?token=cd71e9d7-73a7-4ec8-b890-3d00499e8693", privateUrl.getLink());
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetUserFromRoleAssignmentNonDataset.
@Test
public void testGetUserFromRoleAssignmentNonDataset() {
DataverseRole aRole = null;
PrivateUrlUser privateUrlUserIn = new PrivateUrlUser(42);
RoleAssignee anAssignee = privateUrlUserIn;
DvObject nonDataset = new Dataverse();
nonDataset.setId(123l);
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, nonDataset, privateUrlToken);
PrivateUrlUser privateUrlUserOut = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(ra);
assertNull(privateUrlUserOut);
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testGetPrivateUrlRedirectDataFail.
@Test
public void testGetPrivateUrlRedirectDataFail() {
DataverseRole aRole = null;
long datasetId = 42;
PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
RoleAssignee anAssignee = privateUrlUser;
Dataset dataset = new Dataset();
String privateUrlToken = null;
RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
ra.setDefinitionPoint(null);
PrivateUrlRedirectData privateUrlRedirectData = null;
privateUrlRedirectData = PrivateUrlUtil.getPrivateUrlRedirectData(ra);
assertNull(privateUrlRedirectData);
}
use of edu.harvard.iq.dataverse.authorization.RoleAssignee in project dataverse by IQSS.
the class PrivateUrlUtilTest method testIdentifier2roleAssignee.
@Test
public void testIdentifier2roleAssignee() {
RoleAssignee returnValueFromEmptyString = null;
try {
returnValueFromEmptyString = PrivateUrlUtil.identifier2roleAssignee("");
} catch (Exception ex) {
assertEquals(ex.getClass(), IllegalArgumentException.class);
assertEquals(ex.getMessage(), "Could not find dataset id in ''");
}
assertNull(returnValueFromEmptyString);
RoleAssignee returnValueFromNonColon = null;
String peteIdentifier = "@pete";
try {
returnValueFromNonColon = PrivateUrlUtil.identifier2roleAssignee(peteIdentifier);
} catch (Exception ex) {
assertEquals(ex.getClass(), IllegalArgumentException.class);
assertEquals(ex.getMessage(), "Could not find dataset id in '" + peteIdentifier + "'");
}
assertNull(returnValueFromNonColon);
RoleAssignee returnValueFromNonNumber = null;
String nonNumberIdentifier = PrivateUrlUser.PREFIX + "nonNumber";
try {
returnValueFromNonNumber = PrivateUrlUtil.identifier2roleAssignee(nonNumberIdentifier);
} catch (Exception ex) {
assertEquals(ex.getClass(), IllegalArgumentException.class);
assertEquals(ex.getMessage(), "Could not find dataset id in '" + nonNumberIdentifier + "'");
}
assertNull(returnValueFromNonNumber);
RoleAssignee returnFromValidIdentifier = null;
String validIdentifier = PrivateUrlUser.PREFIX + 42;
returnFromValidIdentifier = PrivateUrlUtil.identifier2roleAssignee(validIdentifier);
assertNotNull(returnFromValidIdentifier);
assertEquals("#42", returnFromValidIdentifier.getIdentifier());
assertEquals("Private URL Enabled", returnFromValidIdentifier.getDisplayInfo().getTitle());
Assert.assertTrue(returnFromValidIdentifier instanceof PrivateUrlUser);
PrivateUrlUser privateUrlUser42 = (PrivateUrlUser) returnFromValidIdentifier;
assertEquals(42, privateUrlUser42.getDatasetId());
}
Aggregations