summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/plugins
diff options
context:
space:
mode:
authorjavanna <cavannaluca@gmail.com>2016-06-03 18:00:54 +0200
committerLuca Cavanna <cavannaluca@gmail.com>2016-06-03 18:00:54 +0200
commit23a94bb9745aeba8bc8c04c02c874deaf89ae621 (patch)
treeb726da5b56656e2f3df9cb112fcd088461eb5e02 /core/src/test/java/org/elasticsearch/plugins
parentf5825b86e631905f1108f72ae9466f2bc42119b9 (diff)
[TEST] create standard RestClient at first request and reuse it
A RestClient instance is now created whenever EsIntegTestCase#getRestClient is invoked for the first time. It is then kept until the cluster is cleared (depending on the cluster scope of the test). Renamed other two restClient methods to createRestClient, as that instance needs to be closed and managed in the tests.
Diffstat (limited to 'core/src/test/java/org/elasticsearch/plugins')
-rw-r--r--core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java27
1 files changed, 12 insertions, 15 deletions
diff --git a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java
index 4b905d7b1a..0fd21651ac 100644
--- a/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java
+++ b/core/src/test/java/org/elasticsearch/plugins/ResponseHeaderPluginIT.java
@@ -21,7 +21,6 @@ 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;
@@ -56,21 +55,19 @@ public class ResponseHeaderPluginIT extends ESIntegTestCase {
public void testThatSettingHeadersWorks() throws Exception {
ensureGreen();
- 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"));
- }
+ try {
+ getRestClient().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"));
+ }
- try (ElasticsearchResponse authResponse = client.performRequest("GET", "/_protected", Collections.emptyMap(), null,
- new BasicHeader("Secret", "password"))) {
- assertThat(authResponse, hasStatus(OK));
- assertThat(authResponse.getFirstHeader("Secret"), equalTo("granted"));
- }
+ try (ElasticsearchResponse authResponse = getRestClient().performRequest("GET", "/_protected", Collections.emptyMap(), null,
+ new BasicHeader("Secret", "password"))) {
+ assertThat(authResponse, hasStatus(OK));
+ assertThat(authResponse.getFirstHeader("Secret"), equalTo("granted"));
}
}
}