use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionWhenUserGroupRecordIsPresentForGivenName.
@Test
public void testGrantUserGroupPermissionWhenUserGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Role role = Mockito.mock(Role.class);
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.grantUserGroupPermission("safeBoxId", userGroupPermission, "user", OffsetDateTime.MAX);
Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName.
@Test
public void testUpdateUserGroupPermissionWhenGroupRecordIsNotPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
String exceptionMessage = "";
List<ApiError> apiErrors = new ArrayList<>();
try {
userGroupPermissionService.updateUserGroupPermission("safeBoId", userGroupPermission, "user", OffsetDateTime.MAX);
} catch (ApiException apiException) {
apiErrors = apiException.getApiErrors();
exceptionMessage = apiException.getMessage();
}
String expectedExceptionMessage = "Unable to update 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 mockUserGroupPermissionWithNameAndRoleId.
private UserGroupPermission mockUserGroupPermissionWithNameAndRoleId(String name, String roleId) {
UserGroupPermission userGroupPermission = Mockito.mock(UserGroupPermission.class);
Mockito.when(userGroupPermission.getName()).thenReturn(name);
Mockito.when(userGroupPermission.getRoleId()).thenReturn(roleId);
return userGroupPermission;
}
use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionsWhenGroupRecordIsPresentForGivenName.
@Test
public void testUpdateUserGroupPermissionsWhenGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
userGroupPermissions.add(userGroupPermission);
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.updateUserGroupPermissions("safeBoId", userGroupPermissions, "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 UserGroupPermissionServiceTest method testUpdateUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName.
@Test
public void testUpdateUserGroupPermissionsWhenGroupRecordIsNotPresentForGivenName() {
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.updateUserGroupPermissions("safeBoId", userGroupPermissions, "user", OffsetDateTime.MAX);
} catch (ApiException apiException) {
apiErrors = apiException.getApiErrors();
exceptionMessage = apiException.getMessage();
}
String expectedExceptionMessage = "Unable to update permissions for user group name that doesn't exist.";
Assert.assertFalse(apiErrors.isEmpty());
Assert.assertEquals(expectedExceptionMessage, exceptionMessage);
}
Aggregations