|
3 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 4 | import org.baeldung.config.WebConfig; |
5 | 5 | import org.baeldung.web.dto.HeavyResource; |
6 | | -import org.baeldung.web.dto.HeavyResourceAddressPartialUpdate; |
| 6 | +import org.baeldung.web.dto.HeavyResourceAddressOnly; |
7 | 7 | import org.junit.Before; |
8 | 8 | import org.junit.Test; |
9 | 9 | import org.junit.runner.RunWith; |
|
16 | 16 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; |
17 | 17 | import org.springframework.web.context.WebApplicationContext; |
18 | 18 |
|
| 19 | +import java.util.HashMap; |
| 20 | + |
19 | 21 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; |
20 | 22 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; |
21 | 23 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
@@ -47,10 +49,21 @@ public void givenHeavyResource_whenSendPutRequest_thenCreateResource() throws Ex |
47 | 49 | } |
48 | 50 |
|
49 | 51 | @Test |
50 | | - public void givenNewAddressOfResource_whenExecutePutRequest_thenUpdateResourcePartially() throws Exception { |
| 52 | + public void givenNewAddressOfResource_whenExecutePatchRequest_thenUpdateResourcePartially() throws Exception { |
51 | 53 | mockMvc.perform(patch("/heavy") |
52 | 54 | .contentType(MediaType.APPLICATION_JSON_VALUE) |
53 | | - .content(objectMapper.writeValueAsString(new HeavyResourceAddressPartialUpdate(1, "5th avenue"))) |
| 55 | + .content(objectMapper.writeValueAsString(new HeavyResourceAddressOnly(1, "5th avenue"))) |
| 56 | + ).andExpect(status().isOk()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void givenNewAddressOfResource_whenExecutePatchGeneric_thenUpdateResourcePartially() throws Exception { |
| 61 | + HashMap<String, Object> updates = new HashMap<>(); |
| 62 | + updates.put("address", "5th avenue"); |
| 63 | + |
| 64 | + mockMvc.perform(patch("/heavy/1") |
| 65 | + .contentType(MediaType.APPLICATION_JSON_VALUE) |
| 66 | + .content(objectMapper.writeValueAsString(updates)) |
54 | 67 | ).andExpect(status().isOk()); |
55 | 68 | } |
56 | 69 |
|
|
0 commit comments