@Test public void testAllDiseaseTraits() throws Exception { List<DiseaseTrait> allTraits = Arrays.asList(DISEASE_TRAIT_1, DISEASE_TRAIT_2); when(diseaseTraitRepository.findAll(Matchers.any(Sort.class))).thenReturn(allTraits); mockMvc.perform(get("/diseasetraits").accept(MediaType.TEXT_HTML_VALUE)) .andExpect(status().isOk()) .andExpect(view().name("disease_traits")) .andExpect(model().attributeExists("diseaseTrait")) .andExpect(model().attributeExists("diseaseTraits")) .andExpect(model().attributeExists("totaldiseaseTraits")) .andExpect(model().attribute("diseaseTrait", instanceOf(DiseaseTrait.class))) .andExpect(model().attribute("diseaseTraits", instanceOf(Collection.class))) .andExpect(model().attribute("diseaseTraits", hasSize(2))) .andExpect(model().attribute("totaldiseaseTraits", instanceOf(Integer.class))) .andExpect(model().attribute("totaldiseaseTraits", equalTo(2))); verifyZeroInteractions(studyRepository); }
@RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) public String allDiseaseTraits(Model model) { Sort sort = sortByTraitAsc(); List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort); model.addAttribute("diseaseTraits", allDiseaseTraits); model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size()); model.addAttribute("diseaseTrait", new DiseaseTrait()); return "disease_traits"; }
DiseaseTraitController { @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) public String allDiseaseTraits(Model model) { Sort sort = sortByTraitAsc(); List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort); model.addAttribute("diseaseTraits", allDiseaseTraits); model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size()); model.addAttribute("diseaseTrait", new DiseaseTrait()); return "disease_traits"; } }
DiseaseTraitController { @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) public String allDiseaseTraits(Model model) { Sort sort = sortByTraitAsc(); List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort); model.addAttribute("diseaseTraits", allDiseaseTraits); model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size()); model.addAttribute("diseaseTrait", new DiseaseTrait()); return "disease_traits"; } @Autowired  DiseaseTraitController(DiseaseTraitRepository diseaseTraitRepository, StudyRepository studyRepository); }
DiseaseTraitController { @RequestMapping(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) public String allDiseaseTraits(Model model) { Sort sort = sortByTraitAsc(); List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort); model.addAttribute("diseaseTraits", allDiseaseTraits); model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size()); model.addAttribute("diseaseTrait", new DiseaseTrait()); return "disease_traits"; } @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(produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.GET) public String allDiseaseTraits(Model model) { Sort sort = sortByTraitAsc(); List<DiseaseTrait> allDiseaseTraits = diseaseTraitRepository.findAll(sort); model.addAttribute("diseaseTraits", allDiseaseTraits); model.addAttribute("totaldiseaseTraits", allDiseaseTraits.size()); model.addAttribute("diseaseTrait", new DiseaseTrait()); return "disease_traits"; } @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();  }