Search in sources :

Example 1 with InvalidPluginConfigurationException

use of com.amazon.dataprepper.model.plugin.InvalidPluginConfigurationException in project data-prepper by opensearch-project.

the class DefaultPluginFactoryIT method loadPlugin_should_throw_when_a_plugin_configuration_is_invalid.

@Test
void loadPlugin_should_throw_when_a_plugin_configuration_is_invalid() {
    final String optionalStringValue = UUID.randomUUID().toString();
    final Map<String, Object> pluginSettingMap = new HashMap<>();
    pluginSettingMap.put("optional_string", optionalStringValue);
    final PluginSetting pluginSetting = createPluginSettings(pluginSettingMap);
    final DefaultPluginFactory objectUnderTest = createObjectUnderTest();
    final InvalidPluginConfigurationException actualException = assertThrows(InvalidPluginConfigurationException.class, () -> objectUnderTest.loadPlugin(TestPluggableInterface.class, pluginSetting));
    assertThat(actualException.getMessage(), notNullValue());
    assertThat(actualException.getMessage(), equalTo("Plugin test_plugin in pipeline " + pipelineName + " is configured incorrectly: requiredString must not be null"));
}
Also used : InvalidPluginConfigurationException(com.amazon.dataprepper.model.plugin.InvalidPluginConfigurationException) HashMap(java.util.HashMap) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting) Test(org.junit.jupiter.api.Test)

Example 2 with InvalidPluginConfigurationException

use of com.amazon.dataprepper.model.plugin.InvalidPluginConfigurationException in project data-prepper by opensearch-project.

the class PluginConfigurationConverterTest method convert_with_other_target_should_throw_exception_when_there_are_constraint_violations.

@Test
void convert_with_other_target_should_throw_exception_when_there_are_constraint_violations() {
    final String value = UUID.randomUUID().toString();
    given(pluginSetting.getSettings()).willReturn(Collections.singletonMap("my_value", value));
    final String pluginName = UUID.randomUUID().toString();
    given(pluginSetting.getName()).willReturn(pluginName);
    final String pipelineName = UUID.randomUUID().toString();
    given(pluginSetting.getPipelineName()).willReturn(pipelineName);
    @SuppressWarnings("unchecked") final ConstraintViolation<Object> constraintViolation = mock(ConstraintViolation.class);
    final String errorMessage = UUID.randomUUID().toString();
    given(constraintViolation.getMessage()).willReturn(errorMessage);
    final String propertyPathString = UUID.randomUUID().toString();
    final Path propertyPath = mock(Path.class);
    given(propertyPath.toString()).willReturn(propertyPathString);
    given(constraintViolation.getPropertyPath()).willReturn(propertyPath);
    given(validator.validate(any())).willReturn(Collections.singleton(constraintViolation));
    final PluginConfigurationConverter objectUnderTest = createObjectUnderTest();
    final InvalidPluginConfigurationException actualException = assertThrows(InvalidPluginConfigurationException.class, () -> objectUnderTest.convert(TestConfiguration.class, pluginSetting));
    assertThat(actualException.getMessage(), containsString(pluginName));
    assertThat(actualException.getMessage(), containsString(pipelineName));
    assertThat(actualException.getMessage(), containsString(propertyPathString));
    assertThat(actualException.getMessage(), containsString(errorMessage));
}
Also used : Path(jakarta.validation.Path) InvalidPluginConfigurationException(com.amazon.dataprepper.model.plugin.InvalidPluginConfigurationException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

InvalidPluginConfigurationException (com.amazon.dataprepper.model.plugin.InvalidPluginConfigurationException)2 Test (org.junit.jupiter.api.Test)2 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)1 Path (jakarta.validation.Path)1 HashMap (java.util.HashMap)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1