これは私のコントローラーメソッドです:
@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);
}
Spring test-mvc を使用して、単体テスト ケースを書きたいと思います。
@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));
}
このテスト ケースを実行すると、以下が生成されます。
WARN org.springframework.web.servlet.PageNotFound - Request method 'PUT' not supported
また、updateUser メソッドは呼び出されず、応答コードは 405 です。
私は多くのテスト、すべての GET リクエストを作成しましたが、それらは正しく機能しています。これは、ContextConfiguration に自信があることを意味します。私は何を逃したのですか?