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

MockHttpServletRequestBuilder does not allow invalid content type for testing [SPR-17643] #22172

Closed
spring-projects-issues opened this issue Jan 7, 2019 · 3 comments
Assignees
Labels
in: web status: superseded type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 7, 2019

dmitry87 opened SPR-17643 and commented

 

Invalid mime type "yaml": does not contain '/'
org.springframework.http.InvalidMediaTypeException: Invalid mime type "yaml": does not contain '/'
 at org.springframework.http.MediaType.parseMediaType(MediaType.java:512)
 at org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.contentType(MockHttpServletRequestBuilder.java:277)

One of the app in stack sends invalid content type. Currently it is impossible to cover this in Unit test because MockHttpServletRequestBuilder uses MediaType.parse(contentType: String).toString() to get the value and it fails to get to ExceptionHandler

I propose that MockHttpServletRequestBuilder could accept any string for contentType. In this case when we send payload with invalid(unparsable) contentType to our controller we will handle InvalidMediaTypeException with our exception handler in Unit tests

 


Affects: 5.1.3

Referenced from: pull request #2077

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 7, 2019

Juergen Hoeller commented

I suppose you can set the Content-Type header directly for the time being? Otherwise you could also modify the content type on the MockHttpServletRequest instance itself where no such parsing is in place.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 8, 2019

@spring-projects-issues spring-projects-issues added type: enhancement in: web labels Jan 11, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 13, 2019
@rstoyanchev rstoyanchev removed this from the General Backlog milestone Dec 13, 2019
@rstoyanchev
Copy link
Contributor

@rstoyanchev rstoyanchev commented Dec 13, 2019

This is now superseded by #2079.

@rstoyanchev rstoyanchev added the status: superseded label Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web status: superseded type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants