I am writing test cases for my spring restful services. We have a put service in the controller, the syntax is as follows
@RequestMapping(value="/update", method=RequestMethod.PUT)
public @ResponseBody List<PaidUpResponse> updateStatus(
@RequestBody @Valid PaidUpRequest paidUpRequest,
HttpServletRequest request, HttpServletResponse response) {
}
to write test case, I used the following method
mockMvc.perform(put("/update").contentType(UnitTestUtil.APPLICATION_JSON_UTF8)
.content(UnitTestUtil.convertObjectToJsonBytes(request)))
.andExpect(status().isOk());
but it is giving compilation error, saying "The method put(String) is undefined". could you suggest me how to test put method?
You have to import the appropriate dependency:
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
or
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With