Improve the fluency of the ResponseCreator API #27280
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added utility methods to DefaultResponseCreator
This enables the ability to fluently add single headers like you can
already with the mock request specification APIs by chaining
.header(name, value)
repeatedly. This reduces code clutter withintest cases.
Added the ability to add cookies as this simplifies tests that work
with sessions.
Added the ability to override the character encoding used for setting
a string body on a response, as this is useful when working in
environments that do not automatically assume UTF-8, such as
integrating with legacy applications from a new Spring one.
Added unit tests for DefaultResponseCreator
These were already partially tested by the MockRestResponseCreator, but some
existing calls prior to this PR were missing, and this was also an opportunity
for me to directly test the changes I added.
Added common response statuses to MockRestResponseCreators
It appears that a couple of the more commonly used HTTP status codes
were missed out from the default methods in MockRestResponseCreators.
The methods included are common enough that most test packs will probably
have at least one case that uses one of these calls, so it enables
keeping the fluent API tidy.
I added a couple of additional edge cases for common response
statuses that will occur when working in cloud environments, such as
AWS, CloudFlare, or using gateways such as Kong, where resillient
applications should be able to respond to ratelimits, gateway errors,
and gateway timeouts (which may occur if a remote service is down).
Added test cases for any changes made.
These changes allow for cases to be written like so:
which should be more fluent and easy to read than what would be needed on the existing API: