apply plugin: 'elasticsearch.internal-yaml-rest-test'

import org.elasticsearch.gradle.util.GradleUtils

dependencies {
  testImplementation project(xpackModule('core'))
  testImplementation(testArtifact(project(xpackModule('core'))))
  testImplementation project(':test:yaml-rest-runner')
  testImplementation project(':x-pack:qa:multi-project:yaml-test-framework')
  testImplementation(testArtifact(project(":x-pack:plugin:security:qa:service-account"), "javaRestTest"))
  restXpackTestConfig project(path: ':x-pack:plugin:downsample:qa:rest', configuration: "basicRestSpecs")
  restXpackTestConfig project(path: ':x-pack:plugin:stack', configuration: "basicRestSpecs")
}

// let the yamlRestTests see the classpath of test
GradleUtils.extendSourceSet(project, "test", "yamlRestTest", tasks.named("yamlRestTest"))

restResources {
  restTests {
    includeXpack '*'
  }
}

tasks.named("yamlRestTest").configure {
  usesDefaultDistribution("to be triaged")
  ArrayList<String> blacklist = [
    /* These tests don't work on multi-project yet - we need to go through each of them and make them work */
    // These analytics tests work in MP mode, they just don't work with security enabled.
    '^analytics/boxplot/*',
    '^analytics/histogram/*',
    '^analytics/moving_percentiles/*',
    '^analytics/top_metrics/*',
    '^data_streams/10_data_stream_resolvability/*',
    '^health/10_usage/*', // The usage API is project-aware, this test just fails on the project-awareness of the SLM health indicator
    '^migration/10_get_feature_upgrade_status/*',
    '^migration/20_post_feature_upgrade/*',
    '^ml/3rd_party_deployment/*',
    '^ml/bucket_correlation_agg/*',
    '^ml/bucket_count_ks_test_agg/*',
    '^ml/calendar_crud/*',
    '^ml/categorization_agg/*',
    '^ml/change_point_agg/*',
    '^ml/custom_all_field/*',
    '^ml/data_frame_analytics_cat_apis/*',
    '^ml/data_frame_analytics_crud/*',
    '^ml/datafeed_cat_apis/*',
    '^ml/datafeeds_crud/*',
    '^ml/delete_expired_data/*',
    '^ml/delete_job_force/*',
    '^ml/explain_data_frame_analytics/*',
    '^ml/filter_crud/*',
    '^ml/forecast/*',
    '^ml/frequent_item_sets_agg/*',
    '^ml/get_datafeed_stats/*',
    '^ml/get_datafeeds/*',
    '^ml/get_memory_stats/*',
    '^ml/get_model_snapshots/*',
    '^ml/get_model_snapshots/*/*',
    '^ml/get_trained_model_stats/*',
    '^ml/inference_crud/*',
    '^ml/inference_processor/*',
    '^ml/job_cat_apis/*',
    '^ml/job_groups/*',
    '^ml/jobs_crud/*',
    '^ml/jobs_get/*',
    '^ml/jobs_get_result_buckets/*',
    '^ml/jobs_get_result_categories/*',
    '^ml/jobs_get_result_influencers/*',
    '^ml/jobs_get_result_overall_buckets/*',
    '^ml/jobs_get_result_records/*',
    '^ml/jobs_get_stats/*',
    '^ml/learning_to_rank_rescorer/*',
    '^ml/ml_anomalies_default_mappings/*',
    '^ml/ml_info/*',
    '^ml/p_value_significant_term_score/*',
    '^ml/pipeline_inference/*',
    '^ml/post_data/*',
    '^ml/preview_data_frame_analytics/*',
    '^ml/preview_datafeed/*',
    '^ml/reset_job/*',
    '^ml/revert_model_snapshot/*',
    '^ml/search_knn_query_vector_builder/*',
    '^ml/set_upgrade_mode/*',
    '^ml/sparse_vector_search/*',
    '^ml/start_data_frame_analytics/*',
    '^ml/start_stop_datafeed/*',
    '^ml/stop_data_frame_analytics/*',
    '^ml/stop_data_frame_analytics/Test stop with inconsistent body/param ids',
    '^ml/text_embedding_search/*',
    '^ml/text_expansion_search/*',
    '^ml/text_expansion_search_rank_features/*',
    '^ml/text_expansion_search_sparse_vector/*',
    '^ml/trained_model_cat_apis/*',
    '^ml/update_trained_model_deployment/*',
    '^ml/upgrade_job_snapshot/*',
    '^monitoring/bulk/10_basic/*',
    '^monitoring/bulk/20_privileges/*',
    '^profiling/10_basic/*',
    // These rollup tests work in MP mode, they just don't work with security enabled.
    '^rollup/delete_job/*',
    '^rollup/get_jobs/*',
    '^rollup/get_rollup_caps/*',
    '^rollup/get_rollup_index_caps/*',
    '^rollup/put_job/*',
    '^rollup/rollup_search/*',
    '^rollup/start_job/*',
    '^rollup/stop_job/*',
    '^searchable_snapshots/10_usage/*', // The usage API is project-aware, so this test can be unmuted once snapshot repositories are project-aware
    '^searchable_snapshots/20_synthetic_source/*',
    '^security/settings/10_update_security_settings/*',
    '^snapshot/10_basic/*',
    '^snapshot/20_operator_privileges_disabled/*',
    '^transform/preview_transforms/*',
    '^transform/transforms_cat_apis/*',
    '^transform/transforms_crud/*',
    '^transform/transforms_force_delete/*',
    '^transform/transforms_reset/*',
    '^transform/transforms_start_stop/*',
    '^transform/transforms_start_stop/Test start/stop only starts/stops specified transform',
    '^transform/transforms_start_stop/Test start/stop with field alias',
    '^transform/transforms_start_stop/Test start/stop/start continuous transform',
    '^transform/transforms_start_stop/Test start/stop/start transform',
    '^transform/transforms_stats/*',
    '^transform/transforms_stats_continuous/*',
    '^transform/transforms_unattended/*',
    '^transform/transforms_update/*',
    '^transform/transforms_upgrade/*',
  ];
  if (buildParams.snapshotBuild == false) {
    blacklist += [];
  }
  systemProperty 'tests.rest.blacklist', blacklist.join(',')
  systemProperty "tests.multi_project.enabled", true
}
