From ccc53fd1d03f53963d8a65f259b0b039710b9fb7 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Tue, 5 Dec 2023 18:22:37 +0000 Subject: [PATCH] Mapping defaults to ConfigSourceContext --- .../main/java/io/smallrye/config/SmallRyeConfigBuilder.java | 3 +++ .../java/io/smallrye/config/ConfigSourceFactoryTest.java | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java index 3dea990b0..e4f30ad65 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java @@ -697,6 +697,9 @@ public SmallRyeConfig build() { .forEach(customizer -> customizer.configBuilder(SmallRyeConfigBuilder.this)); ConfigMappingProvider mappingProvider = mappingsBuilder.build(); + for (Map.Entry entry : mappingProvider.getDefaultValues().entrySet()) { + defaultValues.putIfAbsent(entry.getKey(), entry.getValue()); + } SmallRyeConfig config = new SmallRyeConfig(this); ConfigMappings.mapConfiguration(config, mappingProvider); return config; diff --git a/implementation/src/test/java/io/smallrye/config/ConfigSourceFactoryTest.java b/implementation/src/test/java/io/smallrye/config/ConfigSourceFactoryTest.java index 46e7fd2ef..8eb0b96df 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigSourceFactoryTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigSourceFactoryTest.java @@ -48,10 +48,11 @@ void expression() { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() .withSources(new ExpressionConfigSourceFactory()) - .withSources(config("expression.value", "12${DEFAULT:}")) - .withSources(new EnvConfigSource(Map.of("DEFAULT", "34"), 100)) + .withSources(new EnvConfigSource(Map.of("DEFAULT", "1234"), 100)) + .withMapping(Expression.class) .build(); + assertEquals("1234", config.getConfigMapping(Expression.class).value()); assertEquals("1234", config.getRawValue("factory.expression")); }