I have an interface MyConfig that is using @ConfigMapping(prefix = "myconfig") and getting info from src/main/resources/application.properties.
I have an unit test for a component where I need to pass the MyConfig on its constructor. I prefer not mocking the config interface since I have many values (properties) that needs to be used.
So, I have tried to do what I found in the smallrye-config docs:
final SmallRyeConfig sconfig =
ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
final MyConfig config = sconfig.getConfigMapping(MyConfig.class);
But I'm getting a error:
java.util.NoSuchElementException: SRCFG00027: Could not find a mapping for com.natixis.matrisk.api.management.releases.config.ReleaseConfig
at io.smallrye.config.SmallRyeConfig.getConfigMapping(SmallRyeConfig.java:683)
at io.smallrye.config.SmallRyeConfig.getConfigMapping(SmallRyeConfig.java:673)
Please, what am I missing ?
I have an interface MyConfig that is using @ConfigMapping(prefix = "myconfig") and getting info from src/main/resources/application.properties.
I have an unit test for a component where I need to pass the MyConfig on its constructor. I prefer not mocking the config interface since I have many values (properties) that needs to be used.
So, I have tried to do what I found in the smallrye-config docs:
final SmallRyeConfig sconfig =
ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
final MyConfig config = sconfig.getConfigMapping(MyConfig.class);
But I'm getting a error:
java.util.NoSuchElementException: SRCFG00027: Could not find a mapping for com.natixis.matrisk.api.management.releases.config.ReleaseConfig
at io.smallrye.config.SmallRyeConfig.getConfigMapping(SmallRyeConfig.java:683)
at io.smallrye.config.SmallRyeConfig.getConfigMapping(SmallRyeConfig.java:673)
Please, what am I missing ?
Share Improve this question asked Mar 6 at 11:58 CristianoCristiano 1,8351 gold badge18 silver badges27 bronze badges 1- 1 Quarkus has support for component testing with (auto) mocking support, try this instead: quarkus.io/guides/testing-components – Serkan Commented Mar 10 at 17:31
1 Answer
Reset to default 2SmallRye Config has no auto discovery mechanism for mappings, when running standalone. You need to register the required mappings for the test manually. You can use a SmallRyeConfigBuilderCustomizer
and register the mapping in the build directly via SmallRyeConfigBuilder#withMapping
. Please check:
https://smallrye.io/smallrye-config/3.11.4/config/mappings/#registration
https://smallrye.io/smallrye-config/3.11.4/config/customizer/