@Test public void editDiseaseTrait() throws Exception { mockMvc.perform(post("/diseasetraits/799") .param("trait", "Severe asthma")) .andExpect(status().is3xxRedirection()) .andExpect(view().name("redirect:/diseasetraits")); ArgumentCaptor<DiseaseTrait> diseaseTraitArgumentCaptor = ArgumentCaptor.forClass(DiseaseTrait.class); verify(diseaseTraitRepository).save(diseaseTraitArgumentCaptor.capture()); assertEquals("Severe asthma", diseaseTraitArgumentCaptor.getValue().getTrait()); verifyZeroInteractions(studyRepository); }
@RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) public String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, @PathVariable Long diseaseTraitId) { if (bindingResult.hasErrors()) { return "edit_disease_trait"; } else { diseaseTraitRepository.save(diseaseTrait); return "redirect:/diseasetraits"; } }
DiseaseTraitController { @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) public String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, @PathVariable Long diseaseTraitId) { if (bindingResult.hasErrors()) { return "edit_disease_trait"; } else { diseaseTraitRepository.save(diseaseTrait); return "redirect:/diseasetraits"; } } }
DiseaseTraitController { @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) public String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, @PathVariable Long diseaseTraitId) { if (bindingResult.hasErrors()) { return "edit_disease_trait"; } else { diseaseTraitRepository.save(diseaseTrait); return "redirect:/diseasetraits"; } } @Autowired  DiseaseTraitController(DiseaseTraitRepository diseaseTraitRepository, StudyRepository studyRepository); }
DiseaseTraitController { @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) public String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, @PathVariable Long diseaseTraitId) { if (bindingResult.hasErrors()) { return "edit_disease_trait"; } else { diseaseTraitRepository.save(diseaseTrait); return "redirect:/diseasetraits"; } } @Autowired  DiseaseTraitController(DiseaseTraitRepository diseaseTraitRepository, StudyRepository studyRepository); @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) String allDiseaseTraits(Model model); @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) String addDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait,
                                  BindingResult bindingResult,
                                  Model model, RedirectAttributes redirectAttributes); @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) String viewDiseaseTrait(Model model, @PathVariable Long diseaseTraitId); @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait,
                                   BindingResult bindingResult, @PathVariable Long diseaseTraitId); @RequestMapping(value = "/{diseaseTraitId}/delete", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) String viewDiseaseTraitToDelete(Model model, @PathVariable Long diseaseTraitId); @RequestMapping(value = "/{diseaseTraitId}/delete", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) String deleteDiseaseTrait(@PathVariable Long diseaseTraitId, RedirectAttributes redirectAttributes); @ModelAttribute("diseaseTraits") List<DiseaseTrait> populateDiseaseTraits(); }
DiseaseTraitController { @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) public String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait, BindingResult bindingResult, @PathVariable Long diseaseTraitId) { if (bindingResult.hasErrors()) { return "edit_disease_trait"; } else { diseaseTraitRepository.save(diseaseTrait); return "redirect:/diseasetraits"; } } @Autowired  DiseaseTraitController(DiseaseTraitRepository diseaseTraitRepository, StudyRepository studyRepository); @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) String allDiseaseTraits(Model model); @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) String addDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait,
                                  BindingResult bindingResult,
                                  Model model, RedirectAttributes redirectAttributes); @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) String viewDiseaseTrait(Model model, @PathVariable Long diseaseTraitId); @RequestMapping(value = "/{diseaseTraitId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) String editDiseaseTrait(@Valid @ModelAttribute DiseaseTrait diseaseTrait,
                                   BindingResult bindingResult, @PathVariable Long diseaseTraitId); @RequestMapping(value = "/{diseaseTraitId}/delete", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) String viewDiseaseTraitToDelete(Model model, @PathVariable Long diseaseTraitId); @RequestMapping(value = "/{diseaseTraitId}/delete", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST) String deleteDiseaseTrait(@PathVariable Long diseaseTraitId, RedirectAttributes redirectAttributes); @ModelAttribute("diseaseTraits") List<DiseaseTrait> populateDiseaseTraits();  }