Skip to content
Snippets Groups Projects
Commit 2bb0e4c8 authored by Dominika Zemanovičová's avatar Dominika Zemanovičová
Browse files

Test find user

parent 7c8c5583
No related branches found
No related tags found
2 merge requests!14Language school user tests,!13Language school user
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.fuseri.model.dto.user.AddressDto;
import org.fuseri.model.dto.user.UserCreateDto;
import org.fuseri.model.dto.user.UserDto;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
......@@ -25,6 +26,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@AutoConfigureMockMvc
class UserControllerTest {
@Autowired
private ObjectMapper objectMapper;
@Autowired
private MockMvc mockMvc;
......@@ -99,6 +103,20 @@ class UserControllerTest {
.andExpect(status().is4xxClientError());
}
@Test
void findUser() throws Exception {
String response = mockMvc.perform(post("/users")
.content(asJsonString(USER_TO_CREATE))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
String id = objectMapper.readValue(response, UserDto.class).getId();
mockMvc.perform(get("/users/" + id))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id").value(id));
}
private static String asJsonString(final Object obj) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(obj);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment