|
@@ -19,6 +19,7 @@
|
|
|
|
|
|
package org.elasticsearch.action.admin.indices.create;
|
|
|
|
|
|
+import org.elasticsearch.ElasticsearchParseException;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
@@ -31,6 +32,7 @@ import org.junit.Before;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class CreateIndexRequestBuilderTests extends ESTestCase {
|
|
@@ -58,16 +60,23 @@ public class CreateIndexRequestBuilderTests extends ESTestCase {
|
|
|
*/
|
|
|
public void testSetSource() throws IOException {
|
|
|
CreateIndexRequestBuilder builder = new CreateIndexRequestBuilder(this.testClient, CreateIndexAction.INSTANCE);
|
|
|
- builder.setSource("{\""+KEY+"\" : \""+VALUE+"\"}", XContentType.JSON);
|
|
|
+
|
|
|
+ ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class,
|
|
|
+ () -> {builder.setSource("{\""+KEY+"\" : \""+VALUE+"\"}", XContentType.JSON);});
|
|
|
+ assertEquals(String.format(Locale.ROOT, "unknown key [%s] for create index", KEY), e.getMessage());
|
|
|
+
|
|
|
+ builder.setSource("{\"settings\" : {\""+KEY+"\" : \""+VALUE+"\"}}", XContentType.JSON);
|
|
|
assertEquals(VALUE, builder.request().settings().get(KEY));
|
|
|
|
|
|
- XContentBuilder xContent = XContentFactory.jsonBuilder().startObject().field(KEY, VALUE).endObject();
|
|
|
+ XContentBuilder xContent = XContentFactory.jsonBuilder().startObject()
|
|
|
+ .startObject("settings").field(KEY, VALUE).endObject().endObject();
|
|
|
xContent.close();
|
|
|
builder.setSource(xContent);
|
|
|
assertEquals(VALUE, builder.request().settings().get(KEY));
|
|
|
|
|
|
ByteArrayOutputStream docOut = new ByteArrayOutputStream();
|
|
|
- XContentBuilder doc = XContentFactory.jsonBuilder(docOut).startObject().field(KEY, VALUE).endObject();
|
|
|
+ XContentBuilder doc = XContentFactory.jsonBuilder(docOut).startObject()
|
|
|
+ .startObject("settings").field(KEY, VALUE).endObject().endObject();
|
|
|
doc.close();
|
|
|
builder.setSource(docOut.toByteArray(), XContentType.JSON);
|
|
|
assertEquals(VALUE, builder.request().settings().get(KEY));
|