2017-01-05 40 views
0

我正在为SpringMvc应用程序编写测试,并且遇到了一些问题。带参数的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

控制器方法1 4制成表单提交按钮。如何解决这个问题?

+0

有什么实际的异常明白吗? – hakamairi

回答

0

我已经找到了答案,正确的URL应

"/submit?id=102&delete="