From 91cd6f35cebe386dbcf38bda31fa999ca7aa1720 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 2 Feb 2017 20:03:44 -0800 Subject: [PATCH] Fix client test to not care about complete error response message --- .../http/DetailedErrorsDisabledIT.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java index 51dbad22dec..6d7749849d5 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/DetailedErrorsDisabledIT.java @@ -19,6 +19,9 @@ package org.elasticsearch.http; +import java.io.IOException; +import java.util.Collections; + import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; @@ -27,9 +30,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; -import java.io.IOException; -import java.util.Collections; - +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; /** @@ -48,14 +49,12 @@ public class DetailedErrorsDisabledIT extends HttpSmokeTestCase { } public void testThatErrorTraceParamReturns400() throws IOException { - try { - getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true")); - fail("request should have failed"); - } catch(ResponseException e) { - Response response = e.getResponse(); - assertThat(response.getHeader("Content-Type"), is("application/json; charset=UTF-8")); - assertThat(EntityUtils.toString(e.getResponse().getEntity()), is("{\"error\":\"error traces in responses are disabled.\"}")); - assertThat(response.getStatusLine().getStatusCode(), is(400)); - } + ResponseException e = expectThrows(ResponseException.class, () -> + getRestClient().performRequest("DELETE", "/", Collections.singletonMap("error_trace", "true"))); + + Response response = e.getResponse(); + assertThat(response.getHeader("Content-Type"), is("application/json; charset=UTF-8")); + assertThat(EntityUtils.toString(e.getResponse().getEntity()), containsString("\"error\":\"error traces in responses are disabled.\"")); + assertThat(response.getStatusLine().getStatusCode(), is(400)); } }