use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testIndexingAndUpdatingDocs.
public void testIndexingAndUpdatingDocs() throws IOException {
Request request = new Request("PUT", "/_opensearch_dashboards/" + indexName + "/_doc/1");
request.setJsonEntity("{ \"foo\" : \"bar\" }");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(201));
request = new Request("PUT", "/_opensearch_dashboards/" + indexName + "/_create/2");
request.setJsonEntity("{ \"foo\" : \"bar\" }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(201));
request = new Request("POST", "/_opensearch_dashboards/" + indexName + "/_doc");
request.setJsonEntity("{ \"foo\" : \"bar\" }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(201));
request = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_refresh");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
request = new Request("POST", "/_opensearch_dashboards/" + indexName + "/_update/1");
request.setJsonEntity("{ \"doc\" : { \"foo\" : \"baz\" } }");
response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testGetFromOpenSearchDashboardsIndex.
public void testGetFromOpenSearchDashboardsIndex() throws IOException {
Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
request.addParameter("refresh", "true");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
Request getRequest = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_doc/1");
Response getResponse = client().performRequest(getRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
String responseBody = EntityUtils.toString(getResponse.getEntity());
assertThat(responseBody, containsString("foo"));
assertThat(responseBody, containsString("bar"));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class OpenSearchDashboardsSystemIndexIT method testMultiGetFromOpenSearchDashboardsIndex.
public void testMultiGetFromOpenSearchDashboardsIndex() throws IOException {
Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n" + "{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"2\" } }\n{ \"baz\" : \"tag\" }\n");
request.addParameter("refresh", "true");
Response response = client().performRequest(request);
assertThat(response.getStatusLine().getStatusCode(), is(200));
Request getRequest = new Request("GET", "/_opensearch_dashboards/_mget");
getRequest.setJsonEntity("{ \"docs\" : [ { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" }, " + "{ \"_index\" : \"" + indexName + "\", \"_id\" : \"2\" } ] }\n");
Response getResponse = client().performRequest(getRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
String responseBody = EntityUtils.toString(getResponse.getEntity());
assertThat(responseBody, containsString("foo"));
assertThat(responseBody, containsString("bar"));
assertThat(responseBody, containsString("baz"));
assertThat(responseBody, containsString("tag"));
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class ReindexRestClientSslTests method testClientSucceedsWithCertificateAuthorities.
public void testClientSucceedsWithCertificateAuthorities() throws IOException {
final List<Thread> threads = new ArrayList<>();
final Path ca = getDataPath("ca.pem");
final Settings settings = Settings.builder().put("path.home", createTempDir()).putList("reindex.ssl.certificate_authorities", ca.toString()).put("reindex.ssl.supported_protocols", "TLSv1.2").build();
final Environment environment = TestEnvironment.newEnvironment(settings);
final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
final Response response = client.performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
}
}
use of org.opensearch.client.Response in project OpenSearch by opensearch-project.
the class ReindexRestClientSslTests method testClientSucceedsWithVerificationDisabled.
public void testClientSucceedsWithVerificationDisabled() throws IOException {
assumeFalse("Cannot disable verification in FIPS JVM", inFipsJvm());
final List<Thread> threads = new ArrayList<>();
final Settings settings = Settings.builder().put("path.home", createTempDir()).put("reindex.ssl.verification_mode", "NONE").put("reindex.ssl.supported_protocols", "TLSv1.2").build();
final Environment environment = TestEnvironment.newEnvironment(settings);
final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
final Response response = client.performRequest(new Request("GET", "/"));
assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
}
}
Aggregations