Skip to content

Commit ac59e9b

Browse files
committed
Improve a check in RequestTests#testFieldCaps.
1 parent aa170dd commit ac59e9b

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestTests.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@
110110
import java.lang.reflect.Constructor;
111111
import java.lang.reflect.Modifier;
112112
import java.util.ArrayList;
113+
import java.util.Arrays;
113114
import java.util.Collections;
114115
import java.util.HashMap;
116+
import java.util.HashSet;
115117
import java.util.List;
116118
import java.util.Locale;
117119
import java.util.Map;
120+
import java.util.Set;
118121
import java.util.StringJoiner;
119122
import java.util.function.Consumer;
120123
import java.util.function.Function;
@@ -1226,28 +1229,32 @@ public void testFieldCaps() {
12261229
.indices(indices)
12271230
.fields(fields);
12281231

1229-
Map<String, String> expectedIndicesParams = new HashMap<>();
1232+
Map<String, String> indicesOptionsParams = new HashMap<>();
12301233
setRandomIndicesOptions(fieldCapabilitiesRequest::indicesOptions,
12311234
fieldCapabilitiesRequest::indicesOptions,
1232-
expectedIndicesParams);
1235+
indicesOptionsParams);
12331236

12341237
Request request = Request.fieldCaps(fieldCapabilitiesRequest);
12351238

12361239
// Verify that the resulting REST request looks as expected.
1237-
StringJoiner expectedEndpoint = new StringJoiner("/", "/", "");
1240+
StringJoiner endpoint = new StringJoiner("/", "/", "");
12381241
String joinedIndices = String.join(",", indices);
12391242
if (!joinedIndices.isEmpty()) {
1240-
expectedEndpoint.add(joinedIndices);
1243+
endpoint.add(joinedIndices);
12411244
}
1242-
expectedEndpoint.add("_field_caps");
1245+
endpoint.add("_field_caps");
12431246

1244-
assertEquals(expectedEndpoint.toString(), request.getEndpoint());
1247+
assertEquals(endpoint.toString(), request.getEndpoint());
12451248
assertEquals(4, request.getParameters().size());
12461249

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.
12491252
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()) {
12511258
assertThat(request.getParameters(), hasEntry(param.getKey(), param.getValue()));
12521259
}
12531260

0 commit comments

Comments
 (0)