use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class DateLogstashPluginAttributesMapperTest method convert_match_attribute_with_single_pattern_from_list_to_date_match_list_test.
@Test
void convert_match_attribute_with_single_pattern_from_list_to_date_match_list_test() {
final LogstashAttribute dateMatchAttribute = buildDateMatchLogstashAttribute(Arrays.asList("logdate", "yyyy-MM-dd"));
final String dataPrepperMatchAttribute = "match";
final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(LOGSTASH_DATE_MATCH_ATTRIBUTE_NAME, dataPrepperMatchAttribute));
final List<PluginModel> actualPluginModel = dateLogstashPluginAttributesMapper.mapAttributes(Collections.singletonList(dateMatchAttribute), mappings);
assertThat(actualPluginModel, notNullValue());
assertThat(actualPluginModel.size(), equalTo(1));
assertThat(actualPluginModel.get(0), notNullValue());
final List<DateProcessorConfig.DateMatch> expectedMatchSettings = Collections.singletonList(new DateProcessorConfig.DateMatch("logdate", Collections.singletonList("yyyy-MM-dd")));
final List<DateProcessorConfig.DateMatch> actualMatchSettings = (List<DateProcessorConfig.DateMatch>) actualPluginModel.get(0).getPluginSettings().get(dataPrepperMatchAttribute);
assertThat(actualMatchSettings, notNullValue());
assertThat(actualMatchSettings.size(), equalTo(1));
assertThat(actualPluginModel.get(0).getPluginSettings(), hasKey(dataPrepperMatchAttribute));
assertThat(actualMatchSettings.get(0).getPatterns().size(), equalTo(1));
assertThat(actualMatchSettings.get(0).getKey(), equalTo(expectedMatchSettings.get(0).getKey()));
assertThat(actualMatchSettings.get(0).getPatterns(), equalTo(expectedMatchSettings.get(0).getPatterns()));
}
use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class GrokLogstashPluginAttributesMapperTest method mapAttributes_sets_mapped_attributes_besides_match.
@Test
void mapAttributes_sets_mapped_attributes_besides_match() {
final String value = UUID.randomUUID().toString();
final String logstashAttributeName = UUID.randomUUID().toString();
final LogstashAttribute logstashAttribute = mock(LogstashAttribute.class);
final LogstashAttributeValue logstashAttributeValue = mock(LogstashAttributeValue.class);
when(logstashAttributeValue.getValue()).thenReturn(value);
when(logstashAttribute.getAttributeName()).thenReturn(logstashAttributeName);
when(logstashAttribute.getAttributeValue()).thenReturn(logstashAttributeValue);
final String dataPrepperAttribute = UUID.randomUUID().toString();
final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(logstashAttributeName, dataPrepperAttribute));
final List<PluginModel> actualPluginModel = createObjectUnderTest().mapAttributes(Collections.singletonList(logstashAttribute), mappings);
assertThat(actualPluginModel, Matchers.notNullValue());
assertThat(actualPluginModel.size(), Matchers.equalTo(1));
assertThat(actualPluginModel.get(0), Matchers.notNullValue());
assertThat(actualPluginModel.get(0).getPluginSettings(), notNullValue());
assertThat(actualPluginModel.get(0).getPluginSettings().size(), equalTo(1));
assertThat(actualPluginModel.get(0).getPluginSettings(), hasKey(dataPrepperAttribute));
assertThat(actualPluginModel.get(0).getPluginSettings().get(dataPrepperAttribute), equalTo(value));
}
use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class GrokLogstashPluginAttributesMapperTest method mapAttributes_converts_nested_syntax_in_overwrite_mapped_attributes.
@Test
void mapAttributes_converts_nested_syntax_in_overwrite_mapped_attributes() {
final LogstashAttribute matchMultiKeysLogstashAttribute = prepareOverwriteLogstashAttribute(Arrays.asList("[outer][key1]", "[outer][key2]"));
final List<LogstashAttribute> grokAttributes = Collections.singletonList(matchMultiKeysLogstashAttribute);
final List<String> expectedOverwriteKeys = Arrays.asList("/outer/key1", "/outer/key2");
final String dataPrepperOverwriteAttribute = "keys_to_overwrite";
final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap("overwrite", dataPrepperOverwriteAttribute));
final List<PluginModel> actualPluginModels = createObjectUnderTest().mapAttributes(grokAttributes, mappings);
assertThat(actualPluginModels, notNullValue());
assertThat(actualPluginModels.size(), equalTo(1));
assertThat(actualPluginModels.get(0).getPluginSettings(), hasKey(dataPrepperOverwriteAttribute));
assertThat(actualPluginModels.get(0).getPluginSettings().get(dataPrepperOverwriteAttribute), equalTo(expectedOverwriteKeys));
}
use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class LogstashPluginMapperTest method mapPlugin_with_custom_plugin_mapper_produces_plugins.
@Test
void mapPlugin_with_custom_plugin_mapper_produces_plugins() {
final LogstashPlugin logstashPlugin = mock(LogstashPlugin.class);
when(logstashPlugin.getPluginName()).thenReturn("mutate");
when(pluginMapperProvider.getAttributesMapper(any(LogstashMappingModel.class))).thenReturn(new MutateMapper());
final LogstashPluginMapper objectUnderTest = createObjectUnderTest();
final List<PluginModel> pluginModels = objectUnderTest.mapPlugin(logstashPlugin);
assertThat(pluginModels, notNullValue());
}
use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class LogstashPluginMapperTest method mapPlugin_should_return_PluginModel_with_mapped_attributes.
@Test
void mapPlugin_should_return_PluginModel_with_mapped_attributes() {
final LogstashPlugin logstashPlugin = mock(LogstashPlugin.class);
when(logstashPlugin.getPluginName()).thenReturn("amazon_es");
final Map<String, Object> mappedPluginSettings = Collections.singletonMap(UUID.randomUUID().toString(), UUID.randomUUID().toString());
when(logstashPluginAttributesMapper.mapAttributes(anyList(), any(LogstashAttributesMappings.class))).thenReturn(Collections.singletonList(new PluginModel("opensearch", mappedPluginSettings)));
final List<PluginModel> pluginModels = createObjectUnderTest().mapPlugin(logstashPlugin);
assertThat(pluginModels, notNullValue());
assertThat(pluginModels.get(0).getPluginSettings(), notNullValue());
assertThat(pluginModels.get(0).getPluginSettings(), equalTo(mappedPluginSettings));
}
Aggregations