diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestServiceTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestServiceTests.java new file mode 100644 index 00000000000..e44dc42cbe8 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/ingest/IngestServiceTests.java @@ -0,0 +1,53 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.ingest; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.plugins.IngestPlugin; +import org.elasticsearch.script.ScriptService; +import org.elasticsearch.test.ESTestCase; + +public class IngestServiceTests extends ESTestCase { + private final IngestPlugin DUMMY_PLUGIN = new IngestPlugin() { + @Override + public Map getProcessors(Environment env, ScriptService scriptService, TemplateService templateService) { + return Collections.singletonMap("foo", (factories, tag, config) -> null); + } + }; + + public void testIngestPlugin() { + IngestService ingestService = new IngestService(Settings.EMPTY, null, null, null, Collections.singletonList(DUMMY_PLUGIN)); + Map factories = ingestService.getPipelineStore().getProcessorFactories(); + assertTrue(factories.containsKey("foo")); + assertEquals(1, factories.size()); + } + + public void testIngestPluginDuplicate() { + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> + new IngestService(Settings.EMPTY, null, null, null, Arrays.asList(DUMMY_PLUGIN, DUMMY_PLUGIN)) + ); + assertTrue(e.getMessage(), e.getMessage().contains("already registered")); + } +}