From c063b430ed6f88ba4c3ba0a66e2618b84d1fa02e Mon Sep 17 00:00:00 2001 From: pj-cegeka <119848850+pj-cegeka@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:52:37 +0200 Subject: [PATCH] Fix: expand empty check on member types (#657) --- ...ionObjectProcessorPropertyDescriptors.java | 2 +- .../LdioVersionObjectCreatorAutoConfig.java | 9 +++-- ...dioVersionObjectCreatorAutoConfigTest.java | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfigTest.java diff --git a/ldi-nifi/ldi-nifi-processors/create-version-object-processor/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/processors/config/CreateVersionObjectProcessorPropertyDescriptors.java b/ldi-nifi/ldi-nifi-processors/create-version-object-processor/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/processors/config/CreateVersionObjectProcessorPropertyDescriptors.java index ab1e96111..6052224be 100644 --- a/ldi-nifi/ldi-nifi-processors/create-version-object-processor/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/processors/config/CreateVersionObjectProcessorPropertyDescriptors.java +++ b/ldi-nifi/ldi-nifi-processors/create-version-object-processor/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldi/processors/config/CreateVersionObjectProcessorPropertyDescriptors.java @@ -27,7 +27,7 @@ private CreateVersionObjectProcessorPropertyDescriptors() { .displayName("IRIs to member RDF syntax type") .description("Comma separated list of IRIs that declare a http://www.w3.org/1999/02/22-rdf-syntax-ns#type of all possible members") .required(true) - .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) + .addValidator(StandardValidators.NON_BLANK_VALIDATOR) .build(); public static final PropertyDescriptor DELIMITER = new PropertyDescriptor.Builder() diff --git a/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfig.java b/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfig.java index 4059741fd..4a5eeddad 100644 --- a/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfig.java +++ b/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/main/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfig.java @@ -45,12 +45,15 @@ public LdioTransformer configure(ComponentProperties properties) { .map(PropertyExtractor.class::cast) .orElseGet(EmptyPropertyExtractor::new); - List memberTypes = properties.getPropertyList(MEMBER_TYPE).stream() - .map(initModel::createResource).toList(); - if (memberTypes.isEmpty()) { + List memberTypesPropertyList = properties.getPropertyList(MEMBER_TYPE); + + if (memberTypesPropertyList.isEmpty() || memberTypesPropertyList.stream().allMatch(String::isEmpty)) { throw new ConfigPropertyMissingException(properties.getPipelineName(), properties.getComponentName(), MEMBER_TYPE); } + List memberTypes = memberTypesPropertyList.stream() + .map(initModel::createResource).toList(); + String delimiter = properties.getOptionalProperty(DELIMITER).orElse("/"); Property generatedAtProperty = properties.getOptionalProperty(GENERATED_AT) diff --git a/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfigTest.java b/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfigTest.java new file mode 100644 index 000000000..6226b743d --- /dev/null +++ b/ldi-orchestrator/ldio-connectors/ldio-version-object-creator/src/test/java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioVersionObjectCreatorAutoConfigTest.java @@ -0,0 +1,40 @@ +package be.vlaanderen.informatievlaanderen.ldes.ldio.config; + +import be.vlaanderen.informatievlaanderen.ldes.ldio.configurator.LdioConfigurator; +import be.vlaanderen.informatievlaanderen.ldes.ldio.exception.ConfigPropertyMissingException; +import be.vlaanderen.informatievlaanderen.ldes.ldio.valueobjects.ComponentProperties; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +import static be.vlaanderen.informatievlaanderen.ldes.ldio.config.LdioVersionObjectCreatorAutoConfig.LdioVersionObjectCreatorTransformerConfigurator.MEMBER_TYPE; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class LdioVersionObjectCreatorAutoConfigTest { + private final LdioConfigurator configurator = new LdioVersionObjectCreatorAutoConfig().ldioConfigurator(); + @ParameterizedTest + @ArgumentsSource(configProvider.class) + void when_NoMemberTypes_Then_exceptionIsThrown(Map config) { + ComponentProperties componentProperties = new ComponentProperties("pipelineName", "cName", config); + + assertThrows(ConfigPropertyMissingException.class,() -> configurator.configure(componentProperties)) ; + } + + static class configProvider implements ArgumentsProvider { + @Override + public Stream provideArguments(ExtensionContext extensionContext) { + Map empty = new HashMap<>(); + empty.put(MEMBER_TYPE, ""); + return Stream.of( + Arguments.of(new HashMap()), + Arguments.of(empty) + ); + } + } +} \ No newline at end of file