@Test public void submitEditPersonForm() throws PersonNotFoundException { MockHttpServletRequest mockRequest = new MockHttpServletRequest("/person/edit", "POST"); PersonDTO updated = PersonTestUtil.createDTO(PERSON_ID, FIRST_NAME_UPDATED, LAST_NAME_UPDATED); Person person = PersonTestUtil.createModelObject(PERSON_ID, FIRST_NAME_UPDATED, LAST_NAME_UPDATED); when(personServiceMock.update(updated)).thenReturn(person); initMessageSourceForFeedbackMessage(PersonController.FEEDBACK_MESSAGE_KEY_PERSON_EDITED); BindingResult bindingResult = bindAndValidate(mockRequest, updated); RedirectAttributes attributes = new RedirectAttributesModelMap(); String view = controller.submitEditPersonForm(updated, bindingResult, attributes); verify(personServiceMock, times(1)).update(updated); verifyNoMoreInteractions(personServiceMock); String expectedView = createExpectedRedirectViewPath(PersonController.REQUEST_MAPPING_LIST); assertEquals(expectedView, view); assertFeedbackMessage(attributes, PersonController.FEEDBACK_MESSAGE_KEY_PERSON_EDITED); assertEquals(updated.getFirstName(), person.getFirstName()); assertEquals(updated.getLastName(), person.getLastName()); }
@RequestMapping(value = "/person/edit", method = RequestMethod.POST) public String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes) { LOGGER.debug("Edit person form was submitted with information: " + updated); if (bindingResult.hasErrors()) { LOGGER.debug("Edit person form contains validation errors. Rendering form view."); return PERSON_EDIT_FORM_VIEW; } try { Person person = personService.update(updated); addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_EDITED, person.getName()); } catch (PersonNotFoundException e) { LOGGER.debug("No person was found with id: " + updated.getId()); addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); } return createRedirectViewPath(REQUEST_MAPPING_LIST); }
PersonController extends AbstractController { @RequestMapping(value = "/person/edit", method = RequestMethod.POST) public String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes) { LOGGER.debug("Edit person form was submitted with information: " + updated); if (bindingResult.hasErrors()) { LOGGER.debug("Edit person form contains validation errors. Rendering form view."); return PERSON_EDIT_FORM_VIEW; } try { Person person = personService.update(updated); addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_EDITED, person.getName()); } catch (PersonNotFoundException e) { LOGGER.debug("No person was found with id: " + updated.getId()); addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); } return createRedirectViewPath(REQUEST_MAPPING_LIST); } }
PersonController extends AbstractController { @RequestMapping(value = "/person/edit", method = RequestMethod.POST) public String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes) { LOGGER.debug("Edit person form was submitted with information: " + updated); if (bindingResult.hasErrors()) { LOGGER.debug("Edit person form contains validation errors. Rendering form view."); return PERSON_EDIT_FORM_VIEW; } try { Person person = personService.update(updated); addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_EDITED, person.getName()); } catch (PersonNotFoundException e) { LOGGER.debug("No person was found with id: " + updated.getId()); addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); } return createRedirectViewPath(REQUEST_MAPPING_LIST); }  }
PersonController extends AbstractController { @RequestMapping(value = "/person/edit", method = RequestMethod.POST) public String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes) { LOGGER.debug("Edit person form was submitted with information: " + updated); if (bindingResult.hasErrors()) { LOGGER.debug("Edit person form contains validation errors. Rendering form view."); return PERSON_EDIT_FORM_VIEW; } try { Person person = personService.update(updated); addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_EDITED, person.getName()); } catch (PersonNotFoundException e) { LOGGER.debug("No person was found with id: " + updated.getId()); addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); } return createRedirectViewPath(REQUEST_MAPPING_LIST); }  @RequestMapping(value="/person/count", method = RequestMethod.POST) @ResponseBody Long count(@RequestBody SearchDTO searchCriteria); @RequestMapping(value = "/person/delete/{id}", method = RequestMethod.GET) String delete(@PathVariable("id") Long id, RedirectAttributes attributes); @RequestMapping(value = "/person/search/page", method = RequestMethod.POST) @ResponseBody List<PersonDTO> search(@RequestBody SearchDTO searchCriteria); @RequestMapping(value = "/person/create", method = RequestMethod.GET) String showCreatePersonForm(Model model); @RequestMapping(value = "/person/create", method = RequestMethod.POST) String submitCreatePersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO created, BindingResult bindingResult, RedirectAttributes attributes); @RequestMapping(value = "/person/edit/{id}", method = RequestMethod.GET) String showEditPersonForm(@PathVariable("id") Long id, Model model, RedirectAttributes attributes); @RequestMapping(value = "/person/edit", method = RequestMethod.POST) String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes); @RequestMapping(value = REQUEST_MAPPING_LIST, method = RequestMethod.GET) String showList(Model model); @RequestMapping(value = "/person/search", method=RequestMethod.POST) String showSearchResultPage(@ModelAttribute(MODEL_ATTRIBUTE_SEARCH_CRITERIA) SearchDTO searchCriteria, Model model); }
PersonController extends AbstractController { @RequestMapping(value = "/person/edit", method = RequestMethod.POST) public String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes) { LOGGER.debug("Edit person form was submitted with information: " + updated); if (bindingResult.hasErrors()) { LOGGER.debug("Edit person form contains validation errors. Rendering form view."); return PERSON_EDIT_FORM_VIEW; } try { Person person = personService.update(updated); addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_PERSON_EDITED, person.getName()); } catch (PersonNotFoundException e) { LOGGER.debug("No person was found with id: " + updated.getId()); addErrorMessage(attributes, ERROR_MESSAGE_KEY_EDITED_PERSON_WAS_NOT_FOUND); } return createRedirectViewPath(REQUEST_MAPPING_LIST); }  @RequestMapping(value="/person/count", method = RequestMethod.POST) @ResponseBody Long count(@RequestBody SearchDTO searchCriteria); @RequestMapping(value = "/person/delete/{id}", method = RequestMethod.GET) String delete(@PathVariable("id") Long id, RedirectAttributes attributes); @RequestMapping(value = "/person/search/page", method = RequestMethod.POST) @ResponseBody List<PersonDTO> search(@RequestBody SearchDTO searchCriteria); @RequestMapping(value = "/person/create", method = RequestMethod.GET) String showCreatePersonForm(Model model); @RequestMapping(value = "/person/create", method = RequestMethod.POST) String submitCreatePersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO created, BindingResult bindingResult, RedirectAttributes attributes); @RequestMapping(value = "/person/edit/{id}", method = RequestMethod.GET) String showEditPersonForm(@PathVariable("id") Long id, Model model, RedirectAttributes attributes); @RequestMapping(value = "/person/edit", method = RequestMethod.POST) String submitEditPersonForm(@Valid @ModelAttribute(MODEL_ATTIRUTE_PERSON) PersonDTO updated, BindingResult bindingResult, RedirectAttributes attributes); @RequestMapping(value = REQUEST_MAPPING_LIST, method = RequestMethod.GET) String showList(Model model); @RequestMapping(value = "/person/search", method=RequestMethod.POST) String showSearchResultPage(@ModelAttribute(MODEL_ATTRIBUTE_SEARCH_CRITERIA) SearchDTO searchCriteria, Model model);  }