|
|
@@ -22,7 +22,6 @@ package org.elasticsearch.common.xcontent.builder;
|
|
|
import org.apache.lucene.util.BytesRef;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.geo.GeoPoint;
|
|
|
-import org.elasticsearch.common.io.FastCharArrayWriter;
|
|
|
import org.elasticsearch.common.io.PathUtils;
|
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
@@ -39,6 +38,7 @@ import java.nio.file.Path;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Calendar;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.GregorianCalendar;
|
|
|
import java.util.HashMap;
|
|
|
@@ -51,9 +51,6 @@ import static org.elasticsearch.common.xcontent.XContentBuilder.FieldCaseConvers
|
|
|
import static org.elasticsearch.common.xcontent.XContentBuilder.FieldCaseConversion.UNDERSCORE;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
-/**
|
|
|
- *
|
|
|
- */
|
|
|
public class XContentBuilderTests extends ESTestCase {
|
|
|
public void testPrettyWithLfAtEnd() throws Exception {
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
@@ -350,4 +347,33 @@ public class XContentBuilderTests extends ESTestCase {
|
|
|
"}", string.trim());
|
|
|
}
|
|
|
|
|
|
+ public void testWriteMapWithNullKeys() throws IOException {
|
|
|
+ XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
|
|
|
+ try {
|
|
|
+ builder.map(Collections.singletonMap(null, "test"));
|
|
|
+ fail("write map should have failed");
|
|
|
+ } catch(IllegalArgumentException e) {
|
|
|
+ assertThat(e.getMessage(), equalTo("field name cannot be null"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testWriteMapValueWithNullKeys() throws IOException {
|
|
|
+ XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
|
|
|
+ try {
|
|
|
+ builder.value(Collections.singletonMap(null, "test"));
|
|
|
+ fail("write map should have failed");
|
|
|
+ } catch(IllegalArgumentException e) {
|
|
|
+ assertThat(e.getMessage(), equalTo("field name cannot be null"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testWriteFieldMapWithNullKeys() throws IOException {
|
|
|
+ XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
|
|
|
+ try {
|
|
|
+ builder.field("map", Collections.singletonMap(null, "test"));
|
|
|
+ fail("write map should have failed");
|
|
|
+ } catch(IllegalArgumentException e) {
|
|
|
+ assertThat(e.getMessage(), equalTo("field name cannot be null"));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|