use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class UserRestControllerTest method testRemoveRoleFromUser.
@Test
public void testRemoveRoleFromUser() throws Exception {
final UserEntity user = new UserEntity().setId("user123");
when(userAdminService.removeRoleFromUser("user123", "role123")).thenReturn(user);
ResultActions resultActions = mockMvc.perform(delete("/api/users/user123/roles").content("{\"role\": \"role123\"}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-role-delete"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
verify(userAdminService).removeRoleFromUser("user123", "role123");
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class UserRestControllerTest method testUpdateUserPassword.
@Test
public void testUpdateUserPassword() throws Exception {
final UserEntity user = new UserEntity().setId("user123");
when(userAdminService.updateUserPassword(eq("user123"), any())).thenReturn(user);
ResultActions resultActions = mockMvc.perform(put("/api/users/user123/password").content("{\"username\": \"user123\"}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-update-password"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
verify(userAdminService).updateUserPassword(eq("user123"), any());
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class UserRestControllerTest method testFindUsersByUsernameStartingWith.
@Test
public void testFindUsersByUsernameStartingWith() throws Exception {
final UserEntity user = new UserEntity().setId("user123").setEmail("user@server");
final Page<UserEntity> users = new PageImpl<>(Arrays.asList(user));
when(userAdminService.findUsersByUsernameStartingWith(eq("user123"), any())).thenReturn(users);
ResultActions resultActions = mockMvc.perform(get("/api/users?username=user123").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-read-username-startingwith"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(users.map(u -> UserRestData.builder().fromUserEntity(u).build())));
verify(userAdminService).findUsersByUsernameStartingWith(eq("user123"), any());
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class UserRestControllerTest method testExtendsUserExpiration.
@Test
public void testExtendsUserExpiration() throws Exception {
final UserEntity user = new UserEntity().setExpiredAt(new Date());
when(userAdminService.extendsUserExpiration("user123", 60)).thenReturn(user);
ResultActions resultActions = mockMvc.perform(put("/api/users/user123/exp").content("{\"amount\": 60}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-extend-exp"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
verify(userAdminService).extendsUserExpiration("user123", 60);
}
use of org.springframework.test.web.servlet.ResultActions in project theskeleton by codenergic.
the class UserRestControllerTest method testEnableOrDisableUser.
@Test
public void testEnableOrDisableUser() throws Exception {
final UserEntity user = new UserEntity().setEnabled(true);
when(userAdminService.enableOrDisableUser("user123", true)).thenReturn(user);
ResultActions resultActions = mockMvc.perform(put("/api/users/user123/enable").content("{\"enabled\": true}").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andDo(document("user-enable"));
MockHttpServletResponse response = resultActions.andReturn().getResponse();
assertThat(response.getContentAsByteArray()).isEqualTo(objectMapper.writeValueAsBytes(UserRestData.builder().fromUserEntity(user).build()));
verify(userAdminService).enableOrDisableUser("user123", true);
}
Aggregations