-
Couldn't load subscription status.
- Fork 38.8k
Closed
Labels
in: testIssues in the test moduleIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply
Description
Gena Makhomed opened SPR-11760 and commented
The full source code for HttpStatusOverrideFilter is available in the attachment.
In production env., all works fine, but when I use JUnit + MockMvc, the HTTP Status Code overridden by my filter gets ignored.
Test code fragment:
@Test
public void badUri() throws Exception {
mockMvc.perform(post("/unknown-request-uri")
.andExpect(status().is(equalTo(230)));
}
Controller code fragment:
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set(X_HTTP_STATUS_OVERRIDE, "230");
return new ResponseEntity<>("none", httpHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
In the production env., the filter works fine, and the HTTP status code is 230. With JUnit + MockMvc, the HTTP status code is 500, and the assertion fails.
Looks like this is bug in MockMvc.
Unit-test log fragment:
o.s.test.web.servlet.TestDispatcherServlet | Successfully completed request
c.p.i.util.filter.HttpStatusOverrideFilter | Status overridden '500' => '230'
.t.c.s.DirtiesContextTestExecutionListener | After test method: context
[DefaultTestContext@1895852 testClass = GateControllerTest, testInstance = com.pb.ivrcgate.controller.GateControllerTest@59e71, testMethod =
badUri@GateControllerTest, testException = java.lang.AssertionError: Response status
Expected: <230>
but: was <500>, mergedContextConfiguration = [WebMergedContextConfiguration@f7e9dd testClass = GateControllerTest, locations =
'{classpath:/spring/context.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{dev}', resourceBasePath =
'src/main/webapp', contextLoader = 'org.springframework.test.context.web.WebDelegatingSmartContextLoader', parent = [null]]], class dirties
context [false], class mode [null], method dirties context [false].
Affects: 4.0.4
Attachments:
- HttpStatusOverrideFilter.java (3.39 kB)
- HttpStatusOverrideFilter.java (4.12 kB)
Issue Links:
- Provide better intercepting model for controllers returning @ResponseBody [SPR-10859] #15486 Provide better intercepting model for controllers returning
@ResponseBody - MockHttpServletRequest should not require setContent for non-null getInputStream() result [SPR-11764] #16386 MockHttpServletRequest should not require setContent for non-null getInputStream() result
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applyA suggestion or change that we don't feel we should currently apply