|
19 | 19 |
|
20 | 20 | package org.elasticsearch.action.ingest;
|
21 | 21 |
|
| 22 | +import org.elasticsearch.ElasticsearchParseException; |
22 | 23 | import org.elasticsearch.index.VersionType;
|
23 | 24 | import org.elasticsearch.ingest.CompoundProcessor;
|
24 | 25 | import org.elasticsearch.ingest.IngestDocument;
|
|
45 | 46 | import static org.elasticsearch.ingest.IngestDocument.MetaData.ROUTING;
|
46 | 47 | import static org.elasticsearch.ingest.IngestDocument.MetaData.VERSION;
|
47 | 48 | import static org.elasticsearch.ingest.IngestDocument.MetaData.VERSION_TYPE;
|
| 49 | +import static org.hamcrest.Matchers.containsString; |
48 | 50 | import static org.hamcrest.Matchers.equalTo;
|
49 | 51 | import static org.hamcrest.Matchers.nullValue;
|
50 | 52 | import static org.mockito.Mockito.mock;
|
@@ -216,4 +218,33 @@ public void testNonExistentPipelineId() {
|
216 | 218 | () -> SimulatePipelineRequest.parseWithPipelineId(pipelineId, requestContent, false, ingestService));
|
217 | 219 | assertThat(e.getMessage(), equalTo("pipeline [" + pipelineId + "] does not exist"));
|
218 | 220 | }
|
| 221 | + |
| 222 | + public void testNotValidDocs() { |
| 223 | + Map<String, Object> requestContent = new HashMap<>(); |
| 224 | + List<Map<String, Object>> docs = new ArrayList<>(); |
| 225 | + Map<String, Object> pipelineConfig = new HashMap<>(); |
| 226 | + List<Map<String, Object>> processors = new ArrayList<>(); |
| 227 | + pipelineConfig.put("processors", processors); |
| 228 | + requestContent.put(Fields.DOCS, docs); |
| 229 | + requestContent.put(Fields.PIPELINE, pipelineConfig); |
| 230 | + Exception e1 = expectThrows(IllegalArgumentException.class, |
| 231 | + () -> SimulatePipelineRequest.parse(requestContent, false, ingestService)); |
| 232 | + assertThat(e1.getMessage(), equalTo("must specify at least one document in [docs]")); |
| 233 | + |
| 234 | + List<String> stringList = new ArrayList<>(); |
| 235 | + stringList.add("test"); |
| 236 | + pipelineConfig.put("processors", processors); |
| 237 | + requestContent.put(Fields.DOCS, stringList); |
| 238 | + requestContent.put(Fields.PIPELINE, pipelineConfig); |
| 239 | + Exception e2 = expectThrows(IllegalArgumentException.class, |
| 240 | + () -> SimulatePipelineRequest.parse(requestContent, false, ingestService)); |
| 241 | + assertThat(e2.getMessage(), equalTo("malformed [docs] section, should include an inner object")); |
| 242 | + |
| 243 | + docs.add(new HashMap<>()); |
| 244 | + requestContent.put(Fields.DOCS, docs); |
| 245 | + requestContent.put(Fields.PIPELINE, pipelineConfig); |
| 246 | + Exception e3 = expectThrows(ElasticsearchParseException.class, |
| 247 | + () -> SimulatePipelineRequest.parse(requestContent, false, ingestService)); |
| 248 | + assertThat(e3.getMessage(), containsString("required property is missing")); |
| 249 | + } |
219 | 250 | }
|
0 commit comments