'ConfigurationProperites not applied in SpringBootTest?
We have the following configuration properties class (reduced the minimum)
@ConstructorBinding
@ConfigurationProperties(prefix = "prefix")
data class MyConfiguraion(
val mapping: MutableMap<String, Map<String, Int>>
)
The configuration in the application yaml looks like this:
prefix.mapping:
value1:
a: 1
b: 2
using the application.yml, the map is passed correctly, though if I want to test it with SpringBootTest, the map is not passed, instead an empty map is passed to the constructor:
@SpringBootTest(
classes = [MyConfiguraion::class, ],
properties = [
"prefix.mapping.value1.a=1",
"prefix.mapping.value1.b=2",
]
)
internal class CapabilityMappingTest {
@Autowired
lateinit var config: MyConfiguraiton
@Test
fun `mapping was correctly appiled`() {
expectThat(config)
.get { mapping }.and {
get("value1")
.isNotNull()
.and {
get("a") isEqualTo 1
get("b") isEqualTo 2
}
}
}
(Example is reduced to a minimum to show the issue. Without the context, it does not look useful)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
