|
|
@@ -18,52 +18,45 @@
|
|
|
*/
|
|
|
package org.elasticsearch.client.indices;
|
|
|
|
|
|
-import org.elasticsearch.action.ActionRequestValidationException;
|
|
|
import org.elasticsearch.action.admin.indices.alias.Alias;
|
|
|
+import org.elasticsearch.client.AbstractRequestTestCase;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
+import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
-import org.elasticsearch.test.AbstractXContentTestCase;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.test.ESTestCase;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.UncheckedIOException;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
-import static org.hamcrest.Matchers.hasSize;
|
|
|
-import static org.hamcrest.Matchers.nullValue;
|
|
|
-import static org.hamcrest.core.Is.is;
|
|
|
|
|
|
-public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIndexTemplateRequest> {
|
|
|
- public void testValidateErrorMessage() throws Exception {
|
|
|
- expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest(null));
|
|
|
- expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest("test").name(null));
|
|
|
- PutIndexTemplateRequest request = new PutIndexTemplateRequest("test");
|
|
|
- ActionRequestValidationException withoutPattern = request.validate();
|
|
|
- assertThat(withoutPattern.getMessage(), containsString("index patterns are missing"));
|
|
|
-
|
|
|
- request.name("foo");
|
|
|
- ActionRequestValidationException withoutIndexPatterns = request.validate();
|
|
|
- assertThat(withoutIndexPatterns.validationErrors(), hasSize(1));
|
|
|
- assertThat(withoutIndexPatterns.getMessage(), containsString("index patterns are missing"));
|
|
|
+public class PutIndexTemplateRequestTests extends AbstractRequestTestCase<PutIndexTemplateRequest,
|
|
|
+ org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest> {
|
|
|
|
|
|
- request.patterns(Collections.singletonList("test-*"));
|
|
|
- ActionRequestValidationException noError = request.validate();
|
|
|
- assertThat(noError, is(nullValue()));
|
|
|
+ public void testValidateErrorMessage() throws Exception {
|
|
|
+ expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest(null, null));
|
|
|
+ expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest("test", List.of("index")).name(null));
|
|
|
+ Exception e = expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest("test", null));
|
|
|
+ assertThat(e.getMessage(), containsString("index patterns are missing"));
|
|
|
+ e = expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest("test", List.of()));
|
|
|
+ assertThat(e.getMessage(), containsString("index patterns are missing"));
|
|
|
+ new PutIndexTemplateRequest("test", List.of("index"));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected PutIndexTemplateRequest createTestInstance() {
|
|
|
- PutIndexTemplateRequest request = new PutIndexTemplateRequest("test");
|
|
|
+ protected PutIndexTemplateRequest createClientTestInstance() {
|
|
|
+ PutIndexTemplateRequest request = new PutIndexTemplateRequest("test",
|
|
|
+ List.of(ESTestCase.generateRandomStringArray(20, 100, false, false)));
|
|
|
if (randomBoolean()) {
|
|
|
request.version(randomInt());
|
|
|
}
|
|
|
if (randomBoolean()) {
|
|
|
request.order(randomInt());
|
|
|
}
|
|
|
- request.patterns(Arrays.asList(generateRandomStringArray(20, 100, false, false)));
|
|
|
int numAlias = between(0, 5);
|
|
|
for (int i = 0; i < numAlias; i++) {
|
|
|
// some ASCII or Latin-1 control characters, especially newline, can lead to
|
|
|
@@ -80,9 +73,10 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIn
|
|
|
if (randomBoolean()) {
|
|
|
try {
|
|
|
request.mapping(XContentFactory.jsonBuilder().startObject()
|
|
|
+ .startObject("_doc")
|
|
|
.startObject("properties")
|
|
|
.startObject("field-" + randomInt()).field("type", randomFrom("keyword", "text")).endObject()
|
|
|
- .endObject().endObject());
|
|
|
+ .endObject().endObject().endObject());
|
|
|
} catch (IOException ex) {
|
|
|
throw new UncheckedIOException(ex);
|
|
|
}
|
|
|
@@ -94,23 +88,29 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase<PutIn
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected PutIndexTemplateRequest doParseInstance(XContentParser parser) throws IOException {
|
|
|
- return new PutIndexTemplateRequest("test").source(parser.map());
|
|
|
+ protected org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest doParseToServerInstance(
|
|
|
+ XContentParser parser) throws IOException {
|
|
|
+ return new org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest("test").source(parser.map());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected void assertEqualInstances(PutIndexTemplateRequest expected, PutIndexTemplateRequest actual) {
|
|
|
- assertNotSame(expected, actual);
|
|
|
- assertThat(actual.version(), equalTo(expected.version()));
|
|
|
- assertThat(actual.order(), equalTo(expected.order()));
|
|
|
- assertThat(actual.patterns(), equalTo(expected.patterns()));
|
|
|
- assertThat(actual.aliases(), equalTo(expected.aliases()));
|
|
|
- assertThat(actual.mappings(), equalTo(expected.mappings()));
|
|
|
- assertThat(actual.settings(), equalTo(expected.settings()));
|
|
|
+ protected void assertInstances(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest serverInstance,
|
|
|
+ PutIndexTemplateRequest clientTestInstance) {
|
|
|
+ assertNotSame(serverInstance, clientTestInstance);
|
|
|
+ assertThat(serverInstance.version(), equalTo(clientTestInstance.version()));
|
|
|
+ assertThat(serverInstance.order(), equalTo(clientTestInstance.order()));
|
|
|
+ assertThat(serverInstance.patterns(), equalTo(clientTestInstance.patterns()));
|
|
|
+ assertThat(serverInstance.aliases(), equalTo(clientTestInstance.aliases()));
|
|
|
+ String mapping = null;
|
|
|
+ if (clientTestInstance.mappings() != null) {
|
|
|
+ try {
|
|
|
+ mapping = XContentHelper.convertToJson(clientTestInstance.mappings(), false, XContentType.JSON);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new UncheckedIOException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertThat(serverInstance.mappings().get("_doc"), equalTo(mapping));
|
|
|
+ assertThat(serverInstance.settings(), equalTo(clientTestInstance.settings()));
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected boolean supportsUnknownFields() {
|
|
|
- return false;
|
|
|
- }
|
|
|
}
|