use of org.codenergic.theskeleton.role.RoleEntity in project theskeleton by codenergic.
the class RoleServiceImpl method deleteRole.
@Override
@Transactional
public void deleteRole(String idOrCode) {
RoleEntity e = findRoleByIdOrCode(idOrCode);
assertRoleNotNull(e);
roleRepository.delete(e);
}
use of org.codenergic.theskeleton.role.RoleEntity in project theskeleton by codenergic.
the class RoleServiceImpl method updateRole.
@Override
@Transactional
public RoleEntity updateRole(String id, RoleEntity role) {
RoleEntity e = findRoleByIdOrCode(id);
assertRoleNotNull(e);
e.setCode(role.getCode());
e.setDescription(role.getDescription());
return e;
}
use of org.codenergic.theskeleton.role.RoleEntity in project theskeleton by codenergic.
the class UserServiceImpl method addRoleToUser.
@Override
@Transactional
public UserEntity addRoleToUser(String username, String roleCode) {
UserEntity user = findUserByUsername(username);
RoleEntity role = roleRepository.findByCode(roleCode);
return userRoleRepository.save(new UserRoleEntity(user, role)).getUser();
}
use of org.codenergic.theskeleton.role.RoleEntity in project theskeleton by codenergic.
the class UserServiceTest method testAddRoleToUser.
@Test
public void testAddRoleToUser() {
RoleEntity role = new RoleEntity().setId(UUID.randomUUID().toString()).setCode("role");
UserEntity user = new UserEntity().setId(UUID.randomUUID().toString()).setUsername("user").setPassword(passwordEncoder.encode("user"));
UserRoleEntity result = new UserRoleEntity(user, role);
result.setId(UUID.randomUUID().toString());
when(roleRepository.findByCode("role")).thenReturn(role);
when(userRepository.findByUsername("user")).thenReturn(user);
when(userRoleRepository.save(any(UserRoleEntity.class))).thenReturn(result);
assertThat(userAdminService.addRoleToUser("user", "role")).isEqualTo(user);
verify(roleRepository).findByCode("role");
verify(userRepository).findByUsername("user");
verify(userRoleRepository).save(any(UserRoleEntity.class));
}
use of org.codenergic.theskeleton.role.RoleEntity in project theskeleton by codenergic.
the class PrivilegeServiceTest method testAddPrivilegeToRole.
@Test
public void testAddPrivilegeToRole() {
RoleEntity role = new RoleEntity().setId(UUID.randomUUID().toString()).setCode("role");
PrivilegeEntity privilege = new PrivilegeEntity().setId(UUID.randomUUID().toString()).setName("privilege");
RolePrivilegeEntity result = new RolePrivilegeEntity(role, privilege);
result.setId(UUID.randomUUID().toString());
result.getAuthority();
when(roleRepository.findByCode("role")).thenReturn(Optional.of(role));
when(privilegeRepository.findByName("privilege")).thenReturn(Optional.of(privilege));
when(rolePrivilegeRepository.save(any(RolePrivilegeEntity.class))).thenReturn(result);
assertThat(privilegeService.addPrivilegeToRole("role", "privilege")).isEqualTo(role);
verify(roleRepository).findByCode("role");
verify(privilegeRepository).findByName("privilege");
verify(rolePrivilegeRepository).save(any(RolePrivilegeEntity.class));
when(roleRepository.findByCode("role1")).thenReturn(Optional.empty());
assertThatThrownBy(() -> {
privilegeService.addPrivilegeToRole("role1", "privilege");
}).isInstanceOf(RoleNotFoundException.class);
verify(roleRepository).findByCode("role1");
when(privilegeRepository.findByName("privilege1")).thenReturn(Optional.empty());
assertThatThrownBy(() -> {
privilegeService.addPrivilegeToRole("role", "privilege1");
}).isInstanceOf(PrivilegeNotFoundException.class);
verify(privilegeRepository).findByName("privilege1");
}
Aggregations