@Test public void deleteRoleCustomFalseTest() throws Exception { DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository); RoleEntity roleEntity = new RoleEntity("name", false); roleEntity.setId(1L); Mockito.when(roleRepository.findById(Mockito.any())).thenReturn(Optional.of(roleEntity)); try { authorizationUtility.deleteRole(1L); fail("Custom parameter of roleEntity set to 'false' did not throw expected AlertForbiddenOperationException."); } catch (AlertForbiddenOperationException e) { assertNotNull(e); } }
@Override public void deleteRole(Long roleId) throws AlertForbiddenOperationException { Optional<RoleEntity> foundRole = roleRepository.findById(roleId); if (foundRole.isPresent()) { RoleEntity roleEntity = foundRole.get(); if (BooleanUtils.isFalse(roleEntity.getCustom())) { throw new AlertForbiddenOperationException("Cannot delete the role '" + roleId + "' because it is not a custom role."); } roleRepository.deleteById(roleEntity.getId()); } }
DefaultRoleAccessor implements RoleAccessor { @Override public void deleteRole(Long roleId) throws AlertForbiddenOperationException { Optional<RoleEntity> foundRole = roleRepository.findById(roleId); if (foundRole.isPresent()) { RoleEntity roleEntity = foundRole.get(); if (BooleanUtils.isFalse(roleEntity.getCustom())) { throw new AlertForbiddenOperationException("Cannot delete the role '" + roleId + "' because it is not a custom role."); } roleRepository.deleteById(roleEntity.getId()); } } }
DefaultRoleAccessor implements RoleAccessor { @Override public void deleteRole(Long roleId) throws AlertForbiddenOperationException { Optional<RoleEntity> foundRole = roleRepository.findById(roleId); if (foundRole.isPresent()) { RoleEntity roleEntity = foundRole.get(); if (BooleanUtils.isFalse(roleEntity.getCustom())) { throw new AlertForbiddenOperationException("Cannot delete the role '" + roleId + "' because it is not a custom role."); } roleRepository.deleteById(roleEntity.getId()); } } @Autowired  DefaultRoleAccessor(RoleRepository roleRepository, UserRoleRepository userRoleRepository, PermissionMatrixRepository permissionMatrixRepository,
        RegisteredDescriptorRepository registeredDescriptorRepository, ConfigContextRepository configContextRepository); }
DefaultRoleAccessor implements RoleAccessor { @Override public void deleteRole(Long roleId) throws AlertForbiddenOperationException { Optional<RoleEntity> foundRole = roleRepository.findById(roleId); if (foundRole.isPresent()) { RoleEntity roleEntity = foundRole.get(); if (BooleanUtils.isFalse(roleEntity.getCustom())) { throw new AlertForbiddenOperationException("Cannot delete the role '" + roleId + "' because it is not a custom role."); } roleRepository.deleteById(roleEntity.getId()); } } @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 void deleteRole(Long roleId) throws AlertForbiddenOperationException { Optional<RoleEntity> foundRole = roleRepository.findById(roleId); if (foundRole.isPresent()) { RoleEntity roleEntity = foundRole.get(); if (BooleanUtils.isFalse(roleEntity.getCustom())) { throw new AlertForbiddenOperationException("Cannot delete the role '" + roleId + "' because it is not a custom role."); } roleRepository.deleteById(roleEntity.getId()); } } @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);  }