use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName.
@Test
public void testRevokeUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
String exceptionMessage = "";
List<ApiError> apiErrors = new ArrayList<>();
try {
userGroupPermissionService.revokeUserGroupPermission("safeBoxId", userGroupPermission);
} catch (ApiException apiException) {
exceptionMessage = apiException.getMessage();
apiErrors = apiException.getApiErrors();
}
String expectedExceptionMessage = "Unable to revoke permissions for user group name that doesn't exist.";
Assert.assertFalse(apiErrors.isEmpty());
Assert.assertEquals(expectedExceptionMessage, exceptionMessage);
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionWhenGroupRecordIsPresentForGivenName.
@Test
public void testRevokeUserGroupPermissionWhenGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.revokeUserGroupPermission("safeBoxId", userGroupPermission);
Mockito.verify(userGroupDao).deleteUserGroupPermission("safeBoxId", userGroupRecord.get().getId());
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testRevokeUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName.
@Test
public void testRevokeUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
userGroupPermissions.add(userGroupPermission);
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
String exceptionMessage = "";
List<ApiError> apiErrors = new ArrayList<>();
try {
userGroupPermissionService.revokeUserGroupPermissions("safeBoxId", userGroupPermissions);
} catch (ApiException apiException) {
exceptionMessage = apiException.getMessage();
apiErrors = apiException.getApiErrors();
}
String expectedExceptionMessage = "Unable to revoke permissions for user group name that doesn't exist.";
Assert.assertFalse(apiErrors.isEmpty());
Assert.assertEquals(expectedExceptionMessage, exceptionMessage);
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionWhenGroupRecordIsPresentForGivenName.
@Test
public void testUpdateUserGroupPermissionWhenGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.updateUserGroupPermission("safeBoId", userGroupPermission, "user", OffsetDateTime.MAX);
Mockito.verify(userGroupDao).updateUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionsValidator method isValid.
public boolean isValid(Set<UserGroupPermission> userGroupPermissionSet, ConstraintValidatorContext context) {
if (userGroupPermissionSet == null || userGroupPermissionSet.isEmpty()) {
return true;
}
boolean isValid = true;
Set<String> userGroups = new HashSet<>();
for (UserGroupPermission userGroupPermission : userGroupPermissionSet) {
if (userGroups.contains(userGroupPermission.getName())) {
isValid = false;
break;
} else {
userGroups.add(userGroupPermission.getName());
}
}
return isValid;
}
Aggregations