|
|
@@ -21,15 +21,18 @@ package org.elasticsearch.action.fieldcaps;
|
|
|
|
|
|
import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
import org.elasticsearch.action.support.IndicesOptions;
|
|
|
-import org.elasticsearch.common.ValidationException;
|
|
|
-import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
-import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
-import org.elasticsearch.test.ESTestCase;
|
|
|
+import org.elasticsearch.common.util.ArrayUtils;
|
|
|
+import org.elasticsearch.test.AbstractStreamableTestCase;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.function.Consumer;
|
|
|
|
|
|
-public class FieldCapabilitiesRequestTests extends ESTestCase {
|
|
|
- private FieldCapabilitiesRequest randomRequest() {
|
|
|
+public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase<FieldCapabilitiesRequest> {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected FieldCapabilitiesRequest createTestInstance() {
|
|
|
FieldCapabilitiesRequest request = new FieldCapabilitiesRequest();
|
|
|
int size = randomIntBetween(1, 20);
|
|
|
String[] randomFields = new String[size];
|
|
|
@@ -50,50 +53,33 @@ public class FieldCapabilitiesRequestTests extends ESTestCase {
|
|
|
return request;
|
|
|
}
|
|
|
|
|
|
- public void testEqualsAndHashcode() {
|
|
|
- FieldCapabilitiesRequest request = new FieldCapabilitiesRequest();
|
|
|
- request.indices("foo");
|
|
|
- request.indicesOptions(IndicesOptions.lenientExpandOpen());
|
|
|
- request.fields("bar");
|
|
|
-
|
|
|
- FieldCapabilitiesRequest other = new FieldCapabilitiesRequest();
|
|
|
- other.indices("foo");
|
|
|
- other.indicesOptions(IndicesOptions.lenientExpandOpen());
|
|
|
- other.fields("bar");
|
|
|
- assertEquals(request, request);
|
|
|
- assertEquals(request, other);
|
|
|
- assertEquals(request.hashCode(), other.hashCode());
|
|
|
-
|
|
|
- // change indices
|
|
|
- other.indices("foo", "bar");
|
|
|
- assertNotEquals(request, other);
|
|
|
- other.indices("foo");
|
|
|
- assertEquals(request, other);
|
|
|
-
|
|
|
- // change fields
|
|
|
- other.fields("foo", "bar");
|
|
|
- assertNotEquals(request, other);
|
|
|
- other.fields("bar");
|
|
|
- assertEquals(request, request);
|
|
|
-
|
|
|
- // change indices options
|
|
|
- other.indicesOptions(IndicesOptions.strictExpand());
|
|
|
- assertNotEquals(request, other);
|
|
|
-
|
|
|
+ @Override
|
|
|
+ protected FieldCapabilitiesRequest createBlankInstance() {
|
|
|
+ return new FieldCapabilitiesRequest();
|
|
|
}
|
|
|
|
|
|
- public void testSerialization() throws IOException {
|
|
|
- for (int i = 0; i < 20; i++) {
|
|
|
- FieldCapabilitiesRequest request = randomRequest();
|
|
|
- BytesStreamOutput output = new BytesStreamOutput();
|
|
|
- request.writeTo(output);
|
|
|
- output.flush();
|
|
|
- StreamInput input = output.bytes().streamInput();
|
|
|
- FieldCapabilitiesRequest deserialized = new FieldCapabilitiesRequest();
|
|
|
- deserialized.readFrom(input);
|
|
|
- assertEquals(deserialized, request);
|
|
|
- assertEquals(deserialized.hashCode(), request.hashCode());
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ protected FieldCapabilitiesRequest mutateInstance(FieldCapabilitiesRequest instance) throws IOException {
|
|
|
+ List<Consumer<FieldCapabilitiesRequest>> mutators = new ArrayList<>();
|
|
|
+ mutators.add(request -> {
|
|
|
+ String[] fields = ArrayUtils.concat(request.fields(), new String[] {randomAlphaOfLength(10)});
|
|
|
+ request.fields(fields);
|
|
|
+ });
|
|
|
+ mutators.add(request -> {
|
|
|
+ String[] indices = ArrayUtils.concat(instance.indices(), generateRandomStringArray(5, 10, false, false));
|
|
|
+ request.indices(indices);
|
|
|
+ });
|
|
|
+ mutators.add(request -> {
|
|
|
+ IndicesOptions indicesOptions = randomValueOtherThan(request.indicesOptions(),
|
|
|
+ () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
|
|
|
+ request.indicesOptions(indicesOptions);
|
|
|
+ });
|
|
|
+ mutators.add(request -> request.setMergeResults(!request.isMergeResults()));
|
|
|
+
|
|
|
+ FieldCapabilitiesRequest mutatedInstance = copyInstance(instance);
|
|
|
+ Consumer<FieldCapabilitiesRequest> mutator = randomFrom(mutators);
|
|
|
+ mutator.accept(mutatedInstance);
|
|
|
+ return mutatedInstance;
|
|
|
}
|
|
|
|
|
|
public void testValidation() {
|