【发布时间】:2017-01-05 21:48:51
【问题描述】:
我正在为 SpringMvc 应用程序编写测试,但遇到了一些问题。
这是我的控制器测试方法:
@RequestMapping(value = "submit", method = RequestMethod.POST, params = "delete")
public String delete(@ModelAttribute("inputBean") InputBean inputBean) {
Book book = (Book) itemServiceController.getItemFindByIdService().findById(inputBean.getId());
Author author = getAuthorOfBook(book);
author.getBookList().remove(book);
authorServiceController.getAuthorCreateService().create(authorServiceController.getAuthorUpdateService().update(author));
itemServiceController.getItemDeleteService().delete(inputBean.getId());
return "redirect:index.html";
}
这是我的 mockMvc:
mockMvc.perform(post("/submit?delete")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("id", "1")
.sessionAttr("inputBean", new InputBean())
)
.andExpect(status().isOk())
.andExpect(view().name("indexLib"))
.andExpect(model().attribute("inputBean", hasProperty("id", is(1))));
这将返回状态 http 状态 400。
控制器方法用于 4 个表单提交按钮中的 1 个。如何解决这个问题?
【问题讨论】:
-
你得到的实际异常是什么?
标签: java spring-mvc-test