use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class AbstractLogstashPluginAttributesMapperTest method mapAttributes_with_defaults_should_use_the_actual_value_from_the_attribute_when_it_is_present.
@Test
void mapAttributes_with_defaults_should_use_the_actual_value_from_the_attribute_when_it_is_present() {
final String defaultSettingName = UUID.randomUUID().toString();
final String defaultSettingValue = UUID.randomUUID().toString();
final String attributeValue = UUID.randomUUID().toString();
when(mappings.getDefaultSettings()).thenReturn(Collections.singletonMap(defaultSettingName, defaultSettingValue));
when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(defaultSettingName, defaultSettingName));
final LogstashAttribute logstashAttribute = mock(LogstashAttribute.class);
when(logstashAttribute.getAttributeName()).thenReturn(defaultSettingName);
final LogstashAttributeValue logstashAttributeValue = mock(LogstashAttributeValue.class);
when(logstashAttribute.getAttributeValue()).thenReturn(logstashAttributeValue);
when(logstashAttributeValue.getValue()).thenReturn(attributeValue);
final List<LogstashAttribute> logstashAttributes = Collections.singletonList(logstashAttribute);
final List<PluginModel> pluginModels = createObjectUnderTest().mapAttributes(logstashAttributes, mappings);
assertThat(pluginModels, notNullValue());
assertThat(pluginModels.size(), equalTo(1));
final PluginModel actualPluginModel = pluginModels.get(0);
assertThat(actualPluginModel, notNullValue());
assertThat(actualPluginModel.getPluginSettings(), notNullValue());
assertThat(actualPluginModel.getPluginSettings(), hasKey(defaultSettingName));
assertThat(actualPluginModel.getPluginSettings().get(defaultSettingName), equalTo(attributeValue));
}
use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class DateLogstashPluginAttributesMapperTest method convert_match_attribute_with_nested_syntax_from_list_to_date_match_list_test.
@Test
void convert_match_attribute_with_nested_syntax_from_list_to_date_match_list_test() {
final LogstashAttribute dateMatchAttribute = buildDateMatchLogstashAttribute(Arrays.asList("[data][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("/data/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 DateLogstashPluginAttributesMapperTest method convert_target_attribute_with_nested_syntax_from_list_to_date_match_list_test.
@Test
void convert_target_attribute_with_nested_syntax_from_list_to_date_match_list_test() {
final LogstashAttribute dateMatchAttribute = buildDateMatchLogstashAttribute(Arrays.asList("[data][logdate]", "yyyy-MM-dd"));
final String dataPrepperMatchAttribute = "match";
final String dataPrepperDestinationAttribute = "destination";
final LogstashAttribute targetLogstashAttribute = mock(LogstashAttribute.class);
final LogstashAttributeValue logstashAttributeValue = mock(LogstashAttributeValue.class);
when(logstashAttributeValue.getValue()).thenReturn("[outer][inner]");
when(targetLogstashAttribute.getAttributeName()).thenReturn("target");
when(targetLogstashAttribute.getAttributeValue()).thenReturn(logstashAttributeValue);
Map<String, String> mappedAttributeNames = new HashMap<>();
mappedAttributeNames.put(LOGSTASH_DATE_MATCH_ATTRIBUTE_NAME, dataPrepperMatchAttribute);
mappedAttributeNames.put("target", dataPrepperDestinationAttribute);
final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
when(mappings.getMappedAttributeNames()).thenReturn(mappedAttributeNames);
when(mappings.getNestedSyntaxAttributeNames()).thenReturn(Collections.singletonList("target"));
final List<PluginModel> actualPluginModel = dateLogstashPluginAttributesMapper.mapAttributes(Arrays.asList(targetLogstashAttribute, 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("/data/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()));
assertThat(actualPluginModel.get(0).getPluginSettings(), hasKey("destination"));
final String expectedDestinationSettings = "/outer/inner";
final String actualDestinationSettings = (String) actualPluginModel.get(0).getPluginSettings().get("destination");
assertThat(actualDestinationSettings, notNullValue());
assertThat(actualDestinationSettings, equalTo(expectedDestinationSettings));
}
use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.
the class DateLogstashPluginAttributesMapperTest method convert_match_attribute_with_multiple_patterns_from_list_to_date_match_list_test.
@Test
void convert_match_attribute_with_multiple_patterns_from_list_to_date_match_list_test() {
final LogstashAttribute dateMatchAttribute = buildDateMatchLogstashAttribute(Arrays.asList("logdate", "yyyy-MM-dd", "yyyy-MM-dd hh:mm:ss"));
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", Arrays.asList("yyyy-MM-dd", "yyyy-MM-dd hh:mm:ss")));
final List<DateProcessorConfig.DateMatch> actualMatchSettings = (List<DateProcessorConfig.DateMatch>) actualPluginModel.get(0).getPluginSettings().get(dataPrepperMatchAttribute);
assertThat(actualMatchSettings, notNullValue());
assertThat(actualMatchSettings.size(), equalTo(1));
assertThat(actualMatchSettings.get(0).getPatterns().size(), equalTo(2));
assertThat(actualPluginModel.get(0).getPluginSettings(), hasKey(dataPrepperMatchAttribute));
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 DataPrepperServerConfigurationTest method testGivingInsecureConfigThenCreateInsecureSettings.
@Test
public void testGivingInsecureConfigThenCreateInsecureSettings() {
final PluginModel pluginModel = mock(PluginModel.class);
when(pluginModel.getPluginName()).thenReturn("unauthenticated");
final PluginSetting pluginSetting = serverConfiguration.pluginSetting(pluginModel);
assertThat(pluginSetting.getName(), is("unauthenticated"));
assertThat(pluginSetting.getSettings().isEmpty(), is(true));
}
Aggregations