This is my Controller method:
@RequestMapping(method = RequestMethod.PUT,produces="application/json", headers = "content-type=application/json")
public @ResponseBody User updateUser(@RequestBody User user) throws PropertyErrorException, ItemNotFoundException {
return service.UpdateUser(user);
}
Using Spring test-mvc I would like to write a unit test case:
@Test
public void UpdateUser() throws Exception {
mockMvc.perform(put("/r01/users").body(userJsonString.getBytes())
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().type(MediaType.APPLICATION_JSON))
.andExpect(content().string(userString));
}
Running this test case generates:
WARN org.springframework.web.servlet.PageNotFound - Request method 'PUT' not supported
Also, updateUser method is never called and the response code is 405.
I have written a lot of tests, all GET requests, and they are working correctly. This means that I am confident in ContextConfiguration. What have I missed?