2017-01-05 63 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="