-
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
SPR-15819 - URI variables with MockRestRequestMatchers requestTo #1486
SPR-15819 - URI variables with MockRestRequestMatchers requestTo #1486
Conversation
@drumonii please create a Jira issue for this change. |
c022920
to
5166126
Compare
Assert.notNull(expectedUri, "'uri' must not be null"); | ||
return request -> assertEquals("Request URI", expectedUri, request.getURI().toString()); | ||
String uri = UriComponentsBuilder.fromUriString(expectedUri).buildAndExpand(uriVars).encode().toString(); |
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.
This will cause expectedUri to always be encoded which wasn't the case until now.
One option would be to do this only if uriVars are actually provided but then the method behaves inconsistently with regards to encoding based on whether uriVars are provided or not.
Another option would be to have separate methods -- e.g. requestTo
for exact string match, requestToUriTemplate
to expand + encode, and possibly also requestToUri(String expectedUri, Function<UriBuilder, URI> uriFunction)
for full control (as we've done on the new WebClient
).
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.
In regards to the encoded expectedUri, I looked at the recent changes to use URI vars in MockMvcResultMatchers and modeled this chage off that.
Which option do you prefer? The first option is certainly more convenient. The separate method option also works well because if you are going back to refactor requestTo
to use URI vars instead of concating, then you can change the method name while at it.
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.
Yes I see now that a similar change was made not long ago. The ticket also shows a comment about a subsequent regression https://jira.spring.io/browse/SPR-14790 .. :)
The first option isn't really an option because of the inconsistency I pointed out. I shouldn't have called it an option in the first place. Let's go for these two for now:
requestTo(String)
requestToUriTemplate(String, Object...)
The requestTouri(String, Function<UriBuilder, URI>)
can always be added later.
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.
Sounds good! Wasn't aware of the regression but I'll work on these changes later.
Issue: SPR-15819
5166126
to
fed42af
Compare
This is merged, thanks, |
Adds ability to use URI variables with
MockRestRequestMatchers
'srequestTo