|
19 | 19 |
|
20 | 20 | package org.elasticsearch.action.update;
|
21 | 21 |
|
| 22 | +import org.elasticsearch.action.ActionRequestValidationException; |
22 | 23 | import org.elasticsearch.action.DocWriteResponse;
|
23 | 24 | import org.elasticsearch.action.delete.DeleteRequest;
|
24 | 25 | import org.elasticsearch.action.index.IndexRequest;
|
|
61 | 62 | import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
|
62 | 63 | import static org.elasticsearch.script.MockScriptEngine.mockInlineScript;
|
63 | 64 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
|
| 65 | +import static org.hamcrest.CoreMatchers.hasItems; |
| 66 | +import static org.hamcrest.CoreMatchers.not; |
| 67 | +import static org.hamcrest.CoreMatchers.nullValue; |
64 | 68 | import static org.hamcrest.Matchers.contains;
|
65 | 69 | import static org.hamcrest.Matchers.equalTo;
|
66 | 70 | import static org.hamcrest.Matchers.instanceOf;
|
@@ -511,6 +515,25 @@ public void testToValidateUpsertRequestWithVersion() {
|
511 | 515 | assertThat(updateRequest.validate().validationErrors(), contains("can't provide version in upsert request"));
|
512 | 516 | }
|
513 | 517 |
|
| 518 | + public void testValidate() { |
| 519 | + { |
| 520 | + UpdateRequest request = new UpdateRequest("index", "type", "id"); |
| 521 | + request.doc("{}", XContentType.JSON); |
| 522 | + ActionRequestValidationException validate = request.validate(); |
| 523 | + |
| 524 | + assertThat(validate, nullValue()); |
| 525 | + } |
| 526 | + |
| 527 | + { |
| 528 | + UpdateRequest request = new UpdateRequest("index", randomBoolean() ? "" : null, randomBoolean() ? "" : null); |
| 529 | + request.doc("{}", XContentType.JSON); |
| 530 | + ActionRequestValidationException validate = request.validate(); |
| 531 | + |
| 532 | + assertThat(validate, not(nullValue())); |
| 533 | + assertThat(validate.validationErrors(), hasItems("type is missing", "id is missing")); |
| 534 | + } |
| 535 | + } |
| 536 | + |
514 | 537 | public void testRoutingExtraction() throws Exception {
|
515 | 538 | GetResult getResult = new GetResult("test", "type", "1", 0, false, null, null);
|
516 | 539 | IndexRequest indexRequest = new IndexRequest("test", "type", "1");
|
|
0 commit comments