-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Enhance MockMvcWebTestClient to allow applying RequestPostProcessors #30233
Conversation
@justin-tay Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@justin-tay Thank you for signing the Contributor License Agreement! |
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.
@justin-tay thanks for experimenting with this.
WebTestClient
is a two-phase builder, first to build the server and then the test client. This creates a single chained flow, but once you've moved to the second phase, there is no way to return to the server phase. mutate()
only drops you in the builder for the second phase. The same is true for MockMvcWebTestClient
which builds a MockMvc
server in phase 1 and transitions to the test client builder.
So for MockMvcWebMvcTest
client to introduce a mutate()
with a Builder
that extends the WebTestClient.Builder
is essentially adding server builder methods as a subclass of client builder methods. I don't think this is in the right direction, and it would also be difficult to accommodate the same for all the other WebTestClient
server builder choices with a single mutate()
.
The other mutate
with a WebTestClientConfigurer
is what provides an option to modify the server. Here we pass the ClientHttpConnector
and that could be one possible direction, but we would need to enhance MockMvcHttpConnector
to allow mutation, e.g. to add RequestPostProcessor
s. From a quick look there is also a WiretapConnector
wrapper around the actual ClientHttpConnector
in use that we may have to unwrap when applying a WebTestClientConfigurer
.
Would you like to redo your pull request? If not I can also make some changes along those lines.
transitioned to building the test client, there is no return to the built, mutate()
can change the test client. longer be changed
9a213d5
to
dca11d5
Compare
I see your point about the design. I tried to pick this up again but I don't really know how to do this without making breaking changes, plus I think my initial design was pretty off track. I think it might be best for you to make the changes instead. |
Thanks @justin-tay for inserting some momentum into this. I've created #31298. |
Potentially fixes related issues like spring-projects/spring-security#9257 and spring-projects/spring-security#11334
This PR is unpolished and is just to illustrate the idea of allowing
mutateWith
on MockMvcRequestPostProcessors
as I'm not even sure if this design approach would be acceptable.The basic design idea is to have the
MockMvcWebTestClient
interface extendWebTestClient
with some MockMvc specific methods.