diff --git a/x-pack/plugin/deprecation/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/DeprecationHttpIT.java b/x-pack/plugin/deprecation/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/DeprecationHttpIT.java index 1c6dd59ffc279..3fb9573dd7b62 100644 --- a/x-pack/plugin/deprecation/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/DeprecationHttpIT.java +++ b/x-pack/plugin/deprecation/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/DeprecationHttpIT.java @@ -477,17 +477,23 @@ public void testDeprecationWarnMessagesCanBeIndexed() throws Exception { } - //TODO: check headers too! public void testDeprecateAndKeep() throws Exception { final Request request = new Request("GET", "/_test_cluster/deprecated_but_dont_remove"); request.setEntity(buildSettingsRequest(Collections.singletonList(TEST_NOT_DEPRECATED_SETTING), "settings")); - performScopedRequest(request); + Response response = performScopedRequest(request); + + final List deprecatedWarnings = getWarningHeaders(response.getHeaders()); + assertThat( + extractWarningValuesFromWarningHeaders(deprecatedWarnings), + containsInAnyOrder("[/_test_cluster/deprecated_but_dont_remove] is deprecated, but no plans to remove quite yet") + ); + assertBusy(() -> { List> documents = DeprecationTestUtils.getIndexedDeprecations(client(), xOpaqueId()); logger.warn(documents); - //only assert the relevant fields: level, message, and category + // only assert the relevant fields: level, message, and category assertThat( documents, containsInAnyOrder( @@ -504,7 +510,13 @@ public void testDeprecateAndKeep() throws Exception { public void testReplacesInCurrentVersion() throws Exception { final Request request = new Request("GET", "/_test_cluster/old_name1"); // deprecated in current version request.setEntity(buildSettingsRequest(Collections.singletonList(TEST_NOT_DEPRECATED_SETTING), "settings")); - performScopedRequest(request); + Response response = performScopedRequest(request); + + final List deprecatedWarnings = getWarningHeaders(response.getHeaders()); + assertThat( + extractWarningValuesFromWarningHeaders(deprecatedWarnings), + containsInAnyOrder("[GET /_test_cluster/old_name1] is deprecated! Use [GET /_test_cluster/new_name1] instead.") + ); assertBusy(() -> { List> documents = DeprecationTestUtils.getIndexedDeprecations(client(), xOpaqueId()); @@ -526,7 +538,7 @@ public void testReplacesInCurrentVersion() throws Exception { } public void testReplacesInCompatibleVersion() throws Exception { - final Request request = new Request("GET", "/_test_cluster/old_name2"); //deprecated in minimum supported version + final Request request = new Request("GET", "/_test_cluster/old_name2"); // deprecated in minimum supported version request.setEntity(buildSettingsRequest(Collections.singletonList(TEST_DEPRECATED_SETTING_TRUE1), "deprecated_settings")); final RequestOptions compatibleOptions = request.getOptions() .toBuilder() @@ -534,16 +546,22 @@ public void testReplacesInCompatibleVersion() throws Exception { .addHeader("Content-Type", "application/vnd.elasticsearch+json;compatible-with=" + RestApiVersion.minimumSupported().major) .build(); request.setOptions(compatibleOptions); - performScopedRequest(request); - - //check for 2 headers + Response response = performScopedRequest(request); + final List deprecatedWarnings = getWarningHeaders(response.getHeaders()); + assertThat( + extractWarningValuesFromWarningHeaders(deprecatedWarnings), + containsInAnyOrder( + "[GET /_test_cluster/old_name2] is deprecated! Use [GET /_test_cluster/new_name2] instead.", + "You are using a compatible API for this request" + ) + ); assertBusy(() -> { List> documents = DeprecationTestUtils.getIndexedDeprecations(client(), xOpaqueId()); logger.warn(documents); - //only assert the relevant fields: level, message, and category + // only assert the relevant fields: level, message, and category assertThat( documents, containsInAnyOrder( diff --git a/x-pack/plugin/deprecation/qa/rest/src/main/java/org/elasticsearch/xpack/deprecation/TestDeprecationHeaderRestAction.java b/x-pack/plugin/deprecation/qa/rest/src/main/java/org/elasticsearch/xpack/deprecation/TestDeprecationHeaderRestAction.java index 6656c5e9d3434..9e5f999d1f825 100644 --- a/x-pack/plugin/deprecation/qa/rest/src/main/java/org/elasticsearch/xpack/deprecation/TestDeprecationHeaderRestAction.java +++ b/x-pack/plugin/deprecation/qa/rest/src/main/java/org/elasticsearch/xpack/deprecation/TestDeprecationHeaderRestAction.java @@ -100,17 +100,19 @@ public List routes() { Route.builder(GET, "/_test_cluster/deprecated_settings") .deprecatedForRemoval(DEPRECATED_ENDPOINT, RestApiVersion.current()) .build(), - //TODO: s/deprecated/deprecatedForRemoval when removing `deprecated` method + // TODO: s/deprecated/deprecatedForRemoval when removing `deprecated` method Route.builder(POST, "/_test_cluster/deprecated_settings").deprecated(DEPRECATED_ENDPOINT, RestApiVersion.current()).build(), Route.builder(GET, "/_test_cluster/compat_only") - .deprecatedForRemoval(DEPRECATED_ENDPOINT, RestApiVersion.minimumSupported()).build(), + .deprecatedForRemoval(DEPRECATED_ENDPOINT, RestApiVersion.minimumSupported()) + .build(), Route.builder(GET, "/_test_cluster/only_deprecated_setting").build(), Route.builder(GET, "/_test_cluster/deprecated_but_dont_remove") - .deprecateAndKeep("[/_test_cluster/deprecated_but_dont_remove] is deprecated, but no plans to remove quite yet").build(), - Route.builder(GET, "/_test_cluster/new_name1") - .replaces(GET, "/_test_cluster/old_name1", RestApiVersion.current()).build(), + .deprecateAndKeep("[/_test_cluster/deprecated_but_dont_remove] is deprecated, but no plans to remove quite yet") + .build(), + Route.builder(GET, "/_test_cluster/new_name1").replaces(GET, "/_test_cluster/old_name1", RestApiVersion.current()).build(), Route.builder(GET, "/_test_cluster/new_name2") - .replaces(GET, "/_test_cluster/old_name2", RestApiVersion.minimumSupported()).build() + .replaces(GET, "/_test_cluster/old_name2", RestApiVersion.minimumSupported()) + .build() ); }