类 ServletTestExecutionListener
- 所有已实现的接口:
cn.taketoday.core.Ordered,TestExecutionListener
TestExecutionListener which provides mock Servlet API support to
WebServletApplicationContext loaded by the Infra
TestContext Framework.
Specifically, ServletTestExecutionListener sets up thread-local
state via Infra Web's RequestContextHolder during test instance preparation and before each test method and creates a MockHttpServletRequest, MockHttpServletResponse, and
RequestContext based on the MockServletContext present in
the WebApplicationContext. This listener also ensures that the
MockHttpServletResponse and ServletWebRequest can be injected
into the test instance, and once the test is complete this listener cleans up thread-local state.
Note that ServletTestExecutionListener is enabled by default but
generally takes no action if the test
class is not annotated with @WebAppConfiguration.
See the javadocs for individual methods in this class for details.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Phillip Webb
-
字段概要
字段修饰符和类型字段说明static final StringAttribute name for aTestContextattribute which indicates that theServletTestExecutionListenershould be activated.static final StringAttribute name for a request attribute which indicates that theMockHttpServletRequeststored in theRequestContextin Infra Web'sRequestContextHolderwas created by the TestContext framework.private static final cn.taketoday.logging.Loggerstatic final StringAttribute name for aTestContextattribute which indicates thatServletTestExecutionListenerhas already populated Infra Web'sRequestContextHolder.static final StringAttribute name for aTestContextattribute which indicates whether or not theServletTestExecutionListenershould reset Infra Web'sRequestContextHolderinafterTestMethod(TestContext).从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidafterTestMethod(TestContext testContext) If theRESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTEin the suppliedTestContexthas a value ofBoolean.TRUE, this method will (1) clean up thread-local state after each test method by resetting Infra Web'sRequestContextHolderand (2) ensure that new mocks are injected into the test instance for subsequent tests by setting theDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTEin the test context totrue.private booleanalreadyPopulatedRequestContextHolder(TestContext testContext) voidbeforeTestMethod(TestContext testContext) Sets up thread-local state before each test method via Infra Web'sRequestContextHolder, but only if the test class is annotated with@WebAppConfiguration.final intgetOrder()Returns1000.private booleanisActivated(TestContext testContext) voidprepareTestInstance(TestContext testContext) Sets up thread-local state during the test instance preparation callback phase via Infra Web'sRequestContextHolder, but only if the test class is annotated with@WebAppConfiguration.private voidsetUpRequestContextIfNecessary(TestContext testContext) 从类继承的方法 cn.taketoday.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, beforeTestClass, beforeTestExecution
-
字段详细资料
-
RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTE
Attribute name for aTestContextattribute which indicates whether or not theServletTestExecutionListenershould reset Infra Web'sRequestContextHolderinafterTestMethod(TestContext).Permissible values include
Boolean.TRUEandBoolean.FALSE. -
POPULATED_REQUEST_CONTEXT_HOLDER_ATTRIBUTE
Attribute name for aTestContextattribute which indicates thatServletTestExecutionListenerhas already populated Infra Web'sRequestContextHolder.Permissible values include
Boolean.TRUEandBoolean.FALSE. -
CREATED_BY_THE_TESTCONTEXT_FRAMEWORK
Attribute name for a request attribute which indicates that theMockHttpServletRequeststored in theRequestContextin Infra Web'sRequestContextHolderwas created by the TestContext framework.Permissible values include
Boolean.TRUEandBoolean.FALSE. -
ACTIVATE_LISTENER
Attribute name for aTestContextattribute which indicates that theServletTestExecutionListenershould be activated. When not set totrue, activation occurs when the test class is annotated with@WebAppConfiguration.Permissible values include
Boolean.TRUEandBoolean.FALSE. -
logger
private static final cn.taketoday.logging.Logger logger
-
-
构造器详细资料
-
ServletTestExecutionListener
public ServletTestExecutionListener()
-
-
方法详细资料
-
getOrder
public final int getOrder()Returns1000.- 指定者:
getOrder在接口中cn.taketoday.core.Ordered- 覆盖:
getOrder在类中AbstractTestExecutionListener
-
prepareTestInstance
Sets up thread-local state during the test instance preparation callback phase via Infra Web'sRequestContextHolder, but only if the test class is annotated with@WebAppConfiguration.- 指定者:
prepareTestInstance在接口中TestExecutionListener- 覆盖:
prepareTestInstance在类中AbstractTestExecutionListener- 参数:
testContext- the test context for the test; nevernull- 抛出:
Exception- allows any exception to propagate- 另请参阅:
-
beforeTestMethod
Sets up thread-local state before each test method via Infra Web'sRequestContextHolder, but only if the test class is annotated with@WebAppConfiguration.- 指定者:
beforeTestMethod在接口中TestExecutionListener- 覆盖:
beforeTestMethod在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method will be executed; nevernull- 抛出:
Exception- allows any exception to propagate- 另请参阅:
-
afterTestMethod
If theRESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTEin the suppliedTestContexthas a value ofBoolean.TRUE, this method will (1) clean up thread-local state after each test method by resetting Infra Web'sRequestContextHolderand (2) ensure that new mocks are injected into the test instance for subsequent tests by setting theDependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTEin the test context totrue.The
RESET_REQUEST_CONTEXT_HOLDER_ATTRIBUTEandPOPULATED_REQUEST_CONTEXT_HOLDER_ATTRIBUTEwill be subsequently removed from the test context, regardless of their values.- 指定者:
afterTestMethod在接口中TestExecutionListener- 覆盖:
afterTestMethod在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method was executed; nevernull- 抛出:
Exception- allows any exception to propagate- 另请参阅:
-
isActivated
-
alreadyPopulatedRequestContextHolder
-
setUpRequestContextIfNecessary
-