|
2 | 2 |
|
3 | 3 | import static org.assertj.core.api.Assertions.assertThat; |
4 | 4 | import static org.hamcrest.CoreMatchers.containsString; |
5 | | -import static org.mockito.Mockito.when; |
6 | 5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
7 | 6 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
8 | 7 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
|
25 | 24 | import org.springframework.test.context.ActiveProfiles; |
26 | 25 | import org.springframework.test.web.servlet.MockMvc; |
27 | 26 |
|
28 | | -import com.fasterxml.jackson.core.JsonProcessingException; |
29 | 27 | import com.fasterxml.jackson.databind.ObjectMapper; |
30 | 28 | import com.sistemacliente.SistemaClientesJavaApplication; |
31 | 29 | import com.sistemacliente.model.Cliente; |
@@ -392,6 +390,38 @@ public void listaPaginadaOrdenada_invalidParameters_returns400(int pagina, int i |
392 | 390 | .andExpect(status().isBadRequest()) |
393 | 391 | .andExpect(content().string("A página não pode ser negativa e itens não pode ser menor que 1.")); |
394 | 392 | } |
| 393 | + |
| 394 | + @Test @Transactional |
| 395 | + @DisplayName("Searches for clients using part of their names and returns a paginated list, retuns 200") |
| 396 | + public void buscarPorNomePagina_successWithParameters_returns200() throws Exception { |
| 397 | + Cliente cliente1 = new Cliente(); |
| 398 | + cliente1.setNome("Marcus"); |
| 399 | + cliente1.setCpf("23501206586"); |
| 400 | + cliente1.setEmail("marcus@gmail.com"); |
| 401 | + |
| 402 | + Cliente cliente2 = new Cliente(); |
| 403 | + cliente2.setNome("Antonio"); |
| 404 | + cliente2.setCpf("20219064674"); |
| 405 | + cliente2.setEmail("antonio@gmail.com"); |
| 406 | + |
| 407 | + Cliente cliente3 = new Cliente(); |
| 408 | + cliente3.setNome("Marcelo"); |
| 409 | + cliente3.setCpf("47852136582"); |
| 410 | + cliente3.setEmail("marcelo@gmail.com"); |
| 411 | + |
| 412 | + repository.saveAndFlush(cliente1); |
| 413 | + repository.saveAndFlush(cliente2); |
| 414 | + repository.saveAndFlush(cliente3); |
| 415 | + |
| 416 | + mvc.perform(get("/buscapornome?nome=mar&pagina=0&itens=2")).andExpect(status().isOk()) |
| 417 | + .andExpect(jsonPath("$.content[1].nome").value("Marcus")) |
| 418 | + .andExpect(jsonPath("$.content[0].nome").value("Marcelo")) |
| 419 | + .andExpect(jsonPath("$.content[1].cpf").value("23501206586")) |
| 420 | + .andExpect(jsonPath("$.content[0].cpf").value("47852136582")) |
| 421 | + .andExpect(jsonPath("$.content[1].email").value("marcus@gmail.com")) |
| 422 | + .andExpect(jsonPath("$.content[0].email").value("marcelo@gmail.com")) |
| 423 | + .andExpect(jsonPath("$.content.length()").value(2)); |
| 424 | + } |
395 | 425 | } |
396 | 426 |
|
397 | 427 |
|
|
0 commit comments