use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.
the class RoleDaoTest method testRoleCRUD.
@Test
public void testRoleCRUD() {
Role testRole = roleDao.createRole(TEST_ROLE);
assertNotNull(testRole);
assertNotNull(testRole.getId());
assertEquals(TEST_ROLE, testRole.getName());
Role loadedRole = roleDao.loadRole(testRole.getId()).get();
assertEquals(testRole.getName(), loadedRole.getName());
assertEquals(testRole.getId(), loadedRole.getId());
Collection<Role> allRoles = roleDao.loadAllRoles(false);
assertFalse(allRoles.isEmpty());
assertTrue(isRolePresent(testRole, allRoles));
List<Role> rolesByList = roleDao.loadRolesList(Arrays.asList(testRole.getId(), DefaultRoles.ROLE_USER.getId()));
assertEquals(2, rolesByList.size());
assertTrue(isRolePresent(testRole, rolesByList));
assertTrue(isRolePresent(DefaultRoles.ROLE_USER.getRole(), rolesByList));
roleDao.deleteRole(testRole.getId());
assertTrue(!roleDao.loadRole(testRole.getId()).isPresent());
assertTrue(roleDao.loadAllRoles(false).stream().noneMatch(r -> r.equals(testRole)));
}
use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.
the class RoleDaoTest method shouldUpdateStorage.
@Test
public void shouldUpdateStorage() {
Role testRole = roleDao.createRole(TEST_ROLE);
S3bucketDataStorage s3bucketDataStorage = ObjectCreatorUtils.createS3Bucket(null, TEST_STORAGE_PATH, TEST_STORAGE_PATH, TEST_USER1);
dataStorageDao.createDataStorage(s3bucketDataStorage);
testRole.setUserDefault(true);
testRole.setDefaultStorageId(s3bucketDataStorage.getId());
testRole.setName(TEST_ROLE_UPDATED);
roleDao.updateRole(testRole);
Optional<Role> loaded = roleDao.loadRole(testRole.getId());
assertThat(loaded.isPresent(), equalTo(true));
Role role = loaded.get();
assertThat(role.getName(), equalTo(TEST_ROLE_UPDATED));
assertThat(role.getDefaultStorageId(), equalTo(s3bucketDataStorage.getId()));
assertThat(role.isUserDefault(), equalTo(true));
}
use of com.epam.pipeline.entity.user.Role in project cloud-pipeline by epam.
the class RoleManager method deleteRole.
@Transactional(propagation = Propagation.REQUIRED)
public Role deleteRole(Long id) {
Role role = loadRole(id);
Assert.isTrue(!role.isPredefined(), "Predefined system roles cannot be deleted");
permissionManager.deleteGrantedAuthority(role.getName());
roleDao.deleteRoleReferences(id);
roleDao.deleteRole(id);
return role;
}
Aggregations