RoleController extends AbstractFormController { public ModelAndView defaultView(String agencyFilter) { List roles = agencyUserManager.getRolesForLoggedInUser(); List agencies = null; if (authorityManager.hasPrivilege(Privilege.MANAGE_ROLES, Privilege.SCOPE_ALL)) { agencies = agencyUserManager.getAgencies(); } else { User loggedInUser = AuthUtil.getRemoteUserObject(); Agency usersAgency = loggedInUser.getAgency(); agencies = new ArrayList<Agency>(); agencies.add(usersAgency); } RoleCommand aRoleCmd = new RoleCommand(); aRoleCmd.setAgencyFilter(agencyFilter); ModelAndView mav = new ModelAndView(); mav.addObject(RoleCommand.MDL_ROLES, roles); mav.addObject(RoleCommand.MDL_AGENCIES, agencies); mav.addObject(Constants.GBL_CMD_DATA, aRoleCmd); mav.setViewName("Roles"); return mav; } RoleController(); @Override void initBinder(HttpServletRequest request, ServletRequestDataBinder binder); ModelAndView defaultView(String agencyFilter); void setAgencyUserManager(AgencyUserManager agencyUserManager); void setMessageSource(MessageSource messageSource); void setAuthorityManager(AuthorityManager authorityManager);  }
@Test public final void testDefaultView() { this.testSetAgencyUserManager(); this.testSetAuthorityManager(); this.testSetMessageSource(); this.removeAllCurrentUserPrivileges(); String agencyFilter = "Dummy"; ModelAndView mav = testInstance.defaultView(agencyFilter); assertTrue(mav != null); assertTrue(mav.getViewName().equals("Roles")); List roles = (List)mav.getModel().get(RoleCommand.MDL_ROLES); assertTrue(roles != null); assertFalse(roles.isEmpty()); RoleCommand command = (RoleCommand)mav.getModel().get("command"); assertTrue(command != null); assertTrue(agencyFilter.equals(command.getAgencyFilter())); List<Agency> agencies = (List<Agency>)mav.getModel().get(RoleCommand.MDL_AGENCIES); assertTrue(agencies != null); assertTrue(agencies.size() == 1); this.removeAllCurrentUserPrivileges(); this.addCurrentUserPrivilege(Privilege.SCOPE_AGENCY, Privilege.MANAGE_ROLES); mav = testInstance.defaultView(agencyFilter); assertTrue(mav != null); assertTrue(mav.getViewName().equals("Roles")); roles = (List)mav.getModel().get(RoleCommand.MDL_ROLES); assertTrue(roles != null); assertFalse(roles.isEmpty()); command = (RoleCommand)mav.getModel().get("command"); assertTrue(command != null); assertTrue(agencyFilter.equals(command.getAgencyFilter())); agencies = (List<Agency>)mav.getModel().get(RoleCommand.MDL_AGENCIES); assertTrue(agencies != null); assertTrue(agencies.size() == 1); this.removeAllCurrentUserPrivileges(); this.addCurrentUserPrivilege(Privilege.SCOPE_ALL, Privilege.MANAGE_ROLES); mav = testInstance.defaultView(agencyFilter); assertTrue(mav != null); assertTrue(mav.getViewName().equals("Roles")); roles = (List)mav.getModel().get(RoleCommand.MDL_ROLES); assertTrue(roles != null); assertFalse(roles.isEmpty()); command = (RoleCommand)mav.getModel().get("command"); assertTrue(command != null); assertTrue(agencyFilter.equals(command.getAgencyFilter())); agencies = (List<Agency>)mav.getModel().get(RoleCommand.MDL_AGENCIES); assertTrue(agencies != null); assertTrue(agencies.size() > 1); }