I want to remove the book that I have set in my test method. how can I put make the method and-EXPECT to understand I want to remove the book I set
@Test
public void bookRemoveTest() throws Exception {
securityService.autologin("admin", "admin");
Book book = new Book();
book.setId(1L);
bookService.findOne(1L);
expect(bookService.findOne(anyLong())).andReturn(book);
replay(bookService);
MvcResult result = mockMvc
.perform(post("/book/remove")
.accept(MediaType.TEXT_HTML)
.contentType(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andReturn();
String controllerResult = result.getResponse().getContentAsString();
}
For further understanding this is the test controller
@RequestMapping(value="/remove", method=RequestMethod.POST)
public String remove(
@ModelAttribute("id") String id, Model model
) {
bookService.removeOne(Long.parseLong(id.substring(8)));
List<Book> bookList = bookService.findAll();
model.addAttribute("bookList", bookList);
return "redirect:/book/bookList";
}
Aucun commentaire:
Enregistrer un commentaire