@Test void testGetRoles() { Sid sid1 = new GrantedAuthoritySid("ROLE_a"); Sid sid2 = new GrantedAuthoritySid("ROLE_b"); LinkedList expected = new LinkedList<>(); expected.addAll(Arrays.asList(sid2, sid1)); Role role = mock(Role.class); Role roleA = mock(Role.class); when(roleA.getName()).thenReturn("a"); Role roleB = mock(Role.class); when(roleB.getName()).thenReturn("b"); when(role.getIncludes()).thenReturn(Arrays.asList(roleA, roleB)); Query query = mock(Query.class); Query query1 = mock(Query.class); Query query2 = mock(Query.class); when(dataService.query(RoleMetadata.ROLE, Role.class)).thenReturn(query); doReturn(query).when(query).eq(RoleMetadata.NAME, "role1"); doReturn(query1).when(query).eq(RoleMetadata.NAME, "a"); doReturn(query2).when(query).eq(RoleMetadata.NAME, "b"); when(query.findOne()).thenReturn(role); when(query1.findOne()).thenReturn(mock(Role.class)); when(query2.findOne()).thenReturn(mock(Role.class)); when(userPermissionEvaluator.hasPermission( new EntityTypeIdentity(RoleMetadata.ROLE), EntityTypePermission.READ_DATA)) .thenReturn(true); assertTrue( userRoleTools .getRoles( Sets.newHashSet( new GrantedAuthoritySid("ROLE_role1"), new GrantedAuthoritySid("ROLE_a"), new GrantedAuthoritySid("ROLE_b"))) .containsAll(expected)); }
Set<Sid> getRoles(Sid sid) { Set<Sid> roles = new LinkedHashSet<>(); resolveRoles(sid, roles); return roles; }
UserRoleTools { Set<Sid> getRoles(Sid sid) { Set<Sid> roles = new LinkedHashSet<>(); resolveRoles(sid, roles); return roles; } }
UserRoleTools { Set<Sid> getRoles(Sid sid) { Set<Sid> roles = new LinkedHashSet<>(); resolveRoles(sid, roles); return roles; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); }
UserRoleTools { Set<Sid> getRoles(Sid sid) { Set<Sid> roles = new LinkedHashSet<>(); resolveRoles(sid, roles); return roles; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); void checkRoleExists(String role); void checkUserExists(String user); List<Sid> getSids(List<String> users, List<String> roles); static Optional<String> getUsername(Sid sid); static Optional<String> getRolename(Sid sid); static String getName(Sid sid); List<Sid> getRolesForSid(Sid sid); }
UserRoleTools { Set<Sid> getRoles(Sid sid) { Set<Sid> roles = new LinkedHashSet<>(); resolveRoles(sid, roles); return roles; } UserRoleTools(
      UserService userService,
      DataService dataService,
      UserPermissionEvaluator userPermissionEvaluator); void checkRoleExists(String role); void checkUserExists(String user); List<Sid> getSids(List<String> users, List<String> roles); static Optional<String> getUsername(Sid sid); static Optional<String> getRolename(Sid sid); static String getName(Sid sid); List<Sid> getRolesForSid(Sid sid); static final String ANONYMOUS; }