我正在尝试跟踪异常org.springframework.web.HttpMediaTypeNotSupportedException试图测试Json控制器.
控制器中的方法是:
@RequestMapping(value = "/report", method = RequestMethod.PUT)
public @ResponseBody DatosJsonVO report(@RequestHeader(value = "hash", required = true) String hash,
@RequestBody ReportVO report) {
}
Run Code Online (Sandbox Code Playgroud)
我的测试方法如下:
@Test
public void reportarPreguntaSesionInvalida() throws Exception {
ReportVO report = new ReportVO();
report.setIdQuestion(1);
report.setIssue("Wrong answer");
mockMvc.perform(put("/json/report").header("hash", "123456789")
.accept(MediaType.APPLICATION_JSON).content(asJsonString(report))).andDo(print())
.andExpect(content().string("{\"code\":2,\"message\":\"Session error\",\"data\":null}"));
}
Run Code Online (Sandbox Code Playgroud)
但是,我得到了这样的答复:
MockHttpServletRequest:
HTTP Method = PUT
Request URI = /json/report
Parameters = {}
Headers = {hash=[8.16615469E8], Accept=[application/json]}
Handler:
Type = com.controller.json.QuestionsJsonController
Async:
Was async started = false
Async result = null
Resolved Exception:
Type …Run Code Online (Sandbox Code Playgroud)