|
10 | 10 |
|
11 | 11 | import org.elasticsearch.ElasticsearchException; |
12 | 12 | import org.elasticsearch.ElasticsearchParseException; |
| 13 | +import org.elasticsearch.ingest.ConfigurationUtils; |
13 | 14 | import org.elasticsearch.ingest.TestTemplateService; |
14 | 15 | import org.elasticsearch.test.ESTestCase; |
15 | 16 | import org.junit.Before; |
|
20 | 21 | import java.util.Map; |
21 | 22 |
|
22 | 23 | import static org.hamcrest.CoreMatchers.equalTo; |
| 24 | +import static org.hamcrest.Matchers.containsString; |
23 | 25 |
|
24 | 26 | public class AppendProcessorFactoryTests extends ESTestCase { |
25 | 27 |
|
@@ -92,4 +94,26 @@ public void testInvalidMustacheTemplate() throws Exception { |
92 | 94 | assertThat(exception.getMessage(), equalTo("java.lang.RuntimeException: could not compile script")); |
93 | 95 | assertThat(exception.getMetadata("es.processor_tag").get(0), equalTo(processorTag)); |
94 | 96 | } |
| 97 | + |
| 98 | + public void testMediaType() throws Exception { |
| 99 | + // valid media type |
| 100 | + String expectedMediaType = randomFrom(ConfigurationUtils.VALID_MEDIA_TYPES); |
| 101 | + Map<String, Object> config = new HashMap<>(); |
| 102 | + config.put("field", "field1"); |
| 103 | + config.put("value", "value1"); |
| 104 | + config.put("media_type", expectedMediaType); |
| 105 | + String processorTag = randomAlphaOfLength(10); |
| 106 | + AppendProcessor appendProcessor = factory.create(null, processorTag, null, config); |
| 107 | + assertThat(appendProcessor.getTag(), equalTo(processorTag)); |
| 108 | + |
| 109 | + // invalid media type |
| 110 | + expectedMediaType = randomValueOtherThanMany(m -> Arrays.asList(ConfigurationUtils.VALID_MEDIA_TYPES).contains(m), |
| 111 | + () -> randomAlphaOfLengthBetween(5, 9)); |
| 112 | + final Map<String, Object> config2 = new HashMap<>(); |
| 113 | + config2.put("field", "field1"); |
| 114 | + config2.put("value", "value1"); |
| 115 | + config2.put("media_type", expectedMediaType); |
| 116 | + ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> factory.create(null, processorTag, null, config2)); |
| 117 | + assertThat(e.getMessage(), containsString("property does not contain a supported media type [" + expectedMediaType + "]")); |
| 118 | + } |
95 | 119 | } |
0 commit comments