UserRoleConfigFacadeEjb implements UserRoleConfigFacade { @Override public Set<UserRight> getEffectiveUserRights(UserRole... userRoles) { Set<UserRight> userRights = EnumSet.noneOf(UserRight.class); for (UserRole userRole : userRoles) { UserRoleConfig userRoleConfig = userRoleConfigService.getByUserRole(userRole); if (userRoleConfig != null) { userRights.addAll(userRoleConfig.getUserRights()); } else { userRights.addAll(userRole.getDefaultUserRights()); } } return userRights; }  @Override List<UserRoleConfigDto> getAllAfter(Date since); @Override List<UserRoleConfigDto> getAll(); @Override List<String> getAllUuids(); @Override List<String> getDeletedUuids(Date since); @Override UserRoleConfigDto getByUuid(String uuid); @Override UserRoleConfigDto saveUserRoleConfig(UserRoleConfigDto dto); @Override void deleteUserRoleConfig(UserRoleConfigDto dto); @Override Set<UserRight> getEffectiveUserRights(UserRole... userRoles); UserRoleConfig fromDto(UserRoleConfigDto source); static UserRoleConfigDto toDto(UserRoleConfig source);  }
@Test public void testGetEffectiveUserRights() { Set<UserRight> supervisorRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR); assertThat(supervisorRights, is(UserRole.SURVEILLANCE_SUPERVISOR.getDefaultUserRights())); UserRoleConfigDto userRoleConfig = UserRoleConfigDto.build(UserRole.SURVEILLANCE_SUPERVISOR); userRoleConfig = getUserRoleConfigFacade().saveUserRoleConfig(userRoleConfig); supervisorRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR); assertThat(supervisorRights, is(IsEmptyCollection.empty())); userRoleConfig.getUserRights().add(UserRight.CASE_CREATE); userRoleConfig.getUserRights().add(UserRight.CASE_EDIT); userRoleConfig = getUserRoleConfigFacade().saveUserRoleConfig(userRoleConfig); supervisorRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR); assertThat(supervisorRights, is(new HashSet<UserRight>(Arrays.asList(UserRight.CASE_CREATE, UserRight.CASE_EDIT)))); Set<UserRight> mixedUserRights = getUserRoleConfigFacade().getEffectiveUserRights(UserRole.SURVEILLANCE_SUPERVISOR, UserRole.NATIONAL_OBSERVER); Set<UserRight> expectedUserRights = new HashSet<UserRight>(Arrays.asList(UserRight.CASE_CREATE, UserRight.CASE_EDIT)); expectedUserRights.addAll(UserRole.NATIONAL_OBSERVER.getDefaultUserRights()); assertThat(mixedUserRights, is(expectedUserRights)); }