|
31 | 31 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
32 | 32 |
|
33 | 33 | import java.util.ArrayList;
|
| 34 | +import java.util.Collections; |
34 | 35 | import java.util.HashMap;
|
35 | 36 | import java.util.Iterator;
|
36 | 37 | import java.util.List;
|
|
43 | 44 | import org.eclipse.microprofile.config.spi.ConfigSource;
|
44 | 45 | import org.junit.jupiter.api.Test;
|
45 | 46 |
|
| 47 | +import io.smallrye.config.ConfigSourceFactory.ConfigurableConfigSourceFactory; |
46 | 48 | import io.smallrye.config.EnvConfigSource.EnvName;
|
47 | 49 |
|
48 | 50 | /**
|
@@ -520,7 +522,7 @@ interface Nested {
|
520 | 522 |
|
521 | 523 | @Test
|
522 | 524 | void mappingFactory() {
|
523 |
| - ConfigSourceFactory.ConfigurableConfigSourceFactory<MappingFactory> sourceFactory = new ConfigSourceFactory.ConfigurableConfigSourceFactory<>() { |
| 525 | + ConfigurableConfigSourceFactory<MappingFactory> sourceFactory = new ConfigurableConfigSourceFactory<>() { |
524 | 526 | @Override
|
525 | 527 | public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context, final MappingFactory mapping) {
|
526 | 528 | assertEquals("value", mapping.aValue());
|
@@ -801,6 +803,32 @@ interface Nested {
|
801 | 803 | }
|
802 | 804 | }
|
803 | 805 |
|
| 806 | + @Test |
| 807 | + void matchEnvVarWithFactory() { |
| 808 | + SmallRyeConfig config = new SmallRyeConfigBuilder() |
| 809 | + .withSources(new MatchEnvVarConfigSourceFactory()) |
| 810 | + .withSources(new EnvConfigSource(Map.of( |
| 811 | + "MAP_KEY", "value"), 300)) |
| 812 | + .withMapping(MatchEnvVarWithFactory.class) |
| 813 | + .build(); |
| 814 | + |
| 815 | + MatchEnvVarWithFactory mapping = config.getConfigMapping(MatchEnvVarWithFactory.class); |
| 816 | + |
| 817 | + assertEquals("value", mapping.map().get("key")); |
| 818 | + } |
| 819 | + |
| 820 | + @ConfigMapping(prefix = "") |
| 821 | + interface MatchEnvVarWithFactory { |
| 822 | + Map<String, String> map(); |
| 823 | + } |
| 824 | + |
| 825 | + static class MatchEnvVarConfigSourceFactory implements ConfigurableConfigSourceFactory<MatchEnvVarWithFactory> { |
| 826 | + @Override |
| 827 | + public Iterable<ConfigSource> getConfigSources(final ConfigSourceContext context, final MatchEnvVarWithFactory config) { |
| 828 | + return Collections.emptyList(); |
| 829 | + } |
| 830 | + } |
| 831 | + |
804 | 832 | private static boolean envSourceEquals(String name, String lookup) {
|
805 | 833 | return BOOLEAN_CONVERTER.convert(new EnvConfigSource(Map.of(name, "true"), 100).getValue(lookup));
|
806 | 834 | }
|
|
0 commit comments