[TEST] fix RequestTests#testSearch in case search source is not set
The search request body can never be null as `SearchRequest` doesn't allow the inner `SearchSourceBuilder` to be null. Instead, when search source is not set, the request body is going to be an empty json object (`{}``)
@@ -794,9 +794,11 @@ public class RequestTests extends ESTestCase {
setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams);
- SearchSourceBuilder searchSourceBuilder = null;
+ SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
+ //rarely skip setting the search source completely
+ if (frequently()) {
+ //frequently set the search source to have some content, otherwise leave it empty but still set it
if (frequently()) {
- searchSourceBuilder = new SearchSourceBuilder();
if (randomBoolean()) {
searchSourceBuilder.size(randomIntBetween(0, Integer.MAX_VALUE));
}
@@ -833,6 +835,7 @@ public class RequestTests extends ESTestCase {
if (randomBoolean()) {
searchSourceBuilder.collapse(new CollapseBuilder(randomAlphaOfLengthBetween(3, 10)));
}
+ }
searchRequest.source(searchSourceBuilder);
}
@@ -849,12 +852,8 @@ public class RequestTests extends ESTestCase {
endpoint.add("_search");
assertEquals(endpoint.toString(), request.getEndpoint());
assertEquals(expectedParams, request.getParameters());
- if (searchSourceBuilder == null) {
- assertNull(request.getEntity());
- } else {
assertToXContentBody(searchSourceBuilder, request.getEntity());
}
- }
public void testMultiSearch() throws IOException {
int numberOfSearchRequests = randomIntBetween(0, 32);
