RoleServiceImpl extends BaseServiceImpl<Role> implements RoleService { @Override public Set<Role> getImplicitPermittedRoles(String name) { Set<Role> implicitRoles = new HashSet<>(7); switch (name) { case "Monitor": implicitRoles.add(getByName("Operator")); implicitRoles.add(getByName("Auditor")); case "Operator": implicitRoles.add(getByName("Maintainer")); case "Maintainer": implicitRoles.add(getByName("Administrator")); implicitRoles.add(getByName("Deployer")); case "Deployer": case "Administrator": case "Auditor": implicitRoles.add(getByName("SuperUser")); case "SuperUser": 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 implicitPermittedRolesForMonitor() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(monitor); assertEquals("Operator means that 6 other roles have also access to the operation.", 6, implicitRoles.size()); assertTrue(implicitRoles.contains(operator)); assertTrue(implicitRoles.contains(maintainer)); assertTrue(implicitRoles.contains(deployer)); assertTrue(implicitRoles.contains(administrator)); assertTrue(implicitRoles.contains(auditor)); assertTrue(implicitRoles.contains(superUser)); }
@Test public void implicitPermittedRolesForOperator() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(operator); assertEquals("Operator means that 4 other roles have also access to the operation.", 4, implicitRoles.size()); assertTrue(implicitRoles.contains(maintainer)); assertTrue(implicitRoles.contains(deployer)); assertTrue(implicitRoles.contains(administrator)); assertTrue(implicitRoles.contains(superUser)); }
@Test public void implicitPermittedRolesForMaintainer() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(maintainer); assertEquals("Maintainer means that 3 other roles have also access to the operation.", 3, implicitRoles.size()); assertTrue(implicitRoles.contains(deployer)); assertTrue(implicitRoles.contains(administrator)); assertTrue(implicitRoles.contains(superUser)); }
@Test public void implicitPermittedRolesForDeployer() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(deployer); assertEquals("Deployer means that 1 other roles have also access to the operation.", 1, implicitRoles.size()); assertTrue(implicitRoles.contains(superUser)); }
@Test public void implicitPermittedRolesForAdministrator() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(administrator); assertEquals("Administrator means that 1 other roles have also access to the operation.", 1, implicitRoles .size()); assertTrue(implicitRoles.contains(superUser)); }
@Test public void implicitPermittedRolesForAuditor() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(auditor); assertEquals("Auditor means that 1 other roles have also access to the operation.", 1, implicitRoles.size()); assertTrue(implicitRoles.contains(superUser)); }
@Test public void implicitPermittedRolesForSuperUser() { Set<Role> implicitRoles = roleService.getImplicitPermittedRoles(superUser); assertEquals("No other roles can execute operations marked with SuperUser.", 0, implicitRoles.size()); }