-
Notifications
You must be signed in to change notification settings - Fork 38k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support @TestPropertySource as a repeatable annotation #23320
Support @TestPropertySource as a repeatable annotation #23320
Conversation
the sync of fork
sync with spring source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the PR looks pretty good. I've requested a few minor changes.
Please update the copyright headers where appropriate as well.
spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java
Show resolved
Hide resolved
spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java
Show resolved
Hide resolved
spring-test/src/main/java/org/springframework/test/context/TestPropertySources.java
Show resolved
Hide resolved
@sbrannen thanks for your feedback! I made the requested changes, |
Thanks! Unless I overlooked something, it looks like we need some tests that demonstrate/verify the override behavior when multiple Could you please introduce such tests? |
of course, I added a few test cases to demonstrate how to work overriding of |
Thanks! I'll try to review them and finish up this PR in the coming days. |
@antkorwin, could it be that you copied the Javadoc for It sounds very familiar. 😉 |
I think this is due to the fact that I often have one opened window with source files from the Junit5, so to speak, for inspiration 😃 need to say that this is a real example of a well-designed and well-documented system. |
Understood. I wrote that Javadoc for JUnit 5. That's why it sounded so familiar to me. Normally we shouldn't copy documentation verbatim from other projects, but in this case I think it's OK.
😊 |
Current work on this PR can be viewed in the following feature branch. I had to completely rewrite Another open issue is the handling of the Feedback is welcome. |
I in fact went that route in the latest commit on the aforementioned feature branch.
I think the semantics, and therefore the implementation, are pretty solid now, but feedback is still welcome before I document the changes and push to @philwebb, I'd also appreciate feedback from you regarding use of the |
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 spring-projectsgh-23320
I read the documentation about
if we check this on the same level of |
@antkorwin, Thanks again for the PR and for reviewing the subsequent changes!
Yeah, the ordering within the That is actually in line with the existing documentation for "Whether or not test property source locations from superclasses should be inherited."
Exactly. That's what the code does now: it throws an exception if there are conflicting values for those flags for all annotations present in the same aggregate index (i.e., class hierarchy level).
We have to be careful here when using the term "level", because there are in fact two types of levels: aggregate index and meta distance. The current solution takes both types of levels into account. For a given aggregate index, all directly present and meta-present annotations at that level in the class hierarchy are sorted according to their meta distance, in reverse order. That effectively allows directly present annotations to override individual properties declared in directly present and meta-present annotations. But... that does not mean that a directly present annotation can use the semantics of Perhaps I should explicitly document that last part in the Javadoc. 😉 |
Addressed in 1954861 |
This commit introduces tests which verify that properties configured via @TestPropertySource used as a meta-annotation override those configured via @TestPropertySource used as a meta-meta-annotation. See gh-23320
@sbrannen It all looks sensible to me. If you want to you could remove the |
Fixed #21986 and https://jira.spring.io/browse/SPR-17454?redirect=false
I often make composite meta-annotations in my libraries and sometimes I need to define some properties in tests by the using of meta-annotation, it's difficult without the full support of inheritance and repeatable of the TestPropertySource annotation.
I tried to implement it in this PR, hope this is the right way. If not, please suggest me how to make it better.