|
4 | 4 | import static org.hamcrest.CoreMatchers.containsString; |
5 | 5 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; |
6 | 6 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| 7 | +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; |
7 | 8 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
8 | 9 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; |
9 | 10 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; |
10 | 11 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
11 | 12 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
12 | 13 |
|
| 14 | +import java.util.HashMap; |
| 15 | +import java.util.Map; |
| 16 | + |
13 | 17 | import org.junit.jupiter.api.BeforeEach; |
14 | 18 | import org.junit.jupiter.api.DisplayName; |
15 | 19 | import org.junit.jupiter.api.Test; |
@@ -476,7 +480,24 @@ public void buscarPorNomePagina_invalidName_returns400(String nome) throws Excep |
476 | 480 | .string("Nome para busca não pode ser vazio ou nulo.")); |
477 | 481 | } |
478 | 482 |
|
479 | | - |
| 483 | + @Test @Transactional @DisplayName("Returns 200. Partial update of client information.") |
| 484 | + public void atualizarParcial_success_return200() throws Exception { |
| 485 | + Cliente cliente1 = new Cliente(); |
| 486 | + cliente1.setNome("Marcus"); |
| 487 | + cliente1.setCpf("23501206586"); |
| 488 | + cliente1.setEmail("marcus@gmail.com"); |
| 489 | + repository.saveAndFlush(cliente1); |
| 490 | + |
| 491 | + Map<String, Object> updates = new HashMap<>(); |
| 492 | + updates.put("nome", "Antonio"); |
| 493 | + updates.put("email", "antonio@email.com"); |
| 494 | + |
| 495 | + mvc.perform(patch("/parcial/"+cliente1.getId()).contentType(MediaType.APPLICATION_JSON) |
| 496 | + .content(mapper.writeValueAsString(updates))).andExpect(status().isOk()) |
| 497 | + .andExpect(jsonPath("$.nome").value("Antonio")) |
| 498 | + .andExpect(jsonPath("$.cpf").value("23501206586")) |
| 499 | + .andExpect(jsonPath("$.email").value("antonio@email.com")); |
| 500 | + } |
480 | 501 |
|
481 | 502 | } |
482 | 503 |
|
|
0 commit comments