@Test public void bindingErrorsShouldCauseReturnToFormView() throws Exception { LatenessDormancyFormBean expectedFormBean = new LatenessDormancyFormBean(); expectedFormBean.setLatenessDays(1); expectedFormBean.setDormancyDays(1); when(bindingResult.hasErrors()).thenReturn(true); String returnedView = latenessDormancyController.processFormSubmit("", expectedFormBean, bindingResult, sessionStatus); Assert.assertThat(returnedView, is(FORM_VIEW)); Mockito.verify(sessionStatus, times(0)).setComplete(); }
@RequestMapping(method = RequestMethod.POST) public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean, BindingResult result, SessionStatus status) { String viewName = REDIRECT_TO_ADMIN_SCREEN; if (StringUtils.isNotBlank(cancel)) { viewName = REDIRECT_TO_ADMIN_SCREEN; status.setComplete(); } else if (result.hasErrors()) { viewName = "editLatenessDormancy"; } else { ProductConfigurationDto productConfigurationDto = new ProductConfigurationDto(formBean.getLatenessDays(), formBean.getDormancyDays()); this.adminServiceFacade.updateProductConfiguration(productConfigurationDto); status.setComplete(); } return viewName; }
LatenessDormancyController { @RequestMapping(method = RequestMethod.POST) public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean, BindingResult result, SessionStatus status) { String viewName = REDIRECT_TO_ADMIN_SCREEN; if (StringUtils.isNotBlank(cancel)) { viewName = REDIRECT_TO_ADMIN_SCREEN; status.setComplete(); } else if (result.hasErrors()) { viewName = "editLatenessDormancy"; } else { ProductConfigurationDto productConfigurationDto = new ProductConfigurationDto(formBean.getLatenessDays(), formBean.getDormancyDays()); this.adminServiceFacade.updateProductConfiguration(productConfigurationDto); status.setComplete(); } return viewName; } }
LatenessDormancyController { @RequestMapping(method = RequestMethod.POST) public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean, BindingResult result, SessionStatus status) { String viewName = REDIRECT_TO_ADMIN_SCREEN; if (StringUtils.isNotBlank(cancel)) { viewName = REDIRECT_TO_ADMIN_SCREEN; status.setComplete(); } else if (result.hasErrors()) { viewName = "editLatenessDormancy"; } else { ProductConfigurationDto productConfigurationDto = new ProductConfigurationDto(formBean.getLatenessDays(), formBean.getDormancyDays()); this.adminServiceFacade.updateProductConfiguration(productConfigurationDto); status.setComplete(); } return viewName; } protected  LatenessDormancyController();  LatenessDormancyController(final AdminServiceFacade adminServiceFacade); }
LatenessDormancyController { @RequestMapping(method = RequestMethod.POST) public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean, BindingResult result, SessionStatus status) { String viewName = REDIRECT_TO_ADMIN_SCREEN; if (StringUtils.isNotBlank(cancel)) { viewName = REDIRECT_TO_ADMIN_SCREEN; status.setComplete(); } else if (result.hasErrors()) { viewName = "editLatenessDormancy"; } else { ProductConfigurationDto productConfigurationDto = new ProductConfigurationDto(formBean.getLatenessDays(), formBean.getDormancyDays()); this.adminServiceFacade.updateProductConfiguration(productConfigurationDto); status.setComplete(); } return viewName; } protected  LatenessDormancyController();  LatenessDormancyController(final AdminServiceFacade adminServiceFacade); @ModelAttribute("breadcrumbs") List<BreadCrumbsLinks> showBreadCrumbs(); @RequestMapping(method = RequestMethod.GET) @ModelAttribute("formBean") LatenessDormancyFormBean showPopulatedForm(); @RequestMapping(method = RequestMethod.POST) String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel,
                                    @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean,
                                    BindingResult result,
                                    SessionStatus status); }
LatenessDormancyController { @RequestMapping(method = RequestMethod.POST) public String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean, BindingResult result, SessionStatus status) { String viewName = REDIRECT_TO_ADMIN_SCREEN; if (StringUtils.isNotBlank(cancel)) { viewName = REDIRECT_TO_ADMIN_SCREEN; status.setComplete(); } else if (result.hasErrors()) { viewName = "editLatenessDormancy"; } else { ProductConfigurationDto productConfigurationDto = new ProductConfigurationDto(formBean.getLatenessDays(), formBean.getDormancyDays()); this.adminServiceFacade.updateProductConfiguration(productConfigurationDto); status.setComplete(); } return viewName; } protected  LatenessDormancyController();  LatenessDormancyController(final AdminServiceFacade adminServiceFacade); @ModelAttribute("breadcrumbs") List<BreadCrumbsLinks> showBreadCrumbs(); @RequestMapping(method = RequestMethod.GET) @ModelAttribute("formBean") LatenessDormancyFormBean showPopulatedForm(); @RequestMapping(method = RequestMethod.POST) String processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel,
                                    @Valid @ModelAttribute("formBean") LatenessDormancyFormBean formBean,
                                    BindingResult result,
                                    SessionStatus status);  }