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:
Sam Brannen
2019-07-25 23:15:33 +02:00
parent 2e476ca14f
commit 136af0b164
36 changed files with 687 additions and 854 deletions

View File

@@ -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" />
-->

View File

@@ -1 +1,3 @@
first = 1111
alpha = beta
first = 1111
second = 1111

View File

@@ -1 +1 @@
key = local value
key1 = local file

View File

@@ -1 +1 @@
meta = a value from file in the meta-annotation
key2 = meta file

View File

@@ -1 +1,2 @@
second = 2222
alpha = omega
second = 2222