Skip to content

Commit

Permalink
[ELY-2620] Add a test that makes use of the RoleMapper#and method to …
Browse files Browse the repository at this point in the history
…RoleMappingTest
  • Loading branch information
ericrleung committed Oct 6, 2023
1 parent f851894 commit 1a7af6b
Showing 1 changed file with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,76 @@ public void testDifferenceRoles() {
assertEquals(1, count);
}

@Test
public void testUnionMappedRoles() {
Roles roles = createRoles("foo", "joe");

Map<String, Set<String>> mappingMap1 = new HashMap<>();
mappingMap1.put("foo", createSet("bar", "role"));

RoleMapper mapper1 = new MappedRoleMapper.Builder()
.setRoleMap(mappingMap1).build();

Map<String, Set<String>> mappingMap2 = new HashMap<>();
mappingMap2.put("foo", createSet("bar", "test"));

RoleMapper mapper2 = new MappedRoleMapper.Builder()
.setRoleMap(mappingMap2).build();

RoleMapper mapper3 = mapper1.or(mapper2);

Roles mappedRoles = mapper3.mapRoles(roles);

assertTrue(mappedRoles.contains("bar"));
assertTrue(mappedRoles.contains("role"));
assertTrue(mappedRoles.contains("test"));
assertFalse(mappedRoles.contains("foo"));
assertFalse(mappedRoles.contains("joe"));

Iterator<String> iterator = mappedRoles.iterator();
int count = 0;
while (iterator.hasNext()) {
iterator.next();
count++;
}
assertEquals(3, count);
}

@Test
public void testIntersectionMappedRoles() {
Roles roles = createRoles("foo", "joe");

Map<String, Set<String>> mappingMap1 = new HashMap<>();
mappingMap1.put("foo", createSet("bar", "role"));

RoleMapper mapper1 = new MappedRoleMapper.Builder()
.setRoleMap(mappingMap1).build();

Map<String, Set<String>> mappingMap2 = new HashMap<>();
mappingMap2.put("foo", createSet("bar", "test"));

RoleMapper mapper2 = new MappedRoleMapper.Builder()
.setRoleMap(mappingMap2).build();

RoleMapper mapper3 = mapper1.and(mapper2);

Roles mappedRoles = mapper3.mapRoles(roles);

assertTrue(mappedRoles.contains("bar"));
assertFalse(mappedRoles.contains("role"));
assertFalse(mappedRoles.contains("test"));
assertFalse(mappedRoles.contains("foo"));
assertFalse(mappedRoles.contains("joe"));

Iterator<String> iterator = mappedRoles.iterator();
int count = 0;
while (iterator.hasNext()) {
iterator.next();
count++;
}
assertEquals(1, count);
}

private Set<String> createSet(String... values) {
HashSet<String> set = new HashSet<>();
for (String s : values) set.add(s);
Expand Down

0 comments on commit 1a7af6b

Please sign in to comment.