/* * Copyright [2021] [your_name] * * Licensed 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 usi.vaa.elasticsearch.plugin.ingest.lookup; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.test.ESTestCase; import org.junit.BeforeClass; import java.util.HashMap; import java.util.Map; import static usi.vaa.elasticsearch.plugin.ingest.lookup.LookupProcessor.*; public class LookupProcessorFactoryTests extends ESTestCase { private static String tag; private static String description; private static LookupProcessor.Factory factory; @BeforeClass public static void defaultSettings() { tag = "lookup-test"; description = "lookup pipeline test"; factory = new LookupProcessor.Factory(); } private LookupProcessor callFactory(final Map config) { // if the `config` map is not cloned here java.lang.UnsupportedOperationException is thrown // for some reflective magic related reason, therefore do not remove return factory.create(null, tag, description, new HashMap<>(config)); } public void testDefaultConfiguration() { final String testField = "theTestField"; final Map testMap = Map.of( "C001", "tyre", "C010", "front wing", "C100", "damper" ); final Map config = Map.of( FIELD_PROPERTY, testField, LOOKUP_MAP_PROPERTY, testMap ); final LookupProcessor processor = callFactory(config); assertEquals(tag, processor.getTag()); assertEquals(description, processor.getDescription()); assertEquals(testMap, processor.getLookupMap()); assertEquals(testField, processor.getField()); } public void testInvalidConfiguration() { expectThrows(ElasticsearchParseException.class, () -> callFactory(Map.of("invalid", "config"))); } }