@Test public void getRolesTest() { RoleEntity roleEntity = new RoleEntity(DefaultUserRole.ALERT_USER.name(), true); roleEntity.setId(1L); Mockito.when(roleRepository.findAll()).thenReturn(List.of(roleEntity)); DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository); Set<UserRoleModel> userRoleModelsSet = authorizationUtility.getRoles(); UserRoleModel expectedUserRoleModel = createUserRoleModel(1L, DefaultUserRole.ALERT_USER.name(), true); assertEquals(1, userRoleModelsSet.size()); assertTrue(userRoleModelsSet.contains(expectedUserRoleModel)); }
@Override public Set<UserRoleModel> getRoles() { List<RoleEntity> roleList = roleRepository.findAll(); Set<UserRoleModel> userRoles = new LinkedHashSet<>(); for (RoleEntity entity : roleList) { userRoles.add(new UserRoleModel(entity.getId(), entity.getRoleName(), entity.getCustom(), readPermissionsForRole(entity.getId()))); } return userRoles; }
DefaultRoleAccessor implements RoleAccessor { @Override public Set<UserRoleModel> getRoles() { List<RoleEntity> roleList = roleRepository.findAll(); Set<UserRoleModel> userRoles = new LinkedHashSet<>(); for (RoleEntity entity : roleList) { userRoles.add(new UserRoleModel(entity.getId(), entity.getRoleName(), entity.getCustom(), readPermissionsForRole(entity.getId()))); } return userRoles; } }
DefaultRoleAccessor implements RoleAccessor { @Override public Set<UserRoleModel> getRoles() { List<RoleEntity> roleList = roleRepository.findAll(); Set<UserRoleModel> userRoles = new LinkedHashSet<>(); for (RoleEntity entity : roleList) { userRoles.add(new UserRoleModel(entity.getId(), entity.getRoleName(), entity.getCustom(), readPermissionsForRole(entity.getId()))); } return userRoles; } @Autowired  DefaultRoleAccessor(RoleRepository roleRepository, UserRoleRepository userRoleRepository, PermissionMatrixRepository permissionMatrixRepository,
        RegisteredDescriptorRepository registeredDescriptorRepository, ConfigContextRepository configContextRepository); }
DefaultRoleAccessor implements RoleAccessor { @Override public Set<UserRoleModel> getRoles() { List<RoleEntity> roleList = roleRepository.findAll(); Set<UserRoleModel> userRoles = new LinkedHashSet<>(); for (RoleEntity entity : roleList) { userRoles.add(new UserRoleModel(entity.getId(), entity.getRoleName(), entity.getCustom(), readPermissionsForRole(entity.getId()))); } return userRoles; } @Autowired  DefaultRoleAccessor(RoleRepository roleRepository, UserRoleRepository userRoleRepository, PermissionMatrixRepository permissionMatrixRepository,
        RegisteredDescriptorRepository registeredDescriptorRepository, ConfigContextRepository configContextRepository); @Override Set<UserRoleModel> getRoles(); @Override Set<UserRoleModel> getRoles(Collection<Long> roleIds); @Override boolean doesRoleNameExist(String name); @Override UserRoleModel createRole(String roleName); @Override UserRoleModel createRoleWithPermissions(String roleName, PermissionMatrixModel permissionMatrix); @Override void updateRoleName(Long roleId, String roleName); @Override PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix); @Override void deleteRole(Long roleId); @Override void updateUserRoles(Long userId, Collection<UserRoleModel> roles); @Override PermissionMatrixModel mergePermissionsForRoles(Collection<String> roleNames); @Override PermissionMatrixModel readPermissionsForRole(Long roleId); }
DefaultRoleAccessor implements RoleAccessor { @Override public Set<UserRoleModel> getRoles() { List<RoleEntity> roleList = roleRepository.findAll(); Set<UserRoleModel> userRoles = new LinkedHashSet<>(); for (RoleEntity entity : roleList) { userRoles.add(new UserRoleModel(entity.getId(), entity.getRoleName(), entity.getCustom(), readPermissionsForRole(entity.getId()))); } return userRoles; } @Autowired  DefaultRoleAccessor(RoleRepository roleRepository, UserRoleRepository userRoleRepository, PermissionMatrixRepository permissionMatrixRepository,
        RegisteredDescriptorRepository registeredDescriptorRepository, ConfigContextRepository configContextRepository); @Override Set<UserRoleModel> getRoles(); @Override Set<UserRoleModel> getRoles(Collection<Long> roleIds); @Override boolean doesRoleNameExist(String name); @Override UserRoleModel createRole(String roleName); @Override UserRoleModel createRoleWithPermissions(String roleName, PermissionMatrixModel permissionMatrix); @Override void updateRoleName(Long roleId, String roleName); @Override PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix); @Override void deleteRole(Long roleId); @Override void updateUserRoles(Long userId, Collection<UserRoleModel> roles); @Override PermissionMatrixModel mergePermissionsForRoles(Collection<String> roleNames); @Override PermissionMatrixModel readPermissionsForRole(Long roleId);  }