Skip to content
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

Conversation

drumonii
Copy link
Contributor

Adds ability to use URI variables with MockRestRequestMatchers's requestTo

@snicoll
Copy link
Member

snicoll commented Jul 25, 2017

@drumonii please create a Jira issue for this change.

@drumonii
Copy link
Contributor Author

@snicoll Created! SPR-15819

I'll update the test to include the issue number as a comment later

@snicoll snicoll changed the title URI variables with MockRestRequestMatchers requestTo SPR-15819 - URI variables with MockRestRequestMatchers requestTo Jul 25, 2017
@drumonii drumonii force-pushed the MockRestRequestMatchers-requestTo-UriVars branch from c022920 to 5166126 Compare July 25, 2017 22:48
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();
Copy link
Contributor

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).

Copy link
Contributor Author

@drumonii drumonii Jul 27, 2017

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@drumonii drumonii force-pushed the MockRestRequestMatchers-requestTo-UriVars branch from 5166126 to fed42af Compare July 29, 2017 00:43
@rstoyanchev
Copy link
Contributor

This is merged, thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants