I have the following property list in my application.yml
:
foo:
bar:
-
id: baz
item: value
// ...
Then I want to overwrite item
value in tests using @DynamicPropertySource
:
@DynamicPropertySource
@JvmStatic
@Suppress("unused")
fun setupProperties(registry: DynamicPropertyRegistry) {
registry.add("foo.bar[0].item") { "new value" }
}
But during the tests, I got all other properties set to nulls, with one element in bar
array.
I guess that I'm not referring correctly to map entry in yaml
file.
I wonder how I can do that?
It turns out that Spring Boot documentation states clearly:
When lists are configured in more than one place, overriding works by replacing the entire list.
This effectively means that I need to provide whole list item:
@DynamicPropertySource
@JvmStatic
@Suppress("unused")
fun setupProperties(registry: DynamicPropertyRegistry) {
registry.add("foo.bar[0].id") { "new baz" }
registry.add("foo.bar[0].item") { "new value" }
// ...
}