From eafcdbb0c0edd70df5c0e0c8f46ca87a6ee03789 Mon Sep 17 00:00:00 2001 From: Vacha Shah Date: Wed, 11 Oct 2023 23:49:07 +0000 Subject: [PATCH] Fixing merge conflicts and build Signed-off-by: Vacha Shah --- .../client/documentation/ConnectingTest.java | 2 +- .../client/documentation/MigrateHlrcTest.java | 2 +- .../integTest/AbstractClusterClientIT.java | 6 +-- .../integTest/AbstractPingAndInfoIT.java | 2 +- .../OpenSearchJavaClientTestCase.java | 40 +++++++++---------- .../integTest/OpenSearchTransportSupport.java | 1 - .../HttpClient5TransportSupport.java | 3 +- .../integTest/restclient/ClusterClientIT.java | 1 - .../integTest/restclient/CrudIT.java | 1 - .../integTest/restclient/HighlightIT.java | 1 - .../integTest/restclient/IndicesClientIT.java | 1 - .../integTest/restclient/NodesIT.java | 1 - .../integTest/restclient/PingAndInfoIT.java | 1 - .../integTest/restclient/RequestIT.java | 37 ++++++++--------- 14 files changed, 41 insertions(+), 58 deletions(-) diff --git a/java-client/src/test/java/org/opensearch/client/documentation/ConnectingTest.java b/java-client/src/test/java/org/opensearch/client/documentation/ConnectingTest.java index 024d55b67f..16ec98af51 100644 --- a/java-client/src/test/java/org/opensearch/client/documentation/ConnectingTest.java +++ b/java-client/src/test/java/org/opensearch/client/documentation/ConnectingTest.java @@ -32,6 +32,7 @@ package org.opensearch.client.documentation; +import org.apache.http.HttpHost; import org.junit.Ignore; import org.junit.Test; import org.opensearch.client.RestClient; @@ -41,7 +42,6 @@ import org.opensearch.client.opensearch.core.search.Hit; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.rest_client.RestClientTransport; -import org.apache.http.HttpHost; public class ConnectingTest { diff --git a/java-client/src/test/java/org/opensearch/client/documentation/MigrateHlrcTest.java b/java-client/src/test/java/org/opensearch/client/documentation/MigrateHlrcTest.java index 9b16b884ba..10e98788a3 100644 --- a/java-client/src/test/java/org/opensearch/client/documentation/MigrateHlrcTest.java +++ b/java-client/src/test/java/org/opensearch/client/documentation/MigrateHlrcTest.java @@ -32,6 +32,7 @@ package org.opensearch.client.documentation; +import org.apache.http.HttpHost; import org.junit.Test; import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; @@ -39,7 +40,6 @@ import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.rest_client.RestClientTransport; -import org.apache.http.HttpHost; public class MigrateHlrcTest { diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java index 1f743676da..bd55b6b94b 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractClusterClientIT.java @@ -11,6 +11,7 @@ import static java.util.Collections.emptyMap; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; + import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -97,9 +98,8 @@ public void testClusterUpdateSettingNonExistent() throws IOException { assertNotNull(e); assertEquals(e.response().status(), 400); assertEquals( - e.getMessage(), - "Request failed: [illegal_argument_exception] " + - "transient setting [no_idea_what_you_are_talking_about], not recognized" + e.getMessage(), + "Request failed: [illegal_argument_exception] " + "transient setting [no_idea_what_you_are_talking_about], not recognized" ); } } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractPingAndInfoIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractPingAndInfoIT.java index 3efd7143b0..6fc7944aa5 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractPingAndInfoIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractPingAndInfoIT.java @@ -8,9 +8,9 @@ package org.opensearch.client.opensearch.integTest; -import org.apache.http.client.methods.HttpGet; import java.io.IOException; import java.util.Map; +import org.apache.http.client.methods.HttpGet; import org.opensearch.client.Request; import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.opensearch.core.InfoResponse; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java index 7fe8e1e42d..d60a6e28c3 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java @@ -8,6 +8,21 @@ package org.opensearch.client.opensearch.integTest; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.TreeSet; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.apache.http.ssl.SSLContextBuilder; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; import org.opensearch.Version; import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; @@ -19,25 +34,9 @@ import org.opensearch.client.opensearch.indices.DeleteIndexRequest; import org.opensearch.client.opensearch.nodes.NodesInfoResponse; import org.opensearch.client.opensearch.nodes.info.NodeInfo; -import org.apache.http.HttpHost; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.conn.ssl.NoopHostnameVerifier; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.ssl.SSLContextBuilder; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; import org.opensearch.common.settings.Settings; import org.opensearch.test.rest.OpenSearchRestTestCase; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import java.util.TreeSet; - public abstract class OpenSearchJavaClientTestCase extends OpenSearchRestTestCase implements OpenSearchTransportSupport { private static final List systemIndices = List.of(".opensearch-observability", ".opendistro_security", ".plugins-ml-config"); private static OpenSearchClient javaClient; @@ -90,15 +89,12 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE String password = Optional.ofNullable(System.getProperty("password")).orElse("admin"); final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - for (final HttpHost host: hosts) { - credentialsProvider.setCredentials(AuthScope.ANY, - new UsernamePasswordCredentials(userName, password)); + for (final HttpHost host : hosts) { + credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password)); } - try { - return httpClientBuilder - .setDefaultCredentialsProvider(credentialsProvider) + return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider) // disable the certificate since our testing cluster just uses the default security configuration .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .setSSLContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build()); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchTransportSupport.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchTransportSupport.java index 9c47d1f69b..4f06567a03 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchTransportSupport.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchTransportSupport.java @@ -10,7 +10,6 @@ import java.io.IOException; import java.util.Optional; - import org.apache.http.HttpHost; import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.transport.OpenSearchTransport; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java index 1e6d4b4405..f0fe9a4768 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/HttpClient5TransportSupport.java @@ -45,8 +45,7 @@ interface HttpClient5TransportSupport extends OpenSearchTransportSupport { @Override default OpenSearchTransport buildTransport(Settings settings, org.apache.http.HttpHost[] hosts) throws IOException { - final HttpHost[] converted = Arrays - .stream(hosts) + final HttpHost[] converted = Arrays.stream(hosts) .map(h -> new HttpHost(h.getSchemeName(), h.getHostName(), h.getPort())) .toArray(HttpHost[]::new); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/ClusterClientIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/ClusterClientIT.java index 188eb616f5..8d70e3875a 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/ClusterClientIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/ClusterClientIT.java @@ -9,7 +9,6 @@ package org.opensearch.client.opensearch.integTest.restclient; import java.io.IOException; - import org.apache.http.HttpHost; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.integTest.AbstractClusterClientIT; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CrudIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CrudIT.java index 6831f1d95d..f9a9076a9c 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CrudIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/CrudIT.java @@ -9,7 +9,6 @@ package org.opensearch.client.opensearch.integTest.restclient; import java.io.IOException; - import org.apache.http.HttpHost; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.integTest.AbstractCrudIT; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/HighlightIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/HighlightIT.java index 7a5c95bd2c..bed40d80e1 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/HighlightIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/HighlightIT.java @@ -9,7 +9,6 @@ package org.opensearch.client.opensearch.integTest.restclient; import java.io.IOException; - import org.apache.http.HttpHost; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.integTest.AbstractHighlightIT; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/IndicesClientIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/IndicesClientIT.java index 190127ea9b..64b17dfd43 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/IndicesClientIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/IndicesClientIT.java @@ -9,7 +9,6 @@ package org.opensearch.client.opensearch.integTest.restclient; import java.io.IOException; - import org.apache.http.HttpHost; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.integTest.AbstractIndicesClientIT; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/NodesIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/NodesIT.java index 47f07306b8..41a5e2b2df 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/NodesIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/NodesIT.java @@ -9,7 +9,6 @@ package org.opensearch.client.opensearch.integTest.restclient; import java.io.IOException; - import org.apache.http.HttpHost; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.integTest.AbstractNodesIT; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/PingAndInfoIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/PingAndInfoIT.java index e5ac93649e..07a258f654 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/PingAndInfoIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/PingAndInfoIT.java @@ -9,7 +9,6 @@ package org.opensearch.client.opensearch.integTest.restclient; import java.io.IOException; - import org.apache.http.HttpHost; import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.integTest.AbstractPingAndInfoIT; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/RequestIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/RequestIT.java index 5c48371cff..7be389daba 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/RequestIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/RequestIT.java @@ -12,7 +12,7 @@ import java.io.IOException; import java.util.Optional; - +import javax.net.ssl.SSLContext; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; @@ -35,10 +35,6 @@ import org.opensearch.client.transport.rest_client.RestClientTransport; import org.opensearch.common.settings.Settings; -import javax.net.ssl.SSLContext; - -import static org.hamcrest.CoreMatchers.equalTo; - public class RequestIT extends AbstractRequestIT { @Override public OpenSearchTransport buildTransport(Settings settings, HttpHost[] hosts) throws IOException { @@ -54,23 +50,22 @@ public void testUnauthorized() throws Exception { final String wrongPassword = Optional.ofNullable(System.getProperty("password")).orElse("admin") + "wrong"; final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials(new AuthScope(getClusterHosts().get(0)), - new UsernamePasswordCredentials(userName, wrongPassword)); + credentialsProvider.setCredentials( + new AuthScope(getClusterHosts().get(0)), + new UsernamePasswordCredentials(userName, wrongPassword) + ); - final RestClient restClient = RestClient - .builder(getClusterHosts().toArray(new HttpHost[0])) - .setHttpClientConfigCallback(httpClientBuilder -> { - try { - final TrustStrategy trustStrategy = new TrustAllStrategy(); - final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial( - null, trustStrategy).build(); - return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider) - .setSSLContext(sslContext); - } catch (Exception e) { - throw new RuntimeException(e); - } - }) - .build(); + final RestClient restClient = RestClient.builder(getClusterHosts().toArray(new HttpHost[0])) + .setHttpClientConfigCallback(httpClientBuilder -> { + try { + final TrustStrategy trustStrategy = new TrustAllStrategy(); + final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, trustStrategy).build(); + return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setSSLContext(sslContext); + } catch (Exception e) { + throw new RuntimeException(e); + } + }) + .build(); final RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); final OpenSearchClient client = new OpenSearchClient(transport);