18
18
import org .elasticsearch .client .Response ;
19
19
import org .elasticsearch .client .WarningsHandler ;
20
20
import org .elasticsearch .common .settings .Settings ;
21
+ import org .elasticsearch .common .util .CollectionUtils ;
21
22
import org .elasticsearch .common .util .concurrent .ThreadContext ;
22
23
import org .elasticsearch .core .Nullable ;
23
24
import org .elasticsearch .rest .RestStatus ;
34
35
35
36
import java .io .IOException ;
36
37
import java .nio .charset .StandardCharsets ;
37
- import java .util .ArrayList ;
38
38
import java .util .Base64 ;
39
39
import java .util .HashSet ;
40
40
import java .util .List ;
@@ -212,9 +212,8 @@ private void testCatIndices(List<String> indexNames, @Nullable List<String> addi
212
212
String response = EntityUtils .toString (assertOK (client ().performRequest (catIndices )).getEntity ());
213
213
List <String > indices = List .of (response .trim ().split ("\\ s+" ));
214
214
215
- if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
216
- indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
217
- indexNames .addAll (additionalIndexNames );
215
+ if (additionalIndexNames != null ) {
216
+ indexNames = CollectionUtils .concatLists (indexNames , additionalIndexNames );
218
217
}
219
218
220
219
assertThat (new HashSet <>(indices ), is (new HashSet <>(indexNames )));
@@ -240,9 +239,8 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
240
239
);
241
240
Response response = assertOK (client ().performRequest (getStar ));
242
241
243
- if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
244
- indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
245
- indexNames .addAll (additionalIndexNames );
242
+ if (additionalIndexNames != null ) {
243
+ indexNames = CollectionUtils .concatLists (indexNames , additionalIndexNames );
246
244
}
247
245
248
246
Map <String , Object > map = responseAsMap (response );
@@ -258,23 +256,38 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
258
256
);
259
257
Response response = assertOK (client ().performRequest (getStar ));
260
258
261
- if (additionalIndexNames != null && additionalIndexNames .isEmpty () == false ) {
262
- indexNames = new ArrayList <>(indexNames ); // recopy into a mutable list
263
- indexNames .addAll (additionalIndexNames );
259
+ if (additionalIndexNames != null ) {
260
+ indexNames = CollectionUtils .concatLists (indexNames , additionalIndexNames );
264
261
}
265
262
266
263
Map <String , Object > map = responseAsMap (response );
267
264
assertThat (map .keySet (), is (new HashSet <>(indexNames )));
268
265
}
269
266
270
267
private void testGetDatastreams () throws IOException {
271
- Request getStar = new Request ("GET" , "_data_stream" );
272
- getStar .setOptions (
273
- RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (WarningsHandler .PERMISSIVE ) // we don't care about warnings, just errors
268
+ final List <List <String >> wildcardOptions = List .of (
269
+ List .of (), // the default for expand_wildcards (that is, the option is not specified)
270
+ List .of ("all" ),
271
+ List .of ("none" ),
272
+ List .of ("hidden" ),
273
+ List .of ("open" ),
274
+ List .of ("closed" ),
275
+ List .of ("hidden" , "open" ),
276
+ List .of ("hidden" , "closed" ),
277
+ List .of ("open" , "closed" )
274
278
);
275
- Response response = client ().performRequest (getStar );
276
- assertOK (response );
277
-
278
- // note: we don't actually care about the response, just that there was one and that it didn't error out on us
279
+ for (List <String > expandWildcards : wildcardOptions ) {
280
+ final Request getStar = new Request (
281
+ "GET" ,
282
+ "_data_stream" + (expandWildcards .isEmpty () ? "" : ("?expand_wildcards=" + String .join ("," , expandWildcards )))
283
+ );
284
+ getStar .setOptions (
285
+ RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (WarningsHandler .PERMISSIVE ) // we only care about errors
286
+ );
287
+ Response response = client ().performRequest (getStar );
288
+ assertOK (response );
289
+
290
+ // note: we don't actually care about the response, just that there was one and that it didn't error out on us
291
+ }
279
292
}
280
293
}
0 commit comments