@@ -183,7 +183,7 @@ public void elasticsearchOssImage() throws IOException {
183
183
184
184
@ Test
185
185
public void restClientClusterHealth () throws IOException {
186
- // httpClientContainer {
186
+ // httpClientContainer7 {
187
187
// Create the elasticsearch container.
188
188
try (ElasticsearchContainer container = new ElasticsearchContainer (ELASTICSEARCH_IMAGE )) {
189
189
// Start the container. This step might take some time...
@@ -208,7 +208,86 @@ public void restClientClusterHealth() throws IOException {
208
208
// }}
209
209
assertThat (response .getStatusLine ().getStatusCode ()).isEqualTo (200 );
210
210
assertThat (EntityUtils .toString (response .getEntity ())).contains ("cluster_name" );
211
- // httpClientContainer {{
211
+ // httpClientContainer7 {{
212
+ }
213
+ // }
214
+ }
215
+
216
+ @ Test
217
+ public void restClientClusterHealthElasticsearch8 () throws IOException {
218
+ // httpClientContainer8 {
219
+ // Create the elasticsearch container.
220
+ try (
221
+ ElasticsearchContainer container = new ElasticsearchContainer (
222
+ "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"
223
+ )
224
+ ) {
225
+ // Start the container. This step might take some time...
226
+ container .start ();
227
+
228
+ // Do whatever you want with the rest client ...
229
+ final CredentialsProvider credentialsProvider = new BasicCredentialsProvider ();
230
+ credentialsProvider .setCredentials (
231
+ AuthScope .ANY ,
232
+ new UsernamePasswordCredentials (ELASTICSEARCH_USERNAME , ELASTICSEARCH_PASSWORD )
233
+ );
234
+
235
+ client =
236
+ RestClient
237
+ // use HTTPS for Elasticsearch 8
238
+ .builder (HttpHost .create ("https://" + container .getHttpHostAddress ()))
239
+ .setHttpClientConfigCallback (httpClientBuilder -> {
240
+ httpClientBuilder .setDefaultCredentialsProvider (credentialsProvider );
241
+ // SSL is activated by default in Elasticsearch 8
242
+ httpClientBuilder .setSSLContext (container .createSslContextFromCa ());
243
+ return httpClientBuilder ;
244
+ })
245
+ .build ();
246
+
247
+ Response response = client .performRequest (new Request ("GET" , "/_cluster/health" ));
248
+ // }}
249
+ assertThat (response .getStatusLine ().getStatusCode ()).isEqualTo (200 );
250
+ assertThat (EntityUtils .toString (response .getEntity ())).contains ("cluster_name" );
251
+ // httpClientContainer8 {{
252
+ }
253
+ // }
254
+ }
255
+
256
+ @ Test
257
+ public void restClientClusterHealthElasticsearch8WithoutSSL () throws IOException {
258
+ // httpClientContainerNoSSL8 {
259
+ // Create the elasticsearch container.
260
+ try (
261
+ ElasticsearchContainer container = new ElasticsearchContainer (
262
+ "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"
263
+ )
264
+ // disable SSL
265
+ .withEnv ("xpack.security.transport.ssl.enabled" , "false" )
266
+ .withEnv ("xpack.security.http.ssl.enabled" , "false" )
267
+ ) {
268
+ // Start the container. This step might take some time...
269
+ container .start ();
270
+
271
+ // Do whatever you want with the rest client ...
272
+ final CredentialsProvider credentialsProvider = new BasicCredentialsProvider ();
273
+ credentialsProvider .setCredentials (
274
+ AuthScope .ANY ,
275
+ new UsernamePasswordCredentials (ELASTICSEARCH_USERNAME , ELASTICSEARCH_PASSWORD )
276
+ );
277
+
278
+ client =
279
+ RestClient
280
+ .builder (HttpHost .create (container .getHttpHostAddress ()))
281
+ .setHttpClientConfigCallback (httpClientBuilder -> {
282
+ return httpClientBuilder .setDefaultCredentialsProvider (credentialsProvider );
283
+ })
284
+ .build ();
285
+
286
+ Response response = client .performRequest (new Request ("GET" , "/_cluster/health" ));
287
+ // }}
288
+ assertThat (response .getStatusLine ().getStatusCode ()).isEqualTo (200 );
289
+ assertThat (EntityUtils .toString (response .getEntity ())).contains ("cluster_name" );
290
+ // httpClientContainerNoSSL8 {{
212
291
}
213
292
// }
214
293
}
@@ -289,20 +368,6 @@ public void incompatibleSettingsTest() {
289
368
.isInstanceOf (IllegalArgumentException .class );
290
369
}
291
370
292
- @ Test
293
- public void testElasticsearch8SecureByDefault () throws Exception {
294
- try (
295
- ElasticsearchContainer container = new ElasticsearchContainer (
296
- "docker.elastic.co/elasticsearch/elasticsearch:8.1.2"
297
- )
298
- ) {
299
- // Start the container. This step might take some time...
300
- container .start ();
301
-
302
- assertClusterHealthResponse (container );
303
- }
304
- }
305
-
306
371
@ Test
307
372
public void testDockerHubElasticsearch8ImageSecureByDefault () throws Exception {
308
373
try (ElasticsearchContainer container = new ElasticsearchContainer ("elasticsearch:8.1.2" )) {
0 commit comments