The previous commit for issue SPR-11144 revealed a bug in
ServletTestExecutionListener (STEL). Specifically, STEL acted on the
fact that the ApplicationContext for a given TestContext was an
instance of WebApplicationContext. This behavior could potentially
break test code from previous releases of the Spring Framework that
relied on a custom setup of the RequestAttributes in the
RequestContextHolder with a custom WebApplicationContext ContextLoader.
This commit addresses this issue by ensuring that STEL only comes into
play if the test class is annotated with @WebAppConfiguration (for
prepareTestInstance() and beforeTestMethod()) or if the TestContext
attribute named RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE is set to
Boolean.TRUE (for afterTestMethod()).
Issue: SPR-11144
@ -76,7 +79,9 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -76,7 +79,9 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@ -88,7 +93,9 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -88,7 +93,9 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@ -101,7 +108,11 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -101,7 +108,11 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@ -112,22 +123,27 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -112,22 +123,27 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
logger.debug(String.format("Resetting RequestContextHolder for test context %s.",testContext));
"The WebApplicationContext for test context %s must be configured with a MockServletContext.",
testContext));
}
if(logger.isDebugEnabled()){
logger.debug(String.format(
@ -135,7 +151,6 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -135,7 +151,6 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@ -153,6 +168,5 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -153,6 +168,5 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener