|
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;
|
|
46 | 47 | import static org.elasticsearch.ingest.IngestDocument.MetaData.TYPE;
|
47 | 48 | import static org.elasticsearch.ingest.IngestDocument.MetaData.VERSION;
|
48 | 49 | import static org.elasticsearch.ingest.IngestDocument.MetaData.VERSION_TYPE;
|
| 50 | +import static org.hamcrest.Matchers.containsString; |
49 | 51 | import static org.hamcrest.Matchers.equalTo;
|
50 | 52 | import static org.hamcrest.Matchers.nullValue;
|
51 | 53 | import static org.mockito.Mockito.mock;
|
@@ -257,4 +259,33 @@ public void testNonExistentPipelineId() {
|
257 | 259 | () -> SimulatePipelineRequest.parseWithPipelineId(pipelineId, requestContent, false, ingestService));
|
258 | 260 | assertThat(e.getMessage(), equalTo("pipeline [" + pipelineId + "] does not exist"));
|
259 | 261 | }
|
| 262 | + |
| 263 | + public void testNotValidDocs() { |
| 264 | + Map<String, Object> requestContent = new HashMap<>(); |
| 265 | + List<Map<String, Object>> docs = new ArrayList<>(); |
| 266 | + Map<String, Object> pipelineConfig = new HashMap<>(); |
| 267 | + List<Map<String, Object>> processors = new ArrayList<>(); |
| 268 | + pipelineConfig.put("processors", processors); |
| 269 | + requestContent.put(Fields.DOCS, docs); |
| 270 | + requestContent.put(Fields.PIPELINE, pipelineConfig); |
| 271 | + Exception e1 = expectThrows(IllegalArgumentException.class, |
| 272 | + () -> SimulatePipelineRequest.parse(requestContent, false, ingestService)); |
| 273 | + assertThat(e1.getMessage(), equalTo("must specify at least one document in [docs]")); |
| 274 | + |
| 275 | + List<String> stringList = new ArrayList<>(); |
| 276 | + stringList.add("test"); |
| 277 | + pipelineConfig.put("processors", processors); |
| 278 | + requestContent.put(Fields.DOCS, stringList); |
| 279 | + requestContent.put(Fields.PIPELINE, pipelineConfig); |
| 280 | + Exception e2 = expectThrows(IllegalArgumentException.class, |
| 281 | + () -> SimulatePipelineRequest.parse(requestContent, false, ingestService)); |
| 282 | + assertThat(e2.getMessage(), equalTo("malformed [docs] section, should include an inner object")); |
| 283 | + |
| 284 | + docs.add(new HashMap<>()); |
| 285 | + requestContent.put(Fields.DOCS, docs); |
| 286 | + requestContent.put(Fields.PIPELINE, pipelineConfig); |
| 287 | + Exception e3 = expectThrows(ElasticsearchParseException.class, |
| 288 | + () -> SimulatePipelineRequest.parse(requestContent, false, ingestService)); |
| 289 | + assertThat(e3.getMessage(), containsString("required property is missing")); |
| 290 | + } |
260 | 291 | }
|
0 commit comments