use of org.codenergic.theskeleton.role.RoleRestData in project theskeleton by codenergic.
the class UserRestControllerTest method testFindRolesByUserUsername.
@Test
public void testFindRolesByUserUsername() throws Exception {
final RoleEntity role = new RoleEntity().setId("role123").setCode("role123");
final Set<RoleEntity> roles = new HashSet<>(Arrays.asList(role));
final Set<RoleRestData> expected = roles.stream().map(r -> RoleRestData.builder().fromRoleEntity(r).build()).collect(Collectors.toSet());
when(userAdminService.findRolesByUserUsername("user123")).thenReturn(roles);
ResultActions resultActions = mockMvc.perform(get("/api/users/user123/roles").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-role-read"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(expected));
verify(userAdminService).findRolesByUserUsername("user123");
}
Aggregations