2121
2222import org .elasticsearch .action .ActionRequestValidationException ;
2323import 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 ;
2826
2927import java .io .IOException ;
28+ import java .util .ArrayList ;
29+ import java .util .List ;
30+ import java .util .function .Consumer ;
3031
31- public class FieldCapabilitiesRequestTests extends ESTestCase {
32- private FieldCapabilitiesRequest randomRequest () {
32+ public class FieldCapabilitiesRequestTests extends AbstractStreamableTestCase <FieldCapabilitiesRequest > {
33+
34+ @ Override
35+ protected FieldCapabilitiesRequest createTestInstance () {
3336 FieldCapabilitiesRequest request = new FieldCapabilitiesRequest ();
3437 int size = randomIntBetween (1 , 20 );
3538 String [] randomFields = new String [size ];
@@ -50,50 +53,33 @@ private FieldCapabilitiesRequest randomRequest() {
5053 return request ;
5154 }
5255
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 ();
8359 }
8460
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 ;
9783 }
9884
9985 public void testValidation () {
0 commit comments