[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 (`{}``)
This commit is contained in:
javanna 2018-01-18 12:56:54 +01:00 committed by Luca Cavanna
parent b4c1c4a78c
commit 0dfb65a6ee
1 changed files with 41 additions and 42 deletions

View File

@ -794,9 +794,11 @@ public class RequestTests extends ESTestCase {
setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams); 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()) { if (frequently()) {
searchSourceBuilder = new SearchSourceBuilder();
if (randomBoolean()) { if (randomBoolean()) {
searchSourceBuilder.size(randomIntBetween(0, Integer.MAX_VALUE)); searchSourceBuilder.size(randomIntBetween(0, Integer.MAX_VALUE));
} }
@ -833,6 +835,7 @@ public class RequestTests extends ESTestCase {
if (randomBoolean()) { if (randomBoolean()) {
searchSourceBuilder.collapse(new CollapseBuilder(randomAlphaOfLengthBetween(3, 10))); searchSourceBuilder.collapse(new CollapseBuilder(randomAlphaOfLengthBetween(3, 10)));
} }
}
searchRequest.source(searchSourceBuilder); searchRequest.source(searchSourceBuilder);
} }
@ -849,12 +852,8 @@ public class RequestTests extends ESTestCase {
endpoint.add("_search"); endpoint.add("_search");
assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(endpoint.toString(), request.getEndpoint());
assertEquals(expectedParams, request.getParameters()); assertEquals(expectedParams, request.getParameters());
if (searchSourceBuilder == null) {
assertNull(request.getEntity());
} else {
assertToXContentBody(searchSourceBuilder, request.getEntity()); assertToXContentBody(searchSourceBuilder, request.getEntity());
} }
}
public void testMultiSearch() throws IOException { public void testMultiSearch() throws IOException {
int numberOfSearchRequests = randomIntBetween(0, 32); int numberOfSearchRequests = randomIntBetween(0, 32);