-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #36389 from mkouba/component-test-config-mapping
QuarkusComponentTest: initial support for ConfigMapping
- 3.17.5
- 3.17.4
- 3.17.3
- 3.17.2
- 3.17.1
- 3.17.0
- 3.17.0.CR1
- 3.16.4
- 3.16.3
- 3.16.2
- 3.16.1
- 3.16.0
- 3.16.0.CR1
- 3.15.2
- 3.15.1
- 3.15.0
- 3.15.0.CR1
- 3.14.4
- 3.14.3
- 3.14.2
- 3.14.1
- 3.14.0
- 3.14.0.CR1
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13.0
- 3.13.0.CR1
- 3.12.3
- 3.12.2
- 3.12.1
- 3.12.0
- 3.12.0.CR1
- 3.11.3
- 3.11.2
- 3.11.1
- 3.11.0
- 3.11.0.CR1
- 3.10.2
- 3.10.1
- 3.10.0
- 3.10.0.CR1
- 3.9.5
- 3.9.4
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.9.0.CR2
- 3.9.0.CR1
- 3.8.6
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.8.0.CR1
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.7.0.CR1
- 3.6.9
- 3.6.8
- 3.6.7
- 3.6.6
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.6.0.CR1
Showing
4 changed files
with
149 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...rk/junit5-component/src/main/java/io/quarkus/test/component/ConfigMappingBeanCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.test.component; | ||
|
||
import io.quarkus.arc.BeanCreator; | ||
import io.quarkus.arc.SyntheticCreationalContext; | ||
import io.smallrye.config.SmallRyeConfig; | ||
|
||
public class ConfigMappingBeanCreator implements BeanCreator<Object> { | ||
|
||
@Override | ||
public Object create(SyntheticCreationalContext<Object> context) { | ||
String prefix = context.getParams().get("prefix").toString(); | ||
Class<?> mappingClass = tryLoad(context.getParams().get("mappingClass").toString()); | ||
SmallRyeConfig config = ConfigBeanCreator.getConfig().unwrap(SmallRyeConfig.class); | ||
return config.getConfigMapping(mappingClass, prefix); | ||
} | ||
|
||
static Class<?> tryLoad(String name) { | ||
try { | ||
return Thread.currentThread().getContextClassLoader().loadClass(name); | ||
} catch (ClassNotFoundException e) { | ||
throw new IllegalStateException("Unable to load type: " + name, e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...rk/junit5-component/src/test/java/io/quarkus/test/component/config/ConfigMappingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.test.component.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.component.QuarkusComponentTest; | ||
import io.quarkus.test.component.TestConfigProperty; | ||
import io.smallrye.config.ConfigMapping; | ||
import io.smallrye.config.WithDefault; | ||
|
||
@QuarkusComponentTest | ||
@TestConfigProperty(key = "foo.bar", value = "true") | ||
@TestConfigProperty(key = "foo.log.rotate", value = "true") | ||
public class ConfigMappingTest { | ||
|
||
@Inject | ||
Foo foo; | ||
|
||
@TestConfigProperty(key = "foo.oof", value = "boom") | ||
@Test | ||
public void testMapping() { | ||
assertTrue(foo.config.bar()); | ||
assertTrue(foo.config.log().rotate()); | ||
assertEquals("loom", foo.config.baz()); | ||
assertEquals("boom", foo.config.oof()); | ||
} | ||
|
||
@TestConfigProperty(key = "foo.oof", value = "boomboom") | ||
@Test | ||
public void testAnotherMapping() { | ||
assertTrue(foo.config.bar()); | ||
assertTrue(foo.config.log().rotate()); | ||
assertEquals("loom", foo.config.baz()); | ||
assertEquals("boomboom", foo.config.oof()); | ||
} | ||
|
||
@Singleton | ||
public static class Foo { | ||
|
||
@Inject | ||
FooConfig config; | ||
} | ||
|
||
@ConfigMapping(prefix = "foo") | ||
interface FooConfig { | ||
|
||
boolean bar(); | ||
|
||
@WithDefault("loom") | ||
String baz(); | ||
|
||
String oof(); | ||
|
||
Log log(); | ||
|
||
// nested mapping | ||
interface Log { | ||
boolean rotate(); | ||
} | ||
} | ||
} |