spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.38k stars 38.04k forks source link

support HTTP status error pages on MockMvc [SPR-13966] #18538

Open spring-projects-issues opened 8 years ago

spring-projects-issues commented 8 years ago

Christopher Smith opened SPR-13966 and commented

MockMvc does not run an actual servlet container but implements part of the stack for testing purposes. Currently, MockMvc does not support content in error responses; for example, a 403 or 404 status will result in an empty body.

With the new HtmlUnit driver support, it's very simple to write most functional tests in something like Spock+Geb, but tests that expect an error (e.g., "Bob can't view Alice's document") require dropping back into the MockMvc DSL because the driver only exposes the view content and not the status code.

I would like to be able to configure the MockMvc to serve HTML pages as error responses, similar to Boot's ConfigurableEmbeddedServletContainer#addErrorPages(ErrorPage[]) so that I can use ordinary Selenium methods of identifying when I've encountered an error.


Affects: 4.2.4

spring-projects-issues commented 8 years ago

Rossen Stoyanchev commented

So is this a limitation of the HtmlUnit driver or our support for it? In other words could we expose the status code?

spring-projects-issues commented 8 years ago

Rob Winch commented

I think Christopher Smith is asking for MockMvc to be able to process HttpServletResponse.sendError. Since it is unable to, that means the error handling that leverages HttpServletResponse.sendError cannot be tested with the HtmlUnit support.