abstract class ContextLoaderUtils
extends java.lang.Object
ContextLoaders
and
SmartContextLoaders
and resolving resource locations,
annotated classes, and active bean definition profiles.ContextLoader
,
SmartContextLoader
,
ContextConfiguration
,
ContextConfigurationAttributes
,
ActiveProfiles
,
MergedContextConfiguration
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DEFAULT_CONTEXT_LOADER_CLASS_NAME |
private static Log |
logger |
Modifier | Constructor and Description |
---|---|
private |
ContextLoaderUtils() |
Modifier and Type | Method and Description |
---|---|
(package private) static MergedContextConfiguration |
buildMergedContextConfiguration(java.lang.Class<?> testClass,
java.lang.String defaultContextLoaderClassName)
Build the
merged context configuration
for the supplied testClass and
defaultContextLoaderClassName . |
(package private) static java.lang.String[] |
resolveActiveProfiles(java.lang.Class<?> clazz)
Resolve active bean definition profiles for the supplied
Class . |
(package private) static java.util.List<ContextConfigurationAttributes> |
resolveContextConfigurationAttributes(java.lang.Class<?> clazz)
Resolve the list of
configuration
attributes for the supplied class and its superclasses. |
(package private) static ContextLoader |
resolveContextLoader(java.lang.Class<?> testClass,
java.lang.String defaultContextLoaderClassName)
Resolve the
ContextLoader class to use for the
supplied testClass and then instantiate and return that
ContextLoader . |
(package private) static java.lang.Class<? extends ContextLoader> |
resolveContextLoaderClass(java.lang.Class<?> testClass,
java.lang.String defaultContextLoaderClassName)
|
(package private) static java.util.Set<java.lang.Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> |
resolveInitializerClasses(java.util.List<ContextConfigurationAttributes> configAttributesList)
Resolve the list of merged
ApplicationContextInitializer classes
for the supplied list of ContextConfigurationAttributes . |
private static java.util.List<ContextConfigurationAttributes> |
reverseContextConfigurationAttributes(java.util.List<ContextConfigurationAttributes> configAttributesList)
Create a copy of the supplied list of
ContextConfigurationAttributes
in reverse order. |
private static final Log logger
private static final java.lang.String DEFAULT_CONTEXT_LOADER_CLASS_NAME
static ContextLoader resolveContextLoader(java.lang.Class<?> testClass, java.lang.String defaultContextLoaderClassName)
ContextLoader
class
to use for the
supplied testClass
and then instantiate and return that
ContextLoader
.
If the supplied defaultContextLoaderClassName
is
null
or empty, the standard
default context loader class name "org.springframework.test.context.support.DelegatingSmartContextLoader"
will be used. For details on the class resolution process, see
#resolveContextLoaderClass()
.
testClass
- the test class for which the ContextLoader
should be resolved (must not be null
)defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use (may be null
)ContextLoader
for the supplied
testClass
(never null
)#resolveContextLoaderClass()
static java.lang.Class<? extends ContextLoader> resolveContextLoaderClass(java.lang.Class<?> testClass, java.lang.String defaultContextLoaderClassName)
ContextLoader
Class
to use for the supplied
testClass
.
loader
attribute of
@ContextConfiguration
is configured
with an explicit class, that class will be returned.loader
class is not specified, the class hierarchy
will be traversed to find a parent class annotated with
@ContextConfiguration
; go to step #1.loader
class is found after traversing
the class hierarchy, an attempt will be made to load and return the class
with the supplied defaultContextLoaderClassName
.testClass
- the class for which to resolve the ContextLoader
class; must not be null
defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use; must not be null
or emptyContextLoader
class to use for the supplied test classjava.lang.IllegalArgumentException
- if @ContextConfiguration
is not
present on the supplied test classjava.lang.IllegalStateException
- if the default ContextLoader
class
could not be loadedstatic java.util.List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(java.lang.Class<?> clazz)
configuration
attributes
for the supplied class
and its superclasses.
Note that the inheritLocations
and inheritInitializers
flags of @ContextConfiguration
will not be taken into
consideration. If these flags need to be honored, that must be handled
manually when traversing the list returned by this method.
clazz
- the class for which to resolve the configuration attributes (must
not be null
)null
)java.lang.IllegalArgumentException
- if the supplied class is null
or
if @ContextConfiguration
is not present on the supplied classprivate static java.util.List<ContextConfigurationAttributes> reverseContextConfigurationAttributes(java.util.List<ContextConfigurationAttributes> configAttributesList)
ContextConfigurationAttributes
in reverse order.static java.util.Set<java.lang.Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> resolveInitializerClasses(java.util.List<ContextConfigurationAttributes> configAttributesList)
ApplicationContextInitializer
classes
for the supplied list of ContextConfigurationAttributes
.
Note that the inheritInitializers
flag of @ContextConfiguration
will be taken into
consideration. Specifically, if the inheritInitializers
flag is
set to true
for a given level in the class hierarchy represented by
the provided configuration attributes, context initializer classes defined
at the given level will be merged with those defined in higher levels
of the class hierarchy.
configAttributesList
- the list of configuration attributes to process
(must not be null
)null
)static java.lang.String[] resolveActiveProfiles(java.lang.Class<?> clazz)
Class
.
Note that the inheritProfiles
flag of @ActiveProfiles
will be taken into
consideration. Specifically, if the inheritProfiles
flag is
set to true
, profiles defined in the test class will be
merged with those defined in superclasses.
clazz
- the class for which to resolve the active profiles (must
not be null
)null
)ActiveProfiles
,
Profile
static MergedContextConfiguration buildMergedContextConfiguration(java.lang.Class<?> testClass, java.lang.String defaultContextLoaderClassName)
merged context configuration
for the supplied testClass
and
defaultContextLoaderClassName
.testClass
- the test class for which the MergedContextConfiguration
should be built (must not be null
)defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use (may be null
)#resolveContextLoader()
,
#resolveContextConfigurationAttributes()
,
SmartContextLoader#processContextConfiguration()
,
ContextLoader#processLocations()
,
#resolveActiveProfiles()
,
MergedContextConfiguration