[TEST] Simplify SplitProcessorTests#testSplitAppendable to not require compound and append processor
This commit is contained in:
parent
e860f9ddda
commit
17a36aecff
|
@ -19,14 +19,10 @@
|
|||
|
||||
package org.elasticsearch.ingest.processor;
|
||||
|
||||
import org.elasticsearch.ingest.TestTemplateService;
|
||||
import org.elasticsearch.ingest.core.CompoundProcessor;
|
||||
import org.elasticsearch.ingest.core.IngestDocument;
|
||||
import org.elasticsearch.ingest.RandomDocumentPicks;
|
||||
import org.elasticsearch.ingest.core.IngestDocument;
|
||||
import org.elasticsearch.ingest.core.Processor;
|
||||
import org.elasticsearch.ingest.core.TemplateService;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -84,21 +80,18 @@ public class SplitProcessorTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testSplitAppendable() throws Exception {
|
||||
TemplateService templateService = TestTemplateService.instance();
|
||||
Map splitConfig = new HashMap<>();
|
||||
Map<String, Object> splitConfig = new HashMap<>();
|
||||
splitConfig.put("field", "flags");
|
||||
splitConfig.put("separator", "\\|");
|
||||
Processor splitProcessor = (new SplitProcessor.Factory()).create(splitConfig);
|
||||
Map appendConfig = new HashMap<>();
|
||||
appendConfig.put("field", "flags");
|
||||
appendConfig.put("value", Collections.singletonList("additional_flag"));
|
||||
Processor appendProcessor = (new AppendProcessor.Factory(templateService)).create(appendConfig);
|
||||
CompoundProcessor compoundProcessor = new CompoundProcessor(splitProcessor, appendProcessor);
|
||||
Map<String, Object> source = new HashMap<>();
|
||||
source.put("flags", "new|hot|super|fun|interesting");
|
||||
IngestDocument ingestDocument = new IngestDocument(source, new HashMap<>());
|
||||
compoundProcessor.execute(ingestDocument);
|
||||
List<String> expectedFlags = Arrays.asList("new", "hot", "super", "fun", "interesting", "additional_flag");
|
||||
assertThat(ingestDocument.getFieldValue("flags", List.class), CoreMatchers.equalTo(expectedFlags));
|
||||
splitProcessor.execute(ingestDocument);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> flags = (List<String>)ingestDocument.getFieldValue("flags", List.class);
|
||||
assertThat(flags, equalTo(Arrays.asList("new", "hot", "super", "fun", "interesting")));
|
||||
ingestDocument.appendFieldValue("flags", "additional_flag");
|
||||
assertThat(ingestDocument.getFieldValue("flags", List.class), equalTo(Arrays.asList("new", "hot", "super", "fun", "interesting", "additional_flag")));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue