Search in sources :

Example 6 with Role

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)));
}
Also used : ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Role(com.epam.pipeline.entity.user.Role) Arrays(java.util.Arrays) DataStorageDao(com.epam.pipeline.dao.datastorage.DataStorageDao) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Collection(java.util.Collection) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) CollectionUtils(org.apache.commons.collections4.CollectionUtils) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) ObjectCreatorUtils(com.epam.pipeline.manager.ObjectCreatorUtils) Optional(java.util.Optional) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) Assert(org.junit.Assert) Role(com.epam.pipeline.entity.user.Role) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 7 with Role

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));
}
Also used : ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Role(com.epam.pipeline.entity.user.Role) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest)

Example 8 with Role

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;
}
Also used : ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Role(com.epam.pipeline.entity.user.Role) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Role (com.epam.pipeline.entity.user.Role)8 ExtendedRole (com.epam.pipeline.entity.user.ExtendedRole)6 Test (org.junit.Test)5 Transactional (org.springframework.transaction.annotation.Transactional)5 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)4 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)3 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)2 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)2 ObjectCreatorUtils (com.epam.pipeline.manager.ObjectCreatorUtils)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2 CollectionUtils (org.apache.commons.collections4.CollectionUtils)2 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)2 IsCollectionWithSize.hasSize (org.hamcrest.collection.IsCollectionWithSize.hasSize)2 Assert (org.junit.Assert)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ContextualPreference (com.epam.pipeline.entity.contextual.ContextualPreference)1 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1