@Test public void testIndex() throws Exception { AuthenticatedUser currentUser = mock(AuthenticatedUser.class); when(userContext.getCurrentUser()).thenReturn(currentUser); when(currentUser.getUsername()).thenReturn("username"); Users users= mock(Users.class); when(usersRepository.loadUserByUsername("username")).thenReturn(users); Set<GrantedAuthority> auths=new HashSet<GrantedAuthority>(); auths.add(new SimpleGrantedAuthority("ROLE_USER")); when(users.getAuthorities()).thenReturn(auths); mockMvc.perform(get("/index.html")) .andExpect(view().name("redirect:/patients/home.html")); }
@RequestMapping(value = "index.html", method = RequestMethod.GET) public String index(Model model, HttpServletRequest request) { AuthenticatedUser currentUser = userContext.getCurrentUser(); if (!currentUser.getUsername().equals("anonymousUser")) { Users users = usersRepository.loadUserByUsername(currentUser .getUsername()); if (users != null) { if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_ADMIN"))) return "redirect:/Administrator/adminHome.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_USER"))) return "redirect:/patients/home.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_SYSADMIN"))) return "redirect:/sysadmin/valueSetList"; } } return "views/index"; }
HomeController { @RequestMapping(value = "index.html", method = RequestMethod.GET) public String index(Model model, HttpServletRequest request) { AuthenticatedUser currentUser = userContext.getCurrentUser(); if (!currentUser.getUsername().equals("anonymousUser")) { Users users = usersRepository.loadUserByUsername(currentUser .getUsername()); if (users != null) { if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_ADMIN"))) return "redirect:/Administrator/adminHome.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_USER"))) return "redirect:/patients/home.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_SYSADMIN"))) return "redirect:/sysadmin/valueSetList"; } } return "views/index"; } }
HomeController { @RequestMapping(value = "index.html", method = RequestMethod.GET) public String index(Model model, HttpServletRequest request) { AuthenticatedUser currentUser = userContext.getCurrentUser(); if (!currentUser.getUsername().equals("anonymousUser")) { Users users = usersRepository.loadUserByUsername(currentUser .getUsername()); if (users != null) { if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_ADMIN"))) return "redirect:/Administrator/adminHome.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_USER"))) return "redirect:/patients/home.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_SYSADMIN"))) return "redirect:/sysadmin/valueSetList"; } } return "views/index"; }  }
HomeController { @RequestMapping(value = "index.html", method = RequestMethod.GET) public String index(Model model, HttpServletRequest request) { AuthenticatedUser currentUser = userContext.getCurrentUser(); if (!currentUser.getUsername().equals("anonymousUser")) { Users users = usersRepository.loadUserByUsername(currentUser .getUsername()); if (users != null) { if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_ADMIN"))) return "redirect:/Administrator/adminHome.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_USER"))) return "redirect:/patients/home.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_SYSADMIN"))) return "redirect:/sysadmin/valueSetList"; } } return "views/index"; }  @RequestMapping(value = "/", method = RequestMethod.GET, produces = "text/html") String home(Model model); @RequestMapping(value = "/keep-alive", method = RequestMethod.GET) @ResponseBody void keepAlive(); @RequestMapping(value = "index.html", method = RequestMethod.GET) String index(Model model, HttpServletRequest request); @RequestMapping(value = "education_center_mainpage.html", method = RequestMethod.GET) String educationMainpage(Model model); @RequestMapping(value = "privacy_consent.html", method = RequestMethod.GET) String privacyConsent(Model model); @RequestMapping(value = "about_consent2share.html", method = RequestMethod.GET) String aboutConsent2Share(Model model); @RequestMapping(value = "information_shared.html", method = RequestMethod.GET) String informationShared(Model model); @RequestMapping(value = "faq_page.html", method = RequestMethod.GET) String faqpage(Model model); @RequestMapping(value = "defaultLoginPage.html", method = RequestMethod.GET) String roleDispatcher(Model model, HttpServletRequest request); @RequestMapping(value = "error.html") String error(HttpServletRequest request, Model model); }
HomeController { @RequestMapping(value = "index.html", method = RequestMethod.GET) public String index(Model model, HttpServletRequest request) { AuthenticatedUser currentUser = userContext.getCurrentUser(); if (!currentUser.getUsername().equals("anonymousUser")) { Users users = usersRepository.loadUserByUsername(currentUser .getUsername()); if (users != null) { if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_ADMIN"))) return "redirect:/Administrator/adminHome.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_USER"))) return "redirect:/patients/home.html"; else if (users.getAuthorities().contains( new SimpleGrantedAuthority("ROLE_SYSADMIN"))) return "redirect:/sysadmin/valueSetList"; } } return "views/index"; }  @RequestMapping(value = "/", method = RequestMethod.GET, produces = "text/html") String home(Model model); @RequestMapping(value = "/keep-alive", method = RequestMethod.GET) @ResponseBody void keepAlive(); @RequestMapping(value = "index.html", method = RequestMethod.GET) String index(Model model, HttpServletRequest request); @RequestMapping(value = "education_center_mainpage.html", method = RequestMethod.GET) String educationMainpage(Model model); @RequestMapping(value = "privacy_consent.html", method = RequestMethod.GET) String privacyConsent(Model model); @RequestMapping(value = "about_consent2share.html", method = RequestMethod.GET) String aboutConsent2Share(Model model); @RequestMapping(value = "information_shared.html", method = RequestMethod.GET) String informationShared(Model model); @RequestMapping(value = "faq_page.html", method = RequestMethod.GET) String faqpage(Model model); @RequestMapping(value = "defaultLoginPage.html", method = RequestMethod.GET) String roleDispatcher(Model model, HttpServletRequest request); @RequestMapping(value = "error.html") String error(HttpServletRequest request, Model model);  }