Add framework to allow test-specific assertions on HTTP response. #154
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.
Motivation:
Individual tests may have certain expectations on how IDS responds to
HTTP requests.
Some interactions supported by
TestingClient
exercise IDS requeststhat return content; for example,
getData
. For these interactions,TestingClient
returns the content from IDS and not the HTTP response.This makes it impossible for a test to assert that, for these
interactions, the HTTP response from IDS matches the test's
expectations.
Modification:
Update
TestingClient
to allow the test to include one or moreassertions on the HTTP response. The support following the builder
pattern.
The assertions are provided by the test as Consumer objects that accept
an HttpResponse object, with lambdas providing an easy to build such
objects. Some static methods are included that provide common
assertions, to keep code readable and DRY.
The Apache client is customised to include a response interceptor,
through which the assertions are made.
The existing code that checks the combined
Content-Length
(if present)and
Transfer-Encoding
headers (if present) is valid is refactored totake advantage of this framework. This check now applies uniformly to
all HTTP responses from IDS.
Some other, existing tests are updated to take advantage of the new
framework.
Further refactoring is possible; for example, to make the check on the
response's status code more explicit. Such a refactoring would reduce
the complexity of the
TestingClient
interaction methods by reducingthe parameter count.
Result:
It is now possible to write tests that make test-specific assertions on
the HTTP response from IDS for interactions where IDS returns content.