1818import org .elasticsearch .client .Response ;
1919import org .elasticsearch .client .WarningsHandler ;
2020import org .elasticsearch .common .settings .Settings ;
21+ import org .elasticsearch .common .util .CollectionUtils ;
2122import org .elasticsearch .common .util .concurrent .ThreadContext ;
2223import org .elasticsearch .core .Nullable ;
2324import org .elasticsearch .rest .RestStatus ;
3334
3435import java .io .IOException ;
3536import java .nio .charset .StandardCharsets ;
36- import java .util .ArrayList ;
3737import java .util .Base64 ;
3838import java .util .HashSet ;
3939import java .util .List ;
@@ -210,9 +210,8 @@ private void testCatIndices(List<String> indexNames, @Nullable List<String> addi
210210 String response = EntityUtils .toString (assertOK (client ().performRequest (catIndices )).getEntity ());
211211 List <String > indices = List .of (response .trim ().split ("\\ s+" ));
212212
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 );
216215 }
217216
218217 assertThat (new HashSet <>(indices ), is (new HashSet <>(indexNames )));
@@ -238,9 +237,8 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
238237 );
239238 Response response = assertOK (client ().performRequest (getStar ));
240239
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 );
244242 }
245243
246244 Map <String , Object > map = responseAsMap (response );
@@ -256,23 +254,38 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
256254 );
257255 Response response = assertOK (client ().performRequest (getStar ));
258256
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 );
262259 }
263260
264261 Map <String , Object > map = responseAsMap (response );
265262 assertThat (map .keySet (), is (new HashSet <>(indexNames )));
266263 }
267264
268265 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" )
272276 );
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+ }
277290 }
278291}
0 commit comments