这是我的功能
@RequestMapping(value = { "/showTaskMonitorStatus.do", "/showStatusPage.do" }, method = RequestMethod.GET)
public ModelAndView handleShowTaskMonitorStatus(HttpServletRequest request) {
ModelAndView model = new ModelAndView();
-----------------------------------
return model;
}
我的测试用例看起来像,
@Test
public void testHandleShowTaskMonitorStatus() throws Exception {
MvcResult result = mockMvc.perform(get("/showTaskMonitorStatus.do"))
.andDo(MockMvcResultHandlers.print()) // Print request and response
.andExpect(status().isOk())
.andExpect(content().contentType("application/json")) //but in this line I am getting error.(Content type not set.)
.andReturn();
--------------------------------------
}
任何人都可以建议我如何解决这个问题?
答案 0 :(得分:1)
您可以像这样修改@RequestMapping
以设置正确的内容类型:
@RequestMapping(value = { ... }, produces = MediaType.APPLICATION_JSON_VALUE)