[TEST] Simplify SplitProcessorTests#testSplitAppendable to not require compound and append processor

This commit is contained in:
javanna 2016-01-22 12:03:36 +01:00 committed by Luca Cavanna
parent e860f9ddda
commit 17a36aecff
1 changed files with 8 additions and 15 deletions

View File

@ -19,14 +19,10 @@
package org.elasticsearch.ingest.processor; 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.RandomDocumentPicks;
import org.elasticsearch.ingest.core.IngestDocument;
import org.elasticsearch.ingest.core.Processor; import org.elasticsearch.ingest.core.Processor;
import org.elasticsearch.ingest.core.TemplateService;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.hamcrest.CoreMatchers;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -84,21 +80,18 @@ public class SplitProcessorTests extends ESTestCase {
} }
public void testSplitAppendable() throws Exception { public void testSplitAppendable() throws Exception {
TemplateService templateService = TestTemplateService.instance(); Map<String, Object> splitConfig = new HashMap<>();
Map splitConfig = new HashMap<>();
splitConfig.put("field", "flags"); splitConfig.put("field", "flags");
splitConfig.put("separator", "\\|"); splitConfig.put("separator", "\\|");
Processor splitProcessor = (new SplitProcessor.Factory()).create(splitConfig); 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<>(); Map<String, Object> source = new HashMap<>();
source.put("flags", "new|hot|super|fun|interesting"); source.put("flags", "new|hot|super|fun|interesting");
IngestDocument ingestDocument = new IngestDocument(source, new HashMap<>()); IngestDocument ingestDocument = new IngestDocument(source, new HashMap<>());
compoundProcessor.execute(ingestDocument); splitProcessor.execute(ingestDocument);
List<String> expectedFlags = Arrays.asList("new", "hot", "super", "fun", "interesting", "additional_flag"); @SuppressWarnings("unchecked")
assertThat(ingestDocument.getFieldValue("flags", List.class), CoreMatchers.equalTo(expectedFlags)); 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")));
} }
} }