Complete the code to perform a GET request using MockMvc.
mockMvc.perform([1]("/api/data"))
The get method is used to perform a GET request in MockMvc.
Complete the code to expect a 200 OK status in the response.
mockMvc.perform(get("/api/data")).andExpect([1].status().isOk())
MockMvcResultMatchers provides methods to assert the response status and content.
Fix the error in the code to check the response content contains 'success'.
mockMvc.perform(get("/api/data")).andExpect(MockMvcResultMatchers.content().string([1]("success")))
The method containsString is used to check if the response content includes a specific substring.
Fill both blanks to perform a POST request with JSON content and expect a 201 status.
mockMvc.perform([1]("/api/create").contentType([2]).content(jsonData)).andExpect(MockMvcResultMatchers.status().isCreated())
Use post to send data and MediaType.APPLICATION_JSON to specify JSON content type.
Fill both blanks to check JSON response field 'name' equals 'John'.
mockMvc.perform(get("/api/user/1")).andExpect(MockMvcResultMatchers.jsonPath([1]).value([2]))
The JSON path "$.name" targets the 'name' field, and "John" is the expected value.
