use of com.nike.cerberus.domain.UserGroupPermission in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionsWhenUserGroupRecordIsNotPresentForGivenName.
@Test
public void testGrantUserGroupPermissionsWhenUserGroupRecordIsNotPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
userGroupPermissions.add(userGroupPermission);
Role role = Mockito.mock(Role.class);
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
userGroupPermissionService.grantUserGroupPermissions("safeBoxId", userGroupPermissions, "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 testGrantUserGroupPermissionWhenUserGroupRecordIsNotPresentForGivenName.
@Test
public void testGrantUserGroupPermissionWhenUserGroupRecordIsNotPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Role role = Mockito.mock(Role.class);
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(Optional.empty());
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 UserGroupPermissionService method getUserGroupPermissions.
public Set<UserGroupPermission> getUserGroupPermissions(final String safeDepositBoxId) {
final Set<UserGroupPermission> permissionsSet = Sets.newHashSet();
final List<UserGroupPermissionRecord> permissionRecords = userGroupDao.getUserGroupPermissions(safeDepositBoxId);
permissionRecords.forEach(r -> {
final Optional<UserGroupRecord> userGroupRecord = userGroupDao.getUserGroup(r.getUserGroupId());
if (userGroupRecord.isPresent()) {
UserGroupPermission permission = new UserGroupPermission();
permission.setId(r.getId());
permission.setRoleId(r.getRoleId());
permission.setName(userGroupRecord.get().getName());
permission.setCreatedBy(r.getCreatedBy());
permission.setCreatedTs(r.getCreatedTs());
permission.setLastUpdatedBy(r.getLastUpdatedBy());
permission.setLastUpdatedTs(r.getLastUpdatedTs());
permissionsSet.add(permission);
}
});
return permissionsSet;
}
Aggregations