From 8065531236f53b49435b9853a3b3a338534b6ee5 Mon Sep 17 00:00:00 2001 From: javanna Date: Mon, 23 Jan 2017 19:40:09 +0100 Subject: [PATCH] [TEST] add test to verify that the SMILE format works within the _bulk api --- .../action/bulk/BulkRequestTests.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java index a4a5f6f5ba6..e0c58a60d29 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkRequestTests.java @@ -30,9 +30,15 @@ import org.elasticsearch.client.Requests; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.io.stream.BytesStreamOutput; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.script.Script; import org.elasticsearch.test.ESTestCase; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -205,4 +211,41 @@ public class BulkRequestTests extends ESTestCase { expectThrows(NullPointerException.class, () -> bulkRequest.add((UpdateRequest) null)); expectThrows(NullPointerException.class, () -> bulkRequest.add((DeleteRequest) null)); } + + public void testSmileIsSupported() throws IOException { + XContentType xContentType = XContentType.SMILE; + BytesReference data; + try (BytesStreamOutput out = new BytesStreamOutput()) { + try(XContentBuilder builder = XContentFactory.contentBuilder(xContentType, out)) { + builder.startObject(); + builder.startObject("index"); + builder.field("_index", "index"); + builder.field("_type", "type"); + builder.field("_id", "test"); + builder.endObject(); + builder.endObject(); + } + out.write(xContentType.xContent().streamSeparator()); + try(XContentBuilder builder = XContentFactory.contentBuilder(xContentType, out)) { + builder.startObject(); + builder.field("field", "value"); + builder.endObject(); + } + out.write(xContentType.xContent().streamSeparator()); + data = out.bytes(); + } + + BulkRequest bulkRequest = new BulkRequest(); + bulkRequest.add(data, null, null); + assertEquals(1, bulkRequest.requests().size()); + DocWriteRequest docWriteRequest = bulkRequest.requests().get(0); + assertEquals(DocWriteRequest.OpType.INDEX, docWriteRequest.opType()); + assertEquals("index", docWriteRequest.index()); + assertEquals("type", docWriteRequest.type()); + assertEquals("test", docWriteRequest.id()); + assertThat(docWriteRequest, instanceOf(IndexRequest.class)); + IndexRequest request = (IndexRequest) docWriteRequest; + assertEquals(1, request.sourceAsMap().size()); + assertEquals("value", request.sourceAsMap().get("field")); + } }