Search in sources :

Example 11 with PluginModel

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));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttributeValue(org.opensearch.dataprepper.logstash.model.LogstashAttributeValue) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) Test(org.junit.jupiter.api.Test)

Example 12 with PluginModel

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()));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) ArrayList(java.util.ArrayList) List(java.util.List) DateProcessorConfig(com.amazon.dataprepper.plugins.processor.date.DateProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 13 with PluginModel

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));
}
Also used : LogstashAttributeValue(org.opensearch.dataprepper.logstash.model.LogstashAttributeValue) HashMap(java.util.HashMap) DateProcessorConfig(com.amazon.dataprepper.plugins.processor.date.DateProcessorConfig) PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 14 with PluginModel

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()));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) ArrayList(java.util.ArrayList) List(java.util.List) DateProcessorConfig(com.amazon.dataprepper.plugins.processor.date.DateProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 15 with PluginModel

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));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Aggregations

PluginModel (com.amazon.dataprepper.model.configuration.PluginModel)31 Test (org.junit.jupiter.api.Test)21 LogstashAttribute (org.opensearch.dataprepper.logstash.model.LogstashAttribute)17 List (java.util.List)8 ArrayList (java.util.ArrayList)6 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)5 DateProcessorConfig (com.amazon.dataprepper.plugins.processor.date.DateProcessorConfig)5 HashMap (java.util.HashMap)5 LogstashAttributeValue (org.opensearch.dataprepper.logstash.model.LogstashAttributeValue)5 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 LogstashPlugin (org.opensearch.dataprepper.logstash.model.LogstashPlugin)3 DataPrepperConfiguration (com.amazon.dataprepper.parser.model.DataPrepperConfiguration)2 Objects (java.util.Objects)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 LogstashMappingException (org.opensearch.dataprepper.logstash.exception.LogstashMappingException)2 PipelineModel (com.amazon.dataprepper.model.configuration.PipelineModel)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1