类 AbstractTestContextBootstrapper
- java.lang.Object
- org.springframework.test.context.support.AbstractTestContextBootstrapper
- 所有已实现的接口:
TestContextBootstrapper
public abstract class AbstractTestContextBootstrapper extends Object implements TestContextBootstrapper
Abstract implementation of theTestContextBootstrapperinterface which provides most of the behavior required by a bootstrapper.Concrete subclasses typically will only need to provide implementations for the following methods:
getDefaultContextLoaderClass(java.lang.Class<?>)processMergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration)
To plug in custom
ContextCachesupport, overridegetCacheAwareContextLoaderDelegate().- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen, Juergen Hoeller, Phillip Webb
构造器概要
构造器 构造器 说明 AbstractTestContextBootstrapper()
方法概要
构造器详细资料
AbstractTestContextBootstrapper
public AbstractTestContextBootstrapper()
方法详细资料
setBootstrapContext
public void setBootstrapContext(BootstrapContext bootstrapContext)
从接口复制的说明:TestContextBootstrapperSet theBootstrapContextto be used by this bootstrapper.
getBootstrapContext
public BootstrapContext getBootstrapContext()
从接口复制的说明:TestContextBootstrapperGet theBootstrapContextassociated with this bootstrapper.
buildTestContext
public TestContext buildTestContext()
Build a newDefaultTestContextusing the test class in theBootstrapContextassociated with this bootstrapper and by delegating tobuildMergedContextConfiguration()andgetCacheAwareContextLoaderDelegate().Concrete subclasses may choose to override this method to return a custom
TestContextimplementation.- 指定者:
buildTestContext在接口中TestContextBootstrapper- 返回:
- a new
TestContext, nevernull - 从以下版本开始:
- 4.2
- 另请参阅:
TestContextBootstrapper.buildMergedContextConfiguration()
getTestExecutionListeners
public final List<TestExecutionListener> getTestExecutionListeners()
从接口复制的说明:TestContextBootstrapperGet a list of newly instantiatedTestExecutionListenersfor the test class in theBootstrapContextassociated with this bootstrapper.If
@TestExecutionListenersis not present on the test class in theBootstrapContext, default listeners should be returned. Furthermore, default listeners must be sorted usingAnnotationAwareOrderComparator.Concrete implementations are free to determine what comprises the set of default listeners. However, by default, the Spring TestContext Framework will use the
SpringFactoriesLoadermechanism to look up allTestExecutionListenerclass names configured in allMETA-INF/spring.factoriesfiles on the classpath.The
inheritListenersflag of@TestExecutionListenersmust be taken into consideration. Specifically, if theinheritListenersflag is set totrue, listeners declared for a given test class must be appended to the end of the list of listeners declared in superclasses.- 指定者:
getTestExecutionListeners在接口中TestContextBootstrapper- 返回:
- a list of
TestExecutionListenerinstances
getDefaultTestExecutionListenerClasses
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses()
Get the defaultTestExecutionListenerclasses for this bootstrapper.This method is invoked by
getTestExecutionListeners()and delegates togetDefaultTestExecutionListenerClassNames()to retrieve the class names.If a particular class cannot be loaded, a
DEBUGmessage will be logged, but the associated exception will not be rethrown.
getDefaultTestExecutionListenerClassNames
protected List<String> getDefaultTestExecutionListenerClassNames()
Get the names of the defaultTestExecutionListenerclasses for this bootstrapper.The default implementation looks up all
org.springframework.test.context.TestExecutionListenerentries configured in allMETA-INF/spring.factoriesfiles on the classpath.This method is invoked by
getDefaultTestExecutionListenerClasses().- 返回:
- an unmodifiable list of names of default
TestExecutionListenerclasses - 另请参阅:
SpringFactoriesLoader.loadFactoryNames(java.lang.Class<?>, java.lang.ClassLoader)
buildMergedContextConfiguration
public final MergedContextConfiguration buildMergedContextConfiguration()
Build the merged context configuration for the test class in theBootstrapContextassociated with this bootstrapper.Implementations must take the following into account when building the merged configuration:
- Context hierarchies declared via
@ContextHierarchyand@ContextConfiguration - Active bean definition profiles declared via
@ActiveProfiles - Context initializers declared via
ContextConfiguration.initializers() - Test property sources declared via
@TestPropertySource
Consult the Javadoc for the aforementioned annotations for details on the required semantics.
Note that the implementation of
TestContextBootstrapper.buildTestContext()should typically delegate to this method when constructing theTestContext.When determining which
ContextLoaderto use for a given test class, the following algorithm should be used:- If a
ContextLoaderclass has been explicitly declared viaContextConfiguration.loader(), use it. - Otherwise, concrete implementations are free to determine which
ContextLoaderclass to use as a default.
- 指定者:
buildMergedContextConfiguration在接口中TestContextBootstrapper- 返回:
- the merged context configuration, never
null - 另请参阅:
TestContextBootstrapper.buildTestContext()
- Context hierarchies declared via
getContextCustomizerFactories
protected List<ContextCustomizerFactory> getContextCustomizerFactories()
Get theContextCustomizerFactoryinstances for this bootstrapper.The default implementation uses the
SpringFactoriesLoadermechanism for loading factories configured in allMETA-INF/spring.factoriesfiles on the classpath.
resolveContextLoader
protected ContextLoader resolveContextLoader(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList)
Resolve theContextLoaderclass to use for the supplied list ofContextConfigurationAttributesand then instantiate and return thatContextLoader.If the user has not explicitly declared which loader to use, the value returned from
getDefaultContextLoaderClass(java.lang.Class<?>)will be used as the default context loader class. For details on the class resolution process, seeresolveExplicitContextLoaderClass(java.util.List<org.springframework.test.context.ContextConfigurationAttributes>)andgetDefaultContextLoaderClass(java.lang.Class<?>).- 参数:
testClass- the test class for which theContextLoadershould be resolved; must not benullconfigAttributesList- the list of configuration attributes to process; must not benull; must be ordered bottom-up (i.e., as if we were traversing up the class hierarchy)- 返回:
- the resolved
ContextLoaderfor the suppliedtestClass(nevernull) - 抛出:
IllegalStateException- ifgetDefaultContextLoaderClass(Class)returnsnull
resolveExplicitContextLoaderClass
protected Class<? extends ContextLoader> resolveExplicitContextLoaderClass(List<ContextConfigurationAttributes> configAttributesList)
Resolve theContextLoaderclass to use for the supplied list ofContextConfigurationAttributes.Beginning with the first level in the context configuration attributes hierarchy:
- If the
contextLoaderClassproperty ofContextConfigurationAttributesis configured with an explicit class, that class will be returned. - If an explicit
ContextLoaderclass is not specified at the current level in the hierarchy, traverse to the next level in the hierarchy and return to step #1.
- 参数:
configAttributesList- the list of configuration attributes to process; must not benull; must be ordered bottom-up (i.e., as if we were traversing up the class hierarchy)- 返回:
- the
ContextLoaderclass to use for the supplied configuration attributes, ornullif no explicit loader is found - 抛出:
IllegalArgumentException- if supplied configuration attributes arenullor empty
- If the
getCacheAwareContextLoaderDelegate
protected CacheAwareContextLoaderDelegate getCacheAwareContextLoaderDelegate()
Get theCacheAwareContextLoaderDelegateto use for transparent interaction with theContextCache.The default implementation simply delegates to
getBootstrapContext().getCacheAwareContextLoaderDelegate().Concrete subclasses may choose to override this method to return a custom
CacheAwareContextLoaderDelegateimplementation with customContextCachesupport.- 返回:
- the context loader delegate (never
null)
getDefaultContextLoaderClass
protected abstract Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass)
Determine the defaultContextLoaderclass to use for the supplied test class.The class returned by this method will only be used if a
ContextLoaderclass has not been explicitly declared viaContextConfiguration.loader().- 参数:
testClass- the test class for which to retrieve the defaultContextLoaderclass- 返回:
- the default
ContextLoaderclass for the supplied test class (nevernull)
processMergedContextConfiguration
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig)
Process the supplied, newly instantiatedMergedContextConfigurationinstance.The returned
MergedContextConfigurationinstance may be a wrapper around or a replacement for the original.The default implementation simply returns the supplied instance unmodified.
Concrete subclasses may choose to return a specialized subclass of
MergedContextConfigurationbased on properties in the supplied instance.- 参数:
mergedConfig- theMergedContextConfigurationto process; nevernull- 返回:
- a fully initialized
MergedContextConfiguration; nevernull