Removed pipeline tests with a simpler tests

The PipelineTests tried to test if the configured map/list in set processor wasn't modified while documents were ingested. Creating a pipeline programmatically created more noise than the test needed. The new tests in IngestDocumentTests have the same goal, but is much smaller and clearer by directly testing against IngestDocument.
This commit is contained in:
Martijn van Groningen 2015-12-03 15:19:04 +01:00
parent f427ad2094
commit 6acf8ec263
2 changed files with 24 additions and 52 deletions

View File

@ -551,4 +551,28 @@ public class IngestDocumentTests extends ESTestCase {
assertThat("iteration: " + i, copy, not(sameInstance(map)));
}
}
public void testDeepCopyDoesNotChangeProvidedMap() {
Map<String, Object> myPreciousMap = new HashMap<>();
myPreciousMap.put("field2", "value2");
IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", new HashMap<>());
ingestDocument.setFieldValue("field1", myPreciousMap);
ingestDocument.removeField("field1.field2");
assertThat(myPreciousMap.size(), equalTo(1));
assertThat(myPreciousMap.get("field2"), equalTo("value2"));
}
public void testDeepCopyDoesNotChangeProvidedList() {
List<String> myPreciousList = new ArrayList<>();
myPreciousList.add("value");
IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", new HashMap<>());
ingestDocument.setFieldValue("field1", myPreciousList);
ingestDocument.removeField("field1.0");
assertThat(myPreciousList.size(), equalTo(1));
assertThat(myPreciousList.get(0), equalTo("value"));
}
}

View File

@ -1,52 +0,0 @@
package org.elasticsearch.ingest;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.ingest.processor.Processor;
import org.elasticsearch.ingest.processor.set.SetProcessor;
import org.elasticsearch.ingest.processor.remove.RemoveProcessor;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matchers;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class PipelineTests extends ESTestCase {
public void testProcessorSettingsRemainUntouched() throws Exception {
Map<String, Object> subField = new HashMap<>();
subField.put("_subfield", "value");
Map<String, Object> fieldSettings = new HashMap<>();
fieldSettings.put("_field", subField);
Map<String, Object> addSettings = new HashMap<>();
addSettings.put("fields", fieldSettings);
Map<String, Object> removeSettings = new HashMap<>();
removeSettings.put("fields", Collections.singletonList("_field._subfield"));
Pipeline pipeline = createPipeline(processorConfig(SetProcessor.TYPE, addSettings), processorConfig(RemoveProcessor.TYPE, removeSettings));
IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", new HashMap<>());
pipeline.execute(ingestDocument);
assertThat(ingestDocument.getSource().get("_field"), Matchers.notNullValue());
assertThat(((Map) ingestDocument.getSource().get("_field")).get("_subfield"), Matchers.nullValue());
assertThat(((Map) fieldSettings.get("_field")).get("_subfield"), Matchers.equalTo("value"));
}
private Pipeline createPipeline(Map<String, Object>... processorConfigs) throws Exception {
Map<String, Object> config = new HashMap<>();
config.put("processors", Arrays.asList(processorConfigs));
Map<String, Processor.Factory> factoryRegistry = new HashMap<>();
factoryRegistry.put(SetProcessor.TYPE, new SetProcessor.Factory());
factoryRegistry.put(RemoveProcessor.TYPE, new RemoveProcessor.Factory());
Pipeline.Factory factory = new Pipeline.Factory();
return factory.create("_id", config, factoryRegistry);
}
private Map<String, Object> processorConfig(String type, Map<String, Object> settings) {
Map<String, Object> processorConfig = new HashMap<>();
processorConfig.put(type, settings);
return processorConfig;
}
}