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 ;
3435
3536import java .io .IOException ;
3637import java .nio .charset .StandardCharsets ;
37- import java .util .ArrayList ;
3838import java .util .Base64 ;
3939import java .util .HashSet ;
4040import java .util .List ;
@@ -212,9 +212,8 @@ private void testCatIndices(List<String> indexNames, @Nullable List<String> addi
212212 String response = EntityUtils .toString (assertOK (client ().performRequest (catIndices )).getEntity ());
213213 List <String > indices = List .of (response .trim ().split ("\\ s+" ));
214214
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 );
218217 }
219218
220219 assertThat (new HashSet <>(indices ), is (new HashSet <>(indexNames )));
@@ -240,9 +239,8 @@ private void testGetStar(List<String> indexNames, @Nullable List<String> additio
240239 );
241240 Response response = assertOK (client ().performRequest (getStar ));
242241
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 );
246244 }
247245
248246 Map <String , Object > map = responseAsMap (response );
@@ -258,23 +256,38 @@ private void testGetStarAsKibana(List<String> indexNames, @Nullable List<String>
258256 );
259257 Response response = assertOK (client ().performRequest (getStar ));
260258
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 );
264261 }
265262
266263 Map <String , Object > map = responseAsMap (response );
267264 assertThat (map .keySet (), is (new HashSet <>(indexNames )));
268265 }
269266
270267 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" )
274278 );
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+ }
279292 }
280293}
0 commit comments