Overhaul repeatable @TestPropertySource support
Prior to this commit, if multiple, directly present `@TestPropertySource` annotations declared the same property, the precedence ordering was top-down instead of bottom-up, in contrast to the semantics for class hierarchies. In other words, a subsequent `@TestPropertySource` annotation could not override a property in a previous `@TestPropertySource` annotation. This commit overhauls the internals of `TestPropertySourceUtils` in order to provide proper support for property overrides within local, directly present `@TestPropertySource` declarations. Specifically, the `locations` and `properties` attributes from all `@TestPropertySource` declarations that are directly present or meta-present on a given class are now merged into a single instance of `TestPropertySourceAttributes` internally, with assertions in place to ensure that such "same level" `@TestPropertySource` declarations do not configure different values for the `inheritLocations` and `inheritProperties` flags. Effectively, all "same level" `@TestPropertySource` declarations are treated internally as if there were only one such annotation declared by the user. See gh-23320
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
<Logger name="org.springframework.test.context.support.DelegatingSmartContextLoader" level="info" />
|
||||
<Logger name="org.springframework.test.context.support.AbstractGenericContextLoader" level="info" />
|
||||
<Logger name="org.springframework.test.context.support.AnnotationConfigContextLoader" level="info" />
|
||||
<Logger name="org.springframework.test.context.support.TestPropertySourceUtils" level="trace" />
|
||||
<Logger name="org.springframework.beans" level="warn" />
|
||||
<Logger name="org.springframework.test.web.servlet.result" level="debug" />
|
||||
-->
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
default.value = default file
|
||||
@@ -1 +0,0 @@
|
||||
default.value = a value from default properties file
|
||||
@@ -1 +1,3 @@
|
||||
first = 1111
|
||||
alpha = beta
|
||||
first = 1111
|
||||
second = 1111
|
||||
|
||||
@@ -1 +1 @@
|
||||
key = local value
|
||||
key1 = local file
|
||||
|
||||
@@ -1 +1 @@
|
||||
meta = a value from file in the meta-annotation
|
||||
key2 = meta file
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
second = 2222
|
||||
alpha = omega
|
||||
second = 2222
|
||||
|
||||
Reference in New Issue
Block a user