21
21
22
22
import org .elasticsearch .action .ActionRequestValidationException ;
23
23
import org .elasticsearch .action .support .IndicesOptions ;
24
- import org .elasticsearch .common .ValidationException ;
25
- import org .elasticsearch .common .io .stream .BytesStreamOutput ;
26
- import org .elasticsearch .common .io .stream .StreamInput ;
27
- import org .elasticsearch .test .ESTestCase ;
24
+ import org .elasticsearch .common .util .ArrayUtils ;
25
+ import org .elasticsearch .test .AbstractStreamableTestCase ;
28
26
29
27
import java .io .IOException ;
28
+ import java .util .ArrayList ;
29
+ import java .util .List ;
30
+ import java .util .function .Consumer ;
30
31
31
- public class FieldCapabilitiesRequestTests extends ESTestCase {
32
- private FieldCapabilitiesRequest randomRequest () {
32
+ public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase <FieldCapabilitiesRequest > {
33
+
34
+ @ Override
35
+ protected FieldCapabilitiesRequest createTestInstance () {
33
36
FieldCapabilitiesRequest request = new FieldCapabilitiesRequest ();
34
37
int size = randomIntBetween (1 , 20 );
35
38
String [] randomFields = new String [size ];
@@ -50,50 +53,33 @@ private FieldCapabilitiesRequest randomRequest() {
50
53
return request ;
51
54
}
52
55
53
- public void testEqualsAndHashcode () {
54
- FieldCapabilitiesRequest request = new FieldCapabilitiesRequest ();
55
- request .indices ("foo" );
56
- request .indicesOptions (IndicesOptions .lenientExpandOpen ());
57
- request .fields ("bar" );
58
-
59
- FieldCapabilitiesRequest other = new FieldCapabilitiesRequest ();
60
- other .indices ("foo" );
61
- other .indicesOptions (IndicesOptions .lenientExpandOpen ());
62
- other .fields ("bar" );
63
- assertEquals (request , request );
64
- assertEquals (request , other );
65
- assertEquals (request .hashCode (), other .hashCode ());
66
-
67
- // change indices
68
- other .indices ("foo" , "bar" );
69
- assertNotEquals (request , other );
70
- other .indices ("foo" );
71
- assertEquals (request , other );
72
-
73
- // change fields
74
- other .fields ("foo" , "bar" );
75
- assertNotEquals (request , other );
76
- other .fields ("bar" );
77
- assertEquals (request , request );
78
-
79
- // change indices options
80
- other .indicesOptions (IndicesOptions .strictExpand ());
81
- assertNotEquals (request , other );
82
-
56
+ @ Override
57
+ protected FieldCapabilitiesRequest createBlankInstance () {
58
+ return new FieldCapabilitiesRequest ();
83
59
}
84
60
85
- public void testSerialization () throws IOException {
86
- for (int i = 0 ; i < 20 ; i ++) {
87
- FieldCapabilitiesRequest request = randomRequest ();
88
- BytesStreamOutput output = new BytesStreamOutput ();
89
- request .writeTo (output );
90
- output .flush ();
91
- StreamInput input = output .bytes ().streamInput ();
92
- FieldCapabilitiesRequest deserialized = new FieldCapabilitiesRequest ();
93
- deserialized .readFrom (input );
94
- assertEquals (deserialized , request );
95
- assertEquals (deserialized .hashCode (), request .hashCode ());
96
- }
61
+ @ Override
62
+ protected FieldCapabilitiesRequest mutateInstance (FieldCapabilitiesRequest instance ) throws IOException {
63
+ List <Consumer <FieldCapabilitiesRequest >> mutators = new ArrayList <>();
64
+ mutators .add (request -> {
65
+ String [] fields = ArrayUtils .concat (request .fields (), new String [] {randomAlphaOfLength (10 )});
66
+ request .fields (fields );
67
+ });
68
+ mutators .add (request -> {
69
+ String [] indices = ArrayUtils .concat (instance .indices (), generateRandomStringArray (5 , 10 , false , false ));
70
+ request .indices (indices );
71
+ });
72
+ mutators .add (request -> {
73
+ IndicesOptions indicesOptions = randomValueOtherThan (request .indicesOptions (),
74
+ () -> IndicesOptions .fromOptions (randomBoolean (), randomBoolean (), randomBoolean (), randomBoolean ()));
75
+ request .indicesOptions (indicesOptions );
76
+ });
77
+ mutators .add (request -> request .setMergeResults (!request .isMergeResults ()));
78
+
79
+ FieldCapabilitiesRequest mutatedInstance = copyInstance (instance );
80
+ Consumer <FieldCapabilitiesRequest > mutator = randomFrom (mutators );
81
+ mutator .accept (mutatedInstance );
82
+ return mutatedInstance ;
97
83
}
98
84
99
85
public void testValidation () {
0 commit comments