use of org.codenergic.theskeleton.privilege.PrivilegeRestData 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));
}
Aggregations