|
@@ -19,6 +19,7 @@
|
|
|
|
|
|
package org.elasticsearch.ingest;
|
|
|
|
|
|
+import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.ElasticsearchParseException;
|
|
|
import org.elasticsearch.script.ScriptService;
|
|
|
import org.elasticsearch.script.TemplateScript;
|
|
@@ -32,6 +33,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
@@ -114,6 +116,36 @@ public class ConfigurationUtilsTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testReadMimeProperty() {
|
|
|
+ // valid mime type
|
|
|
+ String expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES);
|
|
|
+ config.put("mime_type", expectedMimeType);
|
|
|
+ String readMimeType = ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", "");
|
|
|
+ assertThat(readMimeType, equalTo(expectedMimeType));
|
|
|
+
|
|
|
+ // missing mime type with valid default
|
|
|
+ expectedMimeType = randomFrom(ConfigurationUtils.VALID_MIME_TYPES);
|
|
|
+ config.remove("mime_type");
|
|
|
+ readMimeType = ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", expectedMimeType);
|
|
|
+ assertThat(readMimeType, equalTo(expectedMimeType));
|
|
|
+
|
|
|
+ // invalid mime type
|
|
|
+ expectedMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m),
|
|
|
+ () -> randomAlphaOfLengthBetween(5, 9));
|
|
|
+ config.put("mime_type", expectedMimeType);
|
|
|
+ ElasticsearchException e = expectThrows(ElasticsearchException.class,
|
|
|
+ () -> ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", ""));
|
|
|
+ assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + expectedMimeType + "]"));
|
|
|
+
|
|
|
+ // missing mime type with invalid default
|
|
|
+ final String invalidDefaultMimeType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MIME_TYPES).contains(m),
|
|
|
+ () -> randomAlphaOfLengthBetween(5, 9));
|
|
|
+ config.remove("mime_type");
|
|
|
+ e = expectThrows(ElasticsearchException.class,
|
|
|
+ () -> ConfigurationUtils.readMimeTypeProperty(null, null, config, "mime_type", invalidDefaultMimeType));
|
|
|
+ assertThat(e.getMessage(), containsString("property does not contain a supported MIME type [" + invalidDefaultMimeType + "]"));
|
|
|
+ }
|
|
|
+
|
|
|
public void testReadProcessors() throws Exception {
|
|
|
Processor processor = mock(Processor.class);
|
|
|
Map<String, Processor.Factory> registry =
|