I'm writing test for SpringMvc app, and i've run into some issue.
here is my controller method for test:
@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";
}
here is my 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))));
This returns status http status 400.
Controller method is made for 1 of 4 form submit buttons. How to fix this?
I've found the answer, the proper url should be