use of org.codenergic.theskeleton.privilege.PrivilegeEntity in project theskeleton by codenergic.
the class PrivilegeServiceTest method testFindPrivileges.
@Test
@SuppressWarnings("serial")
public void testFindPrivileges() {
PrivilegeEntity result = new PrivilegeEntity() {
{
setId("123");
}
}.setName("user_list_read");
Page<PrivilegeEntity> page = new PageImpl<>(Arrays.asList(result));
when(privilegeRepository.findAll(any(Pageable.class))).thenReturn(page);
assertThat(privilegeService.findPrivileges(new PageRequest(1, 10))).isEqualTo(page);
verify(privilegeRepository).findAll(any(Pageable.class));
}
use of org.codenergic.theskeleton.privilege.PrivilegeEntity in project theskeleton by codenergic.
the class RoleRestControllerTest method testFindPrivilegesByRoleCode.
@Test
public void testFindPrivilegesByRoleCode() throws Exception {
final PrivilegeEntity privilege = new PrivilegeEntity().setId("privilege123").setName("user_list_read");
final Set<PrivilegeEntity> privileges = new HashSet<>(Arrays.asList(privilege));
final Set<PrivilegeRestData> expected = privileges.stream().map(p -> PrivilegeRestData.builder().fromPrivilegeEntity(p).build()).collect(Collectors.toSet());
when(roleService.findPrivilegesByRoleCode("role123")).thenReturn(privileges);
ResultActions resultActions = mockMvc.perform(get("/api/roles/role123/privileges").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("role-privilege-read"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
verify(roleService).findPrivilegesByRoleCode("role123");
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(expected));
}
use of org.codenergic.theskeleton.privilege.PrivilegeEntity in project theskeleton by codenergic.
the class PrivilegeServiceTest method testFindPrivilegeById.
@Test
@SuppressWarnings("serial")
public void testFindPrivilegeById() {
PrivilegeEntity result = new PrivilegeEntity() {
{
setId("123");
}
}.setName("user_list_read");
when(privilegeRepository.findOne(eq("123"))).thenReturn(result);
assertThat(privilegeService.findPrivilegeById("123")).isEqualTo(result);
verify(privilegeRepository).findOne(eq("123"));
when(privilegeRepository.findOne(eq("124"))).thenReturn(null);
assertThat(privilegeService.findPrivilegeById("124")).isNull();
verify(privilegeRepository).findOne(eq("124"));
}
use of org.codenergic.theskeleton.privilege.PrivilegeEntity in project theskeleton by codenergic.
the class PrivilegeServiceTest method testFindPrivilegeByName.
@Test
public void testFindPrivilegeByName() {
PrivilegeEntity result = new PrivilegeEntity();
result.setName("user");
when(privilegeRepository.findByName(eq("user"))).thenReturn(result);
assertThat(privilegeService.findPrivilegeByName("user")).isEqualTo(result);
verify(privilegeRepository).findByName(eq("user"));
when(privilegeRepository.findByName(eq("admin"))).thenReturn(null);
assertThat(privilegeService.findPrivilegeByName("admin")).isNull();
verify(privilegeRepository).findByName(eq("admin"));
}
use of org.codenergic.theskeleton.privilege.PrivilegeEntity in project theskeleton by codenergic.
the class RoleServiceTest 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());
when(roleRepository.findByCode("role")).thenReturn(role);
when(privilegeRepository.findByName("privilege")).thenReturn(privilege);
when(rolePrivilegeRepository.save(any(RolePrivilegeEntity.class))).thenReturn(result);
assertThat(roleService.addPrivilegeToRole("role", "privilege")).isEqualTo(role);
verify(roleRepository).findByCode("role");
verify(privilegeRepository).findByName("privilege");
verify(rolePrivilegeRepository).save(any(RolePrivilegeEntity.class));
}
Aggregations