@Test public void showMessagesOfTypePage() throws Exception { String type = MessageType.REFERRAL_SHARE.toString(); MessageDto messageDto1 = mock(MessageDto.class); MessageDto messageDto2 = mock(MessageDto.class); MessageDto messageDto3 = mock(MessageDto.class); List<MessageDto> messages = Arrays.asList(messageDto1, messageDto2, messageDto3); when(messageService.getMessagesByType(MessageType.REFERRAL_SHARE)).thenReturn(messages); this.mockMvc.perform(get("/messages/{type}", type)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.model().attribute("type", type)) .andExpect(MockMvcResultMatchers.model().attribute("messages", messages)) .andExpect(MockMvcResultMatchers.view().name("messages/type")); }
@RequestMapping("/messages/{type}") public ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type) { model.addAttribute("type", type.toUpperCase()); model.addAttribute("messages", messageService.getMessagesByType(MessageType.valueOf(type.toUpperCase()))); return new ModelAndView("messages/type"); }
MessagesController extends AbstractController { @RequestMapping("/messages/{type}") public ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type) { model.addAttribute("type", type.toUpperCase()); model.addAttribute("messages", messageService.getMessagesByType(MessageType.valueOf(type.toUpperCase()))); return new ModelAndView("messages/type"); } }
MessagesController extends AbstractController { @RequestMapping("/messages/{type}") public ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type) { model.addAttribute("type", type.toUpperCase()); model.addAttribute("messages", messageService.getMessagesByType(MessageType.valueOf(type.toUpperCase()))); return new ModelAndView("messages/type"); } MessagesController(final MessageService messageService); }
MessagesController extends AbstractController { @RequestMapping("/messages/{type}") public ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type) { model.addAttribute("type", type.toUpperCase()); model.addAttribute("messages", messageService.getMessagesByType(MessageType.valueOf(type.toUpperCase()))); return new ModelAndView("messages/type"); } MessagesController(final MessageService messageService); @RequestMapping("/messages") ModelAndView showAllMessagesPage(final Model model); @RequestMapping("/messages/{type}") ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/add") ModelAndView showAddMessageToTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/{name}/edit") ModelAndView showEditPage(final Model model, @PathVariable String type, @PathVariable String name); @PostMapping("/messages/{type}/add") ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/edit") ModelAndView update(WebRequest request, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/delete") ModelAndView delete(final Model model, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); }
MessagesController extends AbstractController { @RequestMapping("/messages/{type}") public ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type) { model.addAttribute("type", type.toUpperCase()); model.addAttribute("messages", messageService.getMessagesByType(MessageType.valueOf(type.toUpperCase()))); return new ModelAndView("messages/type"); } MessagesController(final MessageService messageService); @RequestMapping("/messages") ModelAndView showAllMessagesPage(final Model model); @RequestMapping("/messages/{type}") ModelAndView showMessagesOfTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/add") ModelAndView showAddMessageToTypePage(final Model model, @PathVariable String type); @RequestMapping("/messages/{type}/{name}/edit") ModelAndView showEditPage(final Model model, @PathVariable String type, @PathVariable String name); @PostMapping("/messages/{type}/add") ModelAndView add(WebRequest request, @PathVariable String type, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/edit") ModelAndView update(WebRequest request, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes); @PostMapping("/messages/{type}/{name}/delete") ModelAndView delete(final Model model, @PathVariable String type, @PathVariable String name, RedirectAttributes redirectAttributes);  }