Skip to content

Commit

Permalink
Fix: expand empty check on member types (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
pj-cegeka authored Jul 2, 2024
1 parent 365bb13 commit c063b43
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ public LdioTransformer configure(ComponentProperties properties) {
.map(PropertyExtractor.class::cast)
.orElseGet(EmptyPropertyExtractor::new);

List<Resource> memberTypes = properties.getPropertyList(MEMBER_TYPE).stream()
.map(initModel::createResource).toList();
if (memberTypes.isEmpty()) {
List<String> memberTypesPropertyList = properties.getPropertyList(MEMBER_TYPE);

if (memberTypesPropertyList.isEmpty() || memberTypesPropertyList.stream().allMatch(String::isEmpty)) {
throw new ConfigPropertyMissingException(properties.getPipelineName(), properties.getComponentName(), MEMBER_TYPE);
}

List<Resource> memberTypes = memberTypesPropertyList.stream()
.map(initModel::createResource).toList();

String delimiter = properties.getOptionalProperty(DELIMITER).orElse("/");

Property generatedAtProperty = properties.getOptionalProperty(GENERATED_AT)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> config) {
ComponentProperties componentProperties = new ComponentProperties("pipelineName", "cName", config);

assertThrows(ConfigPropertyMissingException.class,() -> configurator.configure(componentProperties)) ;
}

static class configProvider implements ArgumentsProvider {
@Override
public Stream<Arguments> provideArguments(ExtensionContext extensionContext) {
Map<String, String> empty = new HashMap<>();
empty.put(MEMBER_TYPE, "");
return Stream.of(
Arguments.of(new HashMap<String, String>()),
Arguments.of(empty)
);
}
}
}

0 comments on commit c063b43

Please sign in to comment.