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 bfe6164
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,41 @@ public void testDifferenceRoles() {
assertEquals(1, 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 bfe6164

Please sign in to comment.