use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class PrivilegeRestControllerTest method testFindPrivilegeByName.
@Test
public void testFindPrivilegeByName() throws Exception {
PrivilegeEntity dbResult = new PrivilegeEntity().setId("123").setName("12345").setDescription("Description 12345");
when(privilegeService.findPrivilegeByIdOrName("123")).thenReturn(dbResult);
ResultActions resultActions = mockMvc.perform(get("/api/privileges/123").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("privilege-read"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
verify(privilegeService).findPrivilegeByIdOrName("123");
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(PrivilegeRestData.builder().fromPrivilegeEntity(dbResult).build()));
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class RoleRestControllerTest method testRemovePrivilegeFromRole.
@Test
public void testRemovePrivilegeFromRole() throws Exception {
final RoleEntity role = new RoleEntity().setId("role123").setCode("role123");
when(roleService.removePrivilegeFromRole("role123", "privilege123")).thenReturn(role);
ResultActions resultActions = mockMvc.perform(delete("/api/roles/role123/privileges").content("{\"privilege\": \"privilege123\"}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("role-privilege-delete"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
verify(roleService).removePrivilegeFromRole("role123", "privilege123");
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(RoleRestData.builder().fromRoleEntity(role).build()));
}
use of org.springframework.test.web.servlet.ResultActions 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.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class RoleRestControllerTest method testUpdateRole.
@Test
public void testUpdateRole() throws Exception {
RoleEntity input = new RoleEntity().setId("123").setCode("12345").setDescription("Description 12345");
RoleEntity dbResult = new RoleEntity().setId(UUID.randomUUID().toString()).setCode("12345").setDescription("Description 12345");
byte[] jsonInput = objectMapper.writeValueAsBytes(RoleRestData.builder().fromRoleEntity(input).build());
when(roleService.updateRole(eq("123"), any())).thenReturn(dbResult);
ResultActions resultActions = mockMvc.perform(put("/api/roles/123").contentType(MediaType.APPLICATION_JSON).content(jsonInput)).andExpect(status().isOk()).andDo(document("role-update"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
verify(roleService).updateRole(eq("123"), any());
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(RoleRestData.builder().fromRoleEntity(dbResult).build()));
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class UserRestControllerTest method testLockOrUnlockUser.
@Test
public void testLockOrUnlockUser() throws Exception {
final UserEntity user = new UserEntity().setAccountNonLocked(true);
when(userAdminService.lockOrUnlockUser("user123", true)).thenReturn(user);
ResultActions resultActions = mockMvc.perform(put("/api/users/user123/lock").content("{\"enabled\": true}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-lock"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
verify(userAdminService).lockOrUnlockUser("user123", true);
}
Aggregations