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

MockServletRequest and MockServletResponse Ignore Content-Type [SPR-8750] #13392

Closed
spring-projects-issues opened this issue Oct 7, 2011 · 1 comment
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Neil Chaudhuri opened SPR-8750 and commented

MockServletRequest and MockServletResponse need to support Content-Type so that tests that depend on that header value can yield the appropriate results. I do not know if other headers are ignored as well.


Affects: 3.0.6

Reference URL: http://forum.springsource.org/showthread.php?115547-Testing-HttpRequestHandlingMessagingGateway-with-MockHttpServletRequest-PUT

Referenced from: commits 63e235f, 7918810

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 17, 2011

Rossen Stoyanchev commented

Note that 'Content-Type' may also include a character encoding, which means the contentType, the characterEncoding fields, and the 'Content-Type' header need to be kept in sync regardless of which one is updated and in what order.

My initial approach did just that. However, I've reconsidered since it would break existing tests, which rely on contentType and characterEncoding being equal to exactly what they were set to.

Consider:

response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");

The contentType field and the 'Content-Type' header should now be "text/plain;charset=UTF-8". Existing tests will break because they expect contentType to be "text/plain".

To avoid breaking existing tests, contentType and characterEncoding continue to be equal to exactly what they were set to while the 'Content-Type' header is set correctly. Or if the 'Content-Type' header is set, the contentType and the characterEncoding fields will be set accordingly. I think this will provide the desired behavior without breaking existing tests.

Here is a summary of the main scenario:

Scenario 1:

setContentType("text/plain")
setCharacterEncoding("UTF-8")


contentType="text/plain"
characterEncoding="UTF-8"
headers['Content-Type']="text/plain;charset=UTF-8"

Scenario 2:

setContentType("text/plain;charset=UTF-8")


contentType="text/plain;charset=UTF-8"
characterEncoding="UTF-8"
headers['Content-Type']="text/plain;charset=UTF-8"

Scenario 3:

addHeader("Content-Type", "text/plain;charset=UTF-8");


contentType="text/plain;charset=UTF-8"
characterEncoding="UTF-8"
headers['Content-Type']="text/plain;charset=UTF-8"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants