public abstract class AbstractTestContextBootstrapper extends Object implements TestContextBootstrapper
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:
| Constructor and Description |
|---|
AbstractTestContextBootstrapper() |
| Modifier and Type | Method and Description |
|---|---|
MergedContextConfiguration |
buildMergedContextConfiguration()
Build the merged context configuration
for the test class in the
BootstrapContext associated with this
bootstrapper. |
BootstrapContext |
getBootstrapContext()
Get the
BootstrapContext associated with this bootstrapper. |
protected abstract Class<? extends ContextLoader> |
getDefaultContextLoaderClass(Class<?> testClass)
Determine the default
ContextLoader class to use for the supplied
test class. |
protected Set<Class<? extends TestExecutionListener>> |
getDefaultTestExecutionListenerClasses()
Get the default
TestExecutionListener classes for this bootstrapper. |
protected List<String> |
getDefaultTestExecutionListenerClassNames()
Get the names of the default
TestExecutionListener classes for
this bootstrapper. |
List<TestExecutionListener> |
getTestExecutionListeners()
Get a list of newly instantiated
TestExecutionListeners
for the test class in the BootstrapContext associated with this bootstrapper. |
protected MergedContextConfiguration |
processMergedContextConfiguration(MergedContextConfiguration mergedConfig)
Process the supplied, newly instantiated
MergedContextConfiguration instance. |
void |
setBootstrapContext(BootstrapContext bootstrapContext)
Set the
BootstrapContext to be used by this bootstrapper. |
public void setBootstrapContext(BootstrapContext bootstrapContext)
BootstrapContext to be used by this bootstrapper.setBootstrapContext in interface TestContextBootstrapperpublic BootstrapContext getBootstrapContext()
BootstrapContext associated with this bootstrapper.getBootstrapContext in interface TestContextBootstrapperpublic final List<TestExecutionListener> getTestExecutionListeners()
TestExecutionListeners
for the test class in the BootstrapContext associated with this bootstrapper.
If @TestExecutionListeners is not
present on the test class in the BootstrapContext,
default listeners should be returned. Furthermore, default
listeners must be sorted using
AnnotationAwareOrderComparator.
Concrete implementations are free to determine what comprises the
set of default listeners. However, by default, the Spring TestContext
Framework will use the
SpringFactoriesLoader
mechanism to look up all TestExecutionListener class names
configured in all META-INF/spring.factories files on the classpath.
The inheritListeners
flag of @TestExecutionListeners must be
taken into consideration. Specifically, if the inheritListeners
flag is set to true, listeners declared for a given test class must
be appended to the end of the list of listeners declared in superclasses.
getTestExecutionListeners in interface TestContextBootstrapperTestExecutionListener instancesprotected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses()
TestExecutionListener classes for this bootstrapper.
This method is invoked by getTestExecutionListeners() and
delegates to getDefaultTestExecutionListenerClassNames() to
retrieve the class names.
If a particular class cannot be loaded, a DEBUG message will
be logged, but the associated exception will not be rethrown.
protected List<String> getDefaultTestExecutionListenerClassNames()
TestExecutionListener classes for
this bootstrapper.
The default implementation looks up all
org.springframework.test.context.TestExecutionListener entries
configured in all META-INF/spring.factories files on the classpath.
This method is invoked by getDefaultTestExecutionListenerClasses().
TestExecutionListener
classesSpringFactoriesLoader.loadFactoryNames(java.lang.Class<?>, java.lang.ClassLoader)public final MergedContextConfiguration buildMergedContextConfiguration()
BootstrapContext associated with this
bootstrapper.
Implementations must take the following into account when building the merged configuration:
@ContextHierarchy
and @ContextConfiguration@ActiveProfilesContextConfiguration.initializers()Consult the Javadoc for the aforementioned annotations for details on the required semantics.
When determining which ContextLoader to use for a given test
class, the following algorithm should be used:
ContextLoader class has been explicitly declared via
ContextConfiguration.loader(), use it.ContextLoader class to use as as default.buildMergedContextConfiguration in interface TestContextBootstrappernullprotected abstract Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass)
ContextLoader class to use for the supplied
test class.
The class returned by this method will only be used if a ContextLoader
class has not been explicitly declared via ContextConfiguration.loader().
testClass - the test class for which to retrieve the default
ContextLoader classprotected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig)
MergedContextConfiguration instance.
The returned MergedContextConfiguration instance 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
MergedContextConfiguration based on properties in the supplied instance.
mergedConfig - the MergedContextConfiguration to process;
never nullMergedContextConfiguration; never
null