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

Add framework to allow test-specific assertions on HTTP response. #154

Conversation

paulmillar
Copy link
Contributor

@paulmillar paulmillar commented Feb 3, 2024

Motivation:

Individual tests may have certain expectations on how IDS responds to
HTTP requests.

Some interactions supported by TestingClient exercise IDS requests
that 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 more
assertions 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 to
take 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 reducing
the 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.

@paulmillar paulmillar marked this pull request as draft February 3, 2024 17:06
@paulmillar paulmillar force-pushed the development/add-http-response-tests branch from 3105926 to ddc81e6 Compare February 4, 2024 22:15
@paulmillar paulmillar marked this pull request as ready for review February 4, 2024 22:32
@paulmillar paulmillar force-pushed the development/add-http-response-tests branch 3 times, most recently from a19b030 to 75561ab Compare February 5, 2024 10:03
@paulmillar paulmillar force-pushed the development/add-http-response-tests branch 2 times, most recently from d6f780a to ce5da1e Compare February 6, 2024 12:47
Motivation:

Individual tests may have certain expectations on how IDS responds to
HTTP requests.

Some interactions supported by `TestingClient` exercise IDS requests
that 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 more
assertions 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 to
take 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 reducing
the 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.

Signed-off-by: Paul Millar <paul.millar@desy.de>
@paulmillar paulmillar force-pushed the development/add-http-response-tests branch from ce5da1e to cfce753 Compare February 6, 2024 12:47
@paulmillar
Copy link
Contributor Author

I'm closing this pull request as it isn't clear what is the best strategy for processing the proposed changes. This is something that could be discussed in issue #155.

@paulmillar paulmillar closed this Feb 7, 2024
@paulmillar paulmillar deleted the development/add-http-response-tests branch February 12, 2024 22:09
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.

1 participant