ManageReservationController { @TransactionTokenCheck(value = "cancel", type = TransactionTokenType.IN) @RequestMapping(value = "{reserveNo}/cancel", method = RequestMethod.POST) public String cancel(@PathVariable("reserveNo") String reserveNo, Model model, RedirectAttributes redirectAttr) { try { reserveService.cancel(reserveNo); } catch (BusinessException e) { model.addAttribute(e.getResultMessages()); return cancelConfirm(reserveNo, model); } return "redirect:/reservations/{reserveNo}/cancel?complete"; }  @ModelAttribute ManageReservationForm setUpManageReservationForm(); @RequestMapping(value = "me", method = RequestMethod.GET) String list(
            @AuthenticationPrincipal ReservationUserDetails userDetails,
            Model model); @RequestMapping(value = "{reserveNo}", method = RequestMethod.GET) String detailForm(@PathVariable("reserveNo") String reserveNo,
            Model model); @RequestMapping(value = "{reserveNo}/update", method = RequestMethod.GET, params = "form") String updateForm(@PathVariable("reserveNo") String reserveNo,
            ManageReservationForm form, Model model); @RequestMapping(value = "{reserveNo}/update", method = RequestMethod.POST, params = "redo") String updateRedo(@PathVariable("reserveNo") String reserveNo,
            ManageReservationForm form, Model model); @TransactionTokenCheck(value = "update", type = TransactionTokenType.BEGIN) @RequestMapping(value = "{reserveNo}/update", method = RequestMethod.POST, params = "confirm") String updateConfirm(@PathVariable("reserveNo") String reserveNo,
            @Validated ManageReservationForm form, BindingResult result,
            Model model); @TransactionTokenCheck(value = "update", type = TransactionTokenType.IN) @RequestMapping(value = "{reserveNo}/update", method = RequestMethod.POST) String update(@PathVariable("reserveNo") String reserveNo,
            @Validated ManageReservationForm form, BindingResult result,
            Model model, RedirectAttributes redirectAttr); @RequestMapping(value = "{reserveNo}/update", method = RequestMethod.GET, params = "complete") String updateComplete(); @RequestMapping(value = "{reserveNo}/update", method = RequestMethod.POST, params = "backTolist") String updateBackList(); @TransactionTokenCheck(value = "cancel", type = TransactionTokenType.BEGIN) @RequestMapping(value = "{reserveNo}/cancel", method = RequestMethod.GET) String cancelConfirm(@PathVariable("reserveNo") String reserveNo,
            Model model); @TransactionTokenCheck(value = "cancel", type = TransactionTokenType.IN) @RequestMapping(value = "{reserveNo}/cancel", method = RequestMethod.POST) String cancel(@PathVariable("reserveNo") String reserveNo,
            Model model, RedirectAttributes redirectAttr); @RequestMapping(value = "{reserveNo}/cancel", method = RequestMethod.GET, params = "complete") String cancelComplete(@PathVariable("reserveNo") String reserveNo,
            Model model); @RequestMapping(value = "{reserveNo}/cancel", method = RequestMethod.POST, params = "backTolist") String backList(); @RequestMapping(value = "{reserveNo}/pdf", method = RequestMethod.GET) String downloadPDF(@PathVariable("reserveNo") String reserveNo,
            Model model, Locale locale);  }
@Test public void testManageReservationCancelSuccess() { MockHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.post( "/reservations/123/cancel"); Mockito.doNothing().when(reserveService).cancel("123"); try { ResultActions results = mockMvc.perform(postRequest); results.andExpect(status().isFound()); results.andExpect(view().name( "redirect:/reservations/{reserveNo}/cancel?complete")); return; } catch (Exception e) { e.printStackTrace(); } fail(); }
@Test public void testManageReservationCancelFailByBusinessException() { MockHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.post( "/reservations/123/cancel"); Mockito.doThrow(new BusinessException("")).when(reserveService).cancel( "123"); when(manageReservationHelper.findDetail("123")).thenReturn( new ReservationDetailOutput()); try { ResultActions results = mockMvc.perform(postRequest); results.andExpect(status().isOk()); results.andExpect(view().name("managereservation/cancelConfirm")); results.andExpect(model().attribute("output", notNullValue())); results.andExpect(model().attribute("resultMessages", notNullValue())); return; } catch (Exception e) { e.printStackTrace(); } fail(); }