From 7f2e4cd056ab2098eedc598a2a3d2e29bc63ea13 Mon Sep 17 00:00:00 2001 From: Dirk Mahler Date: Wed, 7 Aug 2024 22:50:41 +0200 Subject: [PATCH] #569 fixed ConfigurationMappingLoaderTest --- .../ConfigurationMappingLoader.java | 21 ++++++++++++------- .../ConfigurationMappingLoaderTest.java | 14 ------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java index d73fa06a8..34da84cb5 100644 --- a/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java +++ b/core/runtime/src/main/java/com/buschmais/jqassistant/core/runtime/api/configuration/ConfigurationMappingLoader.java @@ -13,6 +13,8 @@ import io.smallrye.config.*; import io.smallrye.config.source.yaml.YamlConfigSource; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -22,12 +24,14 @@ import static java.util.Collections.list; import static java.util.stream.Collectors.*; import static java.util.stream.StreamSupport.stream; +import static lombok.AccessLevel.PRIVATE; /** * Defines the interface for loading runtime configuration. *

* The mechanism is based on Eclipse Micro Profile configuration. */ +@NoArgsConstructor(access = PRIVATE) @Slf4j public class ConfigurationMappingLoader { @@ -225,14 +229,17 @@ public C load(ConfigSource... additionalConfigSources) { } private void logConfigProblems(SmallRyeConfig interpolatedConfig) { - // Create final config including validation, including only jqassistant properties - Map interpolatedProperties = stream(interpolatedConfig.getPropertyNames() + Map filteredProperties = stream(interpolatedConfig.getPropertyNames() .spliterator(), false).filter(property -> property.startsWith(Configuration.PREFIX)) .filter(property -> !ignoreProperties.contains(property)) - .collect(toMap(property -> property, interpolatedConfig::getRawValue)); + .collect(toMap(property -> property, interpolatedConfig::getRawValue, (s1, s2) -> null, () -> new TreeMap<>())); + log.debug("jQAssistant config properties:"); + for (Map.Entry entry : filteredProperties.entrySet()) { + log.debug("\t{}={}", entry.getKey(), entry.getValue()); + } try { new SmallRyeConfigBuilder().withMapping(configurationMapping) - .withSources(new PropertiesConfigSource(interpolatedProperties, "jQAssistant Configuration", ConfigSource.DEFAULT_ORDINAL)) + .withSources(new PropertiesConfigSource(filteredProperties, "jQAssistant Configuration", ConfigSource.DEFAULT_ORDINAL)) .build(); } catch (ConfigValidationException configValidationException) { for (int i = 0; i < configValidationException.getProblemCount(); i++) { @@ -243,13 +250,13 @@ private void logConfigProblems(SmallRyeConfig interpolatedConfig) { } private List getExternalYamlConfigSources(File directory, List configLocations, int ordinal) { - List configSources = new ArrayList<>(); + List yamlConfigSources = new ArrayList<>(); for (Path configLocation : configLocations) { Path path = directory.toPath() .resolve(configLocation); - configSources.addAll(getExternalYamlConfigSources(path, ordinal)); + yamlConfigSources.addAll(getExternalYamlConfigSources(path, ordinal)); } - return configSources; + return yamlConfigSources; } private List getExternalYamlConfigSources(Path configLocationPath, int ordinal) { diff --git a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java index ff50bd1ae..041bb2d95 100644 --- a/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java +++ b/core/runtime/src/test/java/com/buschmais/jqassistant/core/runtime/impl/configuration/ConfigurationMappingLoaderTest.java @@ -9,7 +9,6 @@ import com.buschmais.jqassistant.core.scanner.api.configuration.Scan; import com.buschmais.jqassistant.core.shared.configuration.Plugin; -import io.smallrye.config.ConfigValidationException; import io.smallrye.config.PropertiesConfigSource; import io.smallrye.config.SysPropConfigSource; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -19,7 +18,6 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Tests for the {@link ConfigurationMappingLoader}. @@ -83,18 +81,6 @@ void profile() { .properties()).containsEntry("profile-user-value", "test-value"); } - @Test - void unknownProperty() { - String unknownProperty = "jqassistant.unknown"; - assertThatExceptionOfType(ConfigValidationException.class).isThrownBy(() -> { - ConfigurationMappingLoader.builder(TestConfiguration.class, emptyList()) - .withUserHome(USER_HOME) - .withWorkingDirectory(WORKING_DIRECTORY) - .load(new PropertiesConfigSource(Map.of(unknownProperty, "test value"), "Test", ConfigSource.DEFAULT_ORDINAL)); - }) - .withMessageContaining(unknownProperty); - } - @Test void ignoreProperty() { String unknownProperty = "jqassistant.unknown";