|
110 | 110 | import java.lang.reflect.Constructor; |
111 | 111 | import java.lang.reflect.Modifier; |
112 | 112 | import java.util.ArrayList; |
| 113 | +import java.util.Arrays; |
113 | 114 | import java.util.Collections; |
114 | 115 | import java.util.HashMap; |
| 116 | +import java.util.HashSet; |
115 | 117 | import java.util.List; |
116 | 118 | import java.util.Locale; |
117 | 119 | import java.util.Map; |
| 120 | +import java.util.Set; |
118 | 121 | import java.util.StringJoiner; |
119 | 122 | import java.util.function.Consumer; |
120 | 123 | import java.util.function.Function; |
@@ -1226,28 +1229,32 @@ public void testFieldCaps() { |
1226 | 1229 | .indices(indices) |
1227 | 1230 | .fields(fields); |
1228 | 1231 |
|
1229 | | - Map<String, String> expectedIndicesParams = new HashMap<>(); |
| 1232 | + Map<String, String> indicesOptionsParams = new HashMap<>(); |
1230 | 1233 | setRandomIndicesOptions(fieldCapabilitiesRequest::indicesOptions, |
1231 | 1234 | fieldCapabilitiesRequest::indicesOptions, |
1232 | | - expectedIndicesParams); |
| 1235 | + indicesOptionsParams); |
1233 | 1236 |
|
1234 | 1237 | Request request = Request.fieldCaps(fieldCapabilitiesRequest); |
1235 | 1238 |
|
1236 | 1239 | // Verify that the resulting REST request looks as expected. |
1237 | | - StringJoiner expectedEndpoint = new StringJoiner("/", "/", ""); |
| 1240 | + StringJoiner endpoint = new StringJoiner("/", "/", ""); |
1238 | 1241 | String joinedIndices = String.join(",", indices); |
1239 | 1242 | if (!joinedIndices.isEmpty()) { |
1240 | | - expectedEndpoint.add(joinedIndices); |
| 1243 | + endpoint.add(joinedIndices); |
1241 | 1244 | } |
1242 | | - expectedEndpoint.add("_field_caps"); |
| 1245 | + endpoint.add("_field_caps"); |
1243 | 1246 |
|
1244 | | - assertEquals(expectedEndpoint.toString(), request.getEndpoint()); |
| 1247 | + assertEquals(endpoint.toString(), request.getEndpoint()); |
1245 | 1248 | assertEquals(4, request.getParameters().size()); |
1246 | 1249 |
|
1247 | | - // Note that we don't check the field param value explicitly, as field |
1248 | | - // names are added to the request in a non-deterministic order. |
| 1250 | + // Note that we don't check the field param value explicitly, as field names are passed through |
| 1251 | + // a hash set before being added to the request, and can appear in a non-deterministic order. |
1249 | 1252 | assertThat(request.getParameters(), hasKey("fields")); |
1250 | | - for (Map.Entry<String, String> param : expectedIndicesParams.entrySet()) { |
| 1253 | + String[] requestFields = Strings.splitStringByCommaToArray(request.getParameters().get("fields")); |
| 1254 | + assertEquals(new HashSet<>(Arrays.asList(fields)), |
| 1255 | + new HashSet<>(Arrays.asList(requestFields))); |
| 1256 | + |
| 1257 | + for (Map.Entry<String, String> param : indicesOptionsParams.entrySet()) { |
1251 | 1258 | assertThat(request.getParameters(), hasEntry(param.getKey(), param.getValue())); |
1252 | 1259 | } |
1253 | 1260 |
|
|
0 commit comments