RoleServiceImpl extends BaseServiceImpl<Role> implements RoleService { @Override public Set<Role> getImplicitUserRoles(String name) { Set<Role> implicitRoles = new HashSet<>(7); switch (name) { case "SuperUser": implicitRoles.add(getByName("Auditor")); implicitRoles.add(getByName("Administrator")); implicitRoles.add(getByName("Deployer")); case "Deployer": case "Administrator": implicitRoles.add(getByName("Maintainer")); case "Maintainer": implicitRoles.add(getByName("Operator")); case "Auditor": case "Operator": implicitRoles.add(getByName("Monitor")); case "Monitor": break; default: throw new IllegalArgumentException("Unrecognized role: '" + name + "'"); } return implicitRoles; }  @Override Role getById(UUID id); @Override Role create(String name, String description); @Override Role getByName(String name); @Override Set<Role> getImplicitUserRoles(String name); @Override Set<Role> getImplicitPermittedRoles(String name); @Override Set<Role> getImplicitUserRoles(Role role); @Override Set<Role> getImplicitPermittedRoles(Role role); @Override @Produces @NamedRole Role produceRoleByName(InjectionPoint injectionPoint); @Override Role getOrCreateByName(String name, String description);  }
@Test public void implicitUserRolesForSuperUser() { Set<Role> implicitRoles = roleService.getImplicitUserRoles(superUser); assertEquals("SuperUser should have all 6 other roles as implicit roles", 6, implicitRoles.size()); assertTrue(implicitRoles.contains(monitor)); assertTrue(implicitRoles.contains(operator)); assertTrue(implicitRoles.contains(maintainer)); assertTrue(implicitRoles.contains(deployer)); assertTrue(implicitRoles.contains(administrator)); assertTrue(implicitRoles.contains(auditor)); }
@Test public void implicitUserRolesForMonitor() { Set<Role> implicitRoles = roleService.getImplicitUserRoles(monitor); assertEquals("Monitor should have no implicit roles", 0, implicitRoles.size()); }
@Test public void implicitUserRolesForMaintainer() { Set<Role> implicitRoles = roleService.getImplicitUserRoles(maintainer); assertEquals("Maintainer should have 2 other roles as implicit roles", 2, implicitRoles.size()); assertTrue(implicitRoles.contains(monitor)); assertTrue(implicitRoles.contains(operator)); }
@Test public void implicitUserRolesForDeployer() { Set<Role> implicitRoles = roleService.getImplicitUserRoles(deployer); assertEquals("Deployer should have 3 other roles as implicit roles", 3, implicitRoles.size()); assertTrue(implicitRoles.contains(monitor)); assertTrue(implicitRoles.contains(operator)); assertTrue(implicitRoles.contains(maintainer)); }
@Test public void implicitUserRolesForAdministrator() { Set<Role> implicitRoles = roleService.getImplicitUserRoles(administrator); assertEquals("Administrator should have 3 other roles as implicit roles", 3, implicitRoles.size()); assertTrue(implicitRoles.contains(monitor)); assertTrue(implicitRoles.contains(operator)); assertTrue(implicitRoles.contains(maintainer)); }