From 33ccc3bd6c0e204bf9d7b212a08c934ceaef99fe Mon Sep 17 00:00:00 2001 From: javanna Date: Sat, 18 Feb 2017 10:27:35 +0100 Subject: [PATCH] adapt to ObjectPath changes to support binary formats Original commit: elastic/x-pack-elasticsearch@11782418e98cc0c4ca611544b99317e0ab83132c --- .../rest/action/RestAuthenticateActionTests.java | 9 ++------- .../UpgradeClusterClientYamlTestSuiteIT.java | 13 ++----------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/plugin/src/test/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateActionTests.java b/plugin/src/test/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateActionTests.java index f8dac7d25bf..a2388780b48 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateActionTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateActionTests.java @@ -6,13 +6,10 @@ package org.elasticsearch.xpack.security.rest.action; import org.apache.http.message.BasicHeader; -import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.test.rest.yaml.ObjectPath; @@ -56,8 +53,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase { new BasicHeader("Authorization", basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME, new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray())))); assertThat(response.getStatusLine().getStatusCode(), is(200)); - ObjectPath objectPath = ObjectPath.createFromXContent(XContentFactory.xContent(XContentType.JSON), - EntityUtils.toString(response.getEntity())); + ObjectPath objectPath = ObjectPath.createFromResponse(response); assertThat(objectPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.DEFAULT_USER_NAME)); @SuppressWarnings("unchecked") List roles = (List) objectPath.evaluate("roles"); @@ -70,8 +66,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase { Response response = getRestClient().performRequest("GET", "/_xpack/security/_authenticate"); if (anonymousEnabled) { assertThat(response.getStatusLine().getStatusCode(), is(200)); - ObjectPath objectPath = ObjectPath.createFromXContent(XContentFactory.xContent(XContentType.JSON), - EntityUtils.toString(response.getEntity())); + ObjectPath objectPath = ObjectPath.createFromResponse(response); assertThat(objectPath.evaluate("username").toString(), equalTo("anon")); @SuppressWarnings("unchecked") List roles = (List) objectPath.evaluate("roles"); diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java index 299804b640e..b2b0f94373e 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/UpgradeClusterClientYamlTestSuiteIT.java @@ -7,13 +7,11 @@ package org.elasticsearch.upgrades; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; - import org.apache.http.util.EntityUtils; import org.apache.lucene.util.TimeUnits; import org.elasticsearch.client.Response; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.test.rest.yaml.ObjectPath; @@ -49,7 +47,7 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa assertBusy(() -> { try { Response nodeDetailsResponse = client().performRequest("GET", "/_nodes"); - ObjectPath path = objectPath(nodeDetailsResponse); + ObjectPath path = ObjectPath.createFromResponse(nodeDetailsResponse); Map nodes = path.evaluate("nodes"); assertThat(nodes.size(), greaterThanOrEqualTo(2)); String masterVersion = null; @@ -64,7 +62,7 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa final String masterTemplateVersion = masterVersion; Response response = client().performRequest("GET", "/_cluster/state/metadata"); - ObjectPath objectPath = objectPath(response); + ObjectPath objectPath = ObjectPath.createFromResponse(response); final String mappingsPath = "metadata.templates." + SECURITY_TEMPLATE_NAME + ".mappings"; Map mappings = objectPath.evaluate(mappingsPath); assertNotNull(mappings); @@ -79,13 +77,6 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa }); } - private ObjectPath objectPath(Response response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); - String contentType = response.getHeader("Content-Type"); - XContentType xContentType = XContentType.fromMediaTypeOrFormat(contentType); - return ObjectPath.createFromXContent(xContentType.xContent(), body); - } - @Override protected boolean preserveIndicesUponCompletion() { return true;