Skip to content

Commit

Permalink
[ELY-2621] Add a test that makes use of the RoleMapper#or method to R…
Browse files Browse the repository at this point in the history
…oleMappingTest
  • Loading branch information
ericrleung committed Oct 10, 2023
1 parent 8b2219b commit fb44b7c
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,41 @@ public void testIntersectionMappedRoles() {
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);
}

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

0 comments on commit fb44b7c

Please sign in to comment.