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

Improve HeaderAssertions for specific tests [SPR-16285] #20832

Closed
spring-issuemaster opened this issue Dec 11, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Dec 11, 2017

Brian Clozel opened SPR-16285 and commented

While writing test assertions with WebTestClient, I've found a few problematic cases with the current API.

Testing media types

The existing contentType assertion tests for MediaType equality between the one provided as an argument and the one returned by the endpoint. This is rather strict (which is good for tests) but can be surprising at times when you're asserting for "application/json" and getting an error back because the response header actually was "application/json;charset=UTF-8"

Testing for a missing header

I'd like to test that a response header is not present; with the current API, all methods test for the presence of a given header name. Adding a new method for that purpose could be useful.

Pinging rstoyanchev on this since we discussed that previously.


Affects: 5.0.2

Issue Links:

  • #20925 WebTestClient - expecting lack of header ("is duplicated by")

Referenced from: commits 6e587d5

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 11, 2017

Rossen Stoyanchev commented

For the Content-Type let's match to what we have in ContentResultMatchers for MockMvc, i.e. contentTypeIsCompatibleWith and we could also add String-based alternatives for both.

For the header not present, perhaps something like valueDoesNotExist?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 11, 2017

Brian Clozel commented

Your idea for Content-Type sounds good to me.
For the header not present case, in MockMvc we have header().doesNotExist(HttpHeaders.MY_HEADER));

To me, valueDoesNotExist sounds like the header can be there but that no value is associated with it - while doesNotExist sounds like the header is not present at all. On the top of my head, doesNotExist looks like the most useful?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 11, 2017

Rossen Stoyanchev commented

(y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.