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