类 AbstractTestContextBootstrapper
- 所有已实现的接口:
TestContextBootstrapper
- 直接已知子类:
DefaultTestContextBootstrapper
TestContextBootstrapper interface 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(cn.taketoday.test.context.MergedContextConfiguration)
To plug in custom
ContextCache
support, override getCacheAwareContextLoaderDelegate().
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Juergen Hoeller, Phillip Webb, Harry Yang
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static booleanareAllEmpty(Collection<?>... collections) private MergedContextConfigurationbuildDefaultMergedContextConfiguration(Class<?> testClass, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) Build the merged context configuration for the test class in theBootstrapContextassociated with this bootstrapper.private MergedContextConfigurationbuildMergedContextConfiguration(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList, MergedContextConfiguration parentConfig, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, boolean requireLocationsClassesOrInitializers) Build themerged context configurationfor the suppliedtestClass, context configuration attributes, and parent context configuration.Build a newDefaultTestContextusing the test class in theBootstrapContextassociated with this bootstrapper and by delegating tobuildMergedContextConfiguration()andgetCacheAwareContextLoaderDelegate().classSimpleNames(Collection<?> components) Get theBootstrapContextassociated with this bootstrapper.protected CacheAwareContextLoaderDelegateGet theCacheAwareContextLoaderDelegateto use for transparent interaction with theContextCache.protected List<ContextCustomizerFactory>Get theContextCustomizerFactoryinstances for this bootstrapper.private List<ContextCustomizerFactory>getContextCustomizerFactories(Class<?> testClass) private Set<ContextCustomizer>getContextCustomizers(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) protected abstract Class<? extends ContextLoader>getDefaultContextLoaderClass(Class<?> testClass) Determine the defaultContextLoaderclass to use for the supplied test class.protected List<TestExecutionListener>Get the defaultTestExecutionListenersfor this bootstrapper.final List<TestExecutionListener>Get a list of newly instantiatedTestExecutionListenersfor the test class in theBootstrapContextassociated with this bootstrapper.private <T> List<T>instantiateComponents(Class<T> componentType, Class<? extends T>... classes) private List<ContextCustomizerFactory>instantiateCustomizerFactories(Class<? extends ContextCustomizerFactory>... classes) private List<TestExecutionListener>instantiateListeners(Class<? extends TestExecutionListener>... classes) protected MergedContextConfigurationprocessMergedContextConfiguration(MergedContextConfiguration mergedConfig) Process the supplied, newly instantiatedMergedContextConfigurationinstance.protected ContextLoaderresolveContextLoader(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList) Resolve theContextLoaderclass to use for the supplied list ofContextConfigurationAttributesand then instantiate and return thatContextLoader.protected Class<? extends ContextLoader>resolveExplicitContextLoaderClass(List<ContextConfigurationAttributes> configAttributesList) voidsetBootstrapContext(BootstrapContext bootstrapContext) Set theBootstrapContextto be used by this bootstrapper.
-
字段详细资料
-
log
private static final cn.taketoday.logging.Logger log -
bootstrapContext
-
-
构造器详细资料
-
AbstractTestContextBootstrapper
public AbstractTestContextBootstrapper()
-
-
方法详细资料
-
setBootstrapContext
从接口复制的说明:TestContextBootstrapperSet theBootstrapContextto be used by this bootstrapper.- 指定者:
setBootstrapContext在接口中TestContextBootstrapper
-
getBootstrapContext
从接口复制的说明:TestContextBootstrapperGet theBootstrapContextassociated with this bootstrapper.- 指定者:
getBootstrapContext在接口中TestContextBootstrapper
-
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 - 另请参阅:
-
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 Infra TestContext Framework will use the
TodayStrategiesmechanism to look up allTestExecutionListenerclass names configured in allMETA-INF/today.strategiesfiles 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
-
instantiateListeners
private List<TestExecutionListener> instantiateListeners(Class<? extends TestExecutionListener>... classes) -
getDefaultTestExecutionListeners
Get the defaultTestExecutionListenersfor this bootstrapper.The default implementation delegates to
TestContextFactoriesUtils.loadFactoryImplementations(Class).This method is invoked by
getTestExecutionListeners().- 返回:
- an unmodifiable list of default
TestExecutionListenerinstances
-
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 - 另请参阅:
- Context hierarchies declared via
-
buildDefaultMergedContextConfiguration
private MergedContextConfiguration buildDefaultMergedContextConfiguration(Class<?> testClass, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) -
buildMergedContextConfiguration
private MergedContextConfiguration buildMergedContextConfiguration(Class<?> testClass, List<ContextConfigurationAttributes> configAttributesList, @Nullable MergedContextConfiguration parentConfig, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, boolean requireLocationsClassesOrInitializers) Build themerged context configurationfor the suppliedtestClass, context configuration attributes, and parent context configuration.- 参数:
testClass- the test class for which theMergedContextConfigurationshould be built (must not benull)configAttributesList- the list of context configuration attributes for the specified test class, ordered bottom-up (i.e., as if we were traversing up the class hierarchy and enclosing class hierarchy); nevernullor emptyparentConfig- the merged context configuration for the parent application context in a context hierarchy, ornullif there is no parentcacheAwareContextLoaderDelegate- the cache-aware context loader delegate to be passed to theMergedContextConfigurationconstructorrequireLocationsClassesOrInitializers- whether locations, classes, or initializers are required; typicallytruebut may be set tofalseif the configured loader supports empty configuration- 返回:
- the merged context configuration
- 另请参阅:
-
resolveContextLoader(java.lang.Class<?>, java.util.List<cn.taketoday.test.context.ContextConfigurationAttributes>)ContextLoaderUtils.resolveContextConfigurationAttributes(java.lang.Class<?>)SmartContextLoader.processContextConfiguration(cn.taketoday.test.context.ContextConfigurationAttributes)ContextLoader.processLocations(java.lang.Class<?>, java.lang.String...)ActiveProfilesUtils.resolveActiveProfiles(java.lang.Class<?>)ApplicationContextInitializerUtils.resolveInitializerClasses(java.util.List<cn.taketoday.test.context.ContextConfigurationAttributes>)MergedContextConfiguration
-
getContextCustomizers
private Set<ContextCustomizer> getContextCustomizers(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) -
getContextCustomizerFactories
-
getContextCustomizerFactories
Get theContextCustomizerFactoryinstances for this bootstrapper.The default implementation delegates to
TestContextFactoriesUtils.loadFactoryImplementations(Class). -
instantiateCustomizerFactories
private List<ContextCustomizerFactory> instantiateCustomizerFactories(Class<? extends ContextCustomizerFactory>... classes) -
instantiateComponents
-
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<cn.taketoday.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 and enclosing class hierarchy)- 返回:
- the resolved
ContextLoaderfor the suppliedtestClass(nevernull) - 抛出:
IllegalStateException- ifgetDefaultContextLoaderClass(Class)returnsnull
-
resolveExplicitContextLoaderClass
@Nullable 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 and enclosing 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
Get theCacheAwareContextLoaderDelegateto use for transparent interaction with theContextCache.The default implementation delegates to
getBootstrapContext().getCacheAwareContextLoaderDelegate()and the default one will loadApplicationContextFailureProcessorvia the service loading mechanism.Concrete subclasses may choose to override this method to return a custom
CacheAwareContextLoaderDelegateimplementation with customContextCachesupport.- 返回:
- the context loader delegate (never
null) - 另请参阅:
-
getDefaultContextLoaderClass
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
-
classSimpleNames
-
areAllEmpty
-