Tests: Check that GetResponse.toString() outputs json xcontent (#23545)

This commit is contained in:
Christoph Büscher 2017-03-13 09:54:29 -07:00 committed by GitHub
parent ff1530592e
commit 21dcd4f4ca
1 changed files with 9 additions and 2 deletions

View File

@ -29,7 +29,6 @@ import org.elasticsearch.index.get.GetField;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
import java.util.Collections;
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
@ -62,7 +61,7 @@ public class GetResponseTests extends ESTestCase {
assertEquals(expectedGetResponse.getSourceAsString(), parsedGetResponse.getSourceAsString());
}
public void testToXContent() throws IOException {
public void testToXContent() {
{
GetResponse getResponse = new GetResponse(new GetResult("index", "type", "id", 1, true, new BytesArray("{ \"field1\" : " +
"\"value1\", \"field2\":\"value2\"}"), Collections.singletonMap("field1", new GetField("field1",
@ -78,6 +77,14 @@ public class GetResponseTests extends ESTestCase {
}
}
public void testToString() {
GetResponse getResponse = new GetResponse(
new GetResult("index", "type", "id", 1, true, new BytesArray("{ \"field1\" : " + "\"value1\", \"field2\":\"value2\"}"),
Collections.singletonMap("field1", new GetField("field1", Collections.singletonList("value1")))));
assertEquals("{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":1,\"found\":true,\"_source\":{ \"field1\" "
+ ": \"value1\", \"field2\":\"value2\"},\"fields\":{\"field1\":[\"value1\"]}}", getResponse.toString());
}
public void testEqualsAndHashcode() {
checkEqualsAndHashCode(new GetResponse(randomGetResult(XContentType.JSON).v1()), GetResponseTests::copyGetResponse,
GetResponseTests::mutateGetResponse);