Skip to content

Commit

Permalink
#569 fixed ConfigurationMappingLoaderTest
Browse files Browse the repository at this point in the history
  • Loading branch information
DirkMahler committed Aug 7, 2024
1 parent 40e8745 commit 7f2e4cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
* <p>
* The mechanism is based on Eclipse Micro Profile configuration.
*/
@NoArgsConstructor(access = PRIVATE)
@Slf4j
public class ConfigurationMappingLoader {

Expand Down Expand Up @@ -225,14 +229,17 @@ public C load(ConfigSource... additionalConfigSources) {
}

private void logConfigProblems(SmallRyeConfig interpolatedConfig) {
// Create final config including validation, including only jqassistant properties
Map<String, String> interpolatedProperties = stream(interpolatedConfig.getPropertyNames()
Map<String, String> 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<String, String> 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++) {
Expand All @@ -243,13 +250,13 @@ private void logConfigProblems(SmallRyeConfig interpolatedConfig) {
}

private List<ConfigSource> getExternalYamlConfigSources(File directory, List<Path> configLocations, int ordinal) {
List<ConfigSource> configSources = new ArrayList<>();
List<ConfigSource> 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<ConfigSource> getExternalYamlConfigSources(Path configLocationPath, int ordinal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 7f2e4cd

Please sign in to comment.