RoleServiceImpl extends WaspServiceImpl implements RoleService { @Override public List<String> getCompleteSortedRoleList(User user){ Set<String> rolesAsSet = new HashSet<String>(); List<Userrole> userroles = user.getUserrole(); for(Userrole userrole : userroles){ rolesAsSet.add(userrole.getRole().getName()); } List<LabUser> labUsers = user.getLabUser(); for(LabUser labUser : labUsers){ String piLastName = labUser.getLab().getUser().getLastName(); String roleName = labUser.getRole().getRoleName(); if(roleName.equals("lm") || roleName.equals("lu")){ rolesAsSet.add(labUser.getRole().getName() + " (" + piLastName + " Lab)"); } else{ rolesAsSet.add(labUser.getRole().getName()); } } Map<String, Integer> departmentuserQueryMap = new HashMap<String, Integer>(); departmentuserQueryMap.put("userId", user.getId()); List<DepartmentUser> departmentUsers = departmentUserDao.findByMap(departmentuserQueryMap); if(departmentUsers.size() > 0){ rolesAsSet.add("Dep't. Admin."); } List<String> roles = new ArrayList<String>(rolesAsSet); Collections.sort(roles); return roles; }  void setDepartmentUserDao(DepartmentUserDao departmentUserDao); @Override //SuperUser, Facility Manager, Facility Tech, System Admin, Facility Admin, PI, Lab Manager, Lab Member, Department Admin. List<String> getUniqueSortedRoleList(User user); @Override //SuperUser, Facility Manager, Facility Tech, System Admin, Facility Admin, PI (with lab name as PI's last name), Lab Manager (with PI's last name), Lab Member (with PI's last name), Department Admin (departments NOT listed as could be long list). List<String> getCompleteSortedRoleList(User user); @Override List<Role> convertMetaRoleVisibilityDelimitedStringToRoleList(String roleVisibility); @Override Role getRoleByRolename(String roleName); @Override String convertRoleListToMetaRoleVisibilityDelimitedString(List<Role> roleList); @Override boolean metaRoleVisibilityDelimitedStringContainsRole(String roleVisibility, Role role); @Override String addRoleToMetaRoleVisibility(String roleVisibility, Role role); @Override String removeRoleFromMetaRoleVisibility(String roleVisibility, Role role);  }
@Test (groups = "unit-tests-service-objects") public void getCompleteSortedRoleList() { Userrole userrole = new Userrole(); List<Userrole> userroles = new ArrayList<Userrole>(); User user = new User(); user.setLastName("Jones"); Lab lab = new Lab(); lab.setUser(user); Role role1 = new Role(); role1.setId(1); role1.setName("Facility Manager"); userrole.setRole(role1); userroles.add(userrole); User testUser1 = new User(); LabUser labUser = new LabUser(); List<LabUser> labUsers = new ArrayList<LabUser>(); Role role2 = new Role(); role2.setId(2); role2.setRoleName("pi"); role2.setName("Primary Investigator"); labUser.setRole(role2); labUser.setLab(lab); labUsers.add(labUser); LabUser labUser2 = new LabUser(); List<LabUser> labUsers2 = new ArrayList<LabUser>(); User testUser2 = new User(); Role role3 = new Role(); role3.setId(3); role3.setRoleName("lm"); role3.setName("Lab Manager"); labUser2.setRole(role3); labUser2.setLab(lab); labUsers2.add(labUser2); testUser1.setUserrole(userroles); testUser1.setLabUser(labUsers); testUser2.setUserrole(userroles); testUser2.setLabUser(labUsers2); Map<String, Integer> departmentuserQueryMap = new HashMap<String, Integer>(); departmentuserQueryMap.put("userId", null); List<DepartmentUser> departmentUsers = new ArrayList<DepartmentUser>(); List<String> expectedListOfRoles1 = new ArrayList<String>(); expectedListOfRoles1.add("Facility Manager"); expectedListOfRoles1.add("Primary Investigator"); List<String> expectedListOfRoles2 = new ArrayList<String>(); expectedListOfRoles2.add("Facility Manager"); expectedListOfRoles2.add("Lab Manager (Jones Lab)"); roleServiceImpl.setDepartmentUserDao(mockDepartmentUserDao); expect(mockDepartmentUserDao.findByMap(departmentuserQueryMap)).andReturn(departmentUsers); expect(mockDepartmentUserDao.findByMap(departmentuserQueryMap)).andReturn(departmentUsers); replay(mockDepartmentUserDao); Assert.assertEquals(expectedListOfRoles1, roleServiceImpl.getCompleteSortedRoleList(testUser1)); Assert.assertEquals(expectedListOfRoles2, roleServiceImpl.getCompleteSortedRoleList(testUser2)); verify(mockDepartmentUserDao); }