diff options
author | javanna <cavannaluca@gmail.com> | 2016-05-18 15:49:28 +0200 |
---|---|---|
committer | Luca Cavanna <cavannaluca@gmail.com> | 2016-06-03 16:01:07 +0200 |
commit | 325b72393077e7985975515a8c9a8b29c468da16 (patch) | |
tree | b6c5ee106d0b7cf4794035302c59679e8eebf7a1 /core/src/test/java/org/elasticsearch/plugins | |
parent | 6d3f6c7fafd5b5df98c142e04a85d98a434bee37 (diff) |
[TEST] add rest client test dependency and replace usage of HttpRequestBuilder with RestClient in integration tests
Diffstat (limited to 'core/src/test/java/org/elasticsearch/plugins')
-rw-r--r-- | core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java index ac6d8fddd8..4ae9e3912b 100644 --- a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java @@ -18,14 +18,18 @@ */ package org.elasticsearch.plugins; +import org.apache.http.message.BasicHeader; +import org.elasticsearch.client.ElasticsearchResponse; +import org.elasticsearch.client.ElasticsearchResponseException; +import org.elasticsearch.client.RestClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.responseheader.TestResponseHeaderPlugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; -import org.elasticsearch.test.rest.client.http.HttpResponse; import java.util.Collection; +import java.util.Collections; import static org.elasticsearch.rest.RestStatus.OK; import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED; @@ -52,12 +56,20 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase { public void testThatSettingHeadersWorks() throws Exception { ensureGreen(); - HttpResponse response = httpClient().method("GET").path("/_protected").execute(); - assertThat(response, hasStatus(UNAUTHORIZED)); - assertThat(response.getHeaders().get("Secret"), equalTo("required")); + try (RestClient client = restClient()) { + try { + client.performRequest("GET", "/_protected", Collections.emptyMap(), null); + fail("request should have failed"); + } catch(ElasticsearchResponseException e) { + ElasticsearchResponse response = e.getElasticsearchResponse(); + assertThat(response, hasStatus(UNAUTHORIZED)); + assertThat(response.getFirstHeader("Secret"), equalTo("required")); + } - HttpResponse authResponse = httpClient().method("GET").path("/_protected").addHeader("Secret", "password").execute(); - assertThat(authResponse, hasStatus(OK)); - assertThat(authResponse.getHeaders().get("Secret"), equalTo("granted")); + ElasticsearchResponse authResponse = client.performRequest("GET", "/_protected", Collections.emptyMap(), null, + new BasicHeader("Secret", "password")); + assertThat(authResponse, hasStatus(OK)); + assertThat(authResponse.getFirstHeader("Secret"), equalTo("granted")); + } } } |