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 java.lang.String |
DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME |
private static Log |
logger |
private static java.lang.String |
WEB_APP_CONFIGURATION_CLASS_NAME |
private static java.lang.String |
WEB_MERGED_CONTEXT_CONFIGURATION_CLASS_NAME |
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 . |
private static MergedContextConfiguration |
buildWebMergedContextConfiguration(java.lang.Class<?> testClass,
java.lang.String[] locations,
java.lang.Class<?>[] classes,
java.util.Set<java.lang.Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses,
java.lang.String[] activeProfiles,
ContextLoader contextLoader)
Attempt to build a
WebMergedContextConfiguration from the supplied arguments, using reflection
in order to avoid package cycles. |
private static java.lang.Class<? extends java.lang.annotation.Annotation> |
loadWebAppConfigurationClass()
Load the
@WebAppConfiguration
class, using reflection in order to avoid package cycles. |
(package private) static java.lang.String[] |
resolveActiveProfiles(java.lang.Class<?> testClass)
Resolve active bean definition profiles for the supplied
Class . |
(package private) static java.util.List<ContextConfigurationAttributes> |
resolveContextConfigurationAttributes(java.lang.Class<?> testClass)
Resolve the list of
configuration
attributes for the supplied class and its superclasses. |
(package private) static ContextLoader |
resolveContextLoader(java.lang.Class<?> testClass,
java.util.List<ContextConfigurationAttributes> configAttributesList,
java.lang.String defaultContextLoaderClassName)
Resolve the
ContextLoader class to use for the
supplied list of ContextConfigurationAttributes and then
instantiate and return that ContextLoader . |
(package private) static java.lang.Class<? extends ContextLoader> |
resolveContextLoaderClass(java.lang.Class<?> testClass,
java.util.List<ContextConfigurationAttributes> configAttributesList,
java.lang.String defaultContextLoaderClassName)
Resolve the
ContextLoader class to use for the
supplied list of ContextConfigurationAttributes . |
(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 final Log logger
private static final java.lang.String DEFAULT_CONTEXT_LOADER_CLASS_NAME
private static final java.lang.String DEFAULT_WEB_CONTEXT_LOADER_CLASS_NAME
private static final java.lang.String WEB_APP_CONFIGURATION_CLASS_NAME
private static final java.lang.String WEB_MERGED_CONTEXT_CONFIGURATION_CLASS_NAME
static ContextLoader resolveContextLoader(java.lang.Class<?> testClass, java.util.List<ContextConfigurationAttributes> configAttributesList, java.lang.String defaultContextLoaderClassName)
ContextLoader
class to use for the
supplied list of ContextConfigurationAttributes
and then
instantiate and return that ContextLoader
.
If the supplied defaultContextLoaderClassName
is
null
or empty, depending on the absence or presence
of @WebAppConfiguration
either "org.springframework.test.context.support.DelegatingSmartContextLoader"
or "org.springframework.test.context.support.WebDelegatingSmartContextLoader" will be used as the
default context loader class name. For details on the class resolution
process, see #resolveContextLoaderClass()
.
testClass
- the test class for which the ContextLoader
should be resolved; must not be null
configAttributesList
- the list of configuration attributes to process;
must not be null
or empty; must be ordered bottom-up
(i.e., as if we were traversing up the class hierarchy)defaultContextLoaderClassName
- the name of the default
ContextLoader
class to use; may be null
or emptyContextLoader
for the supplied
testClass
(never null
)#resolveContextLoaderClass()
static java.lang.Class<? extends ContextLoader> resolveContextLoaderClass(java.lang.Class<?> testClass, java.util.List<ContextConfigurationAttributes> configAttributesList, java.lang.String defaultContextLoaderClassName)
ContextLoader
class to use for the
supplied list of ContextConfigurationAttributes
.
Beginning with the first level in the context configuration attributes hierarchy:
contextLoaderClass
property of ContextConfigurationAttributes
is
configured with an explicit class, that class will be returned.ContextLoader
class is not specified at the
current level in the hierarchy, traverse to the next level in the hierarchy
and return to step #1.ContextLoader
class is found after traversing
the 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
; only used for logging purposesconfigAttributesList
- the list of configuration attributes to process;
must not be null
or empty; must be ordered bottom-up
(i.e., as if we were traversing up the class hierarchy)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<?> testClass)
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.
testClass
- 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 classstatic 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
or empty; must be ordered bottom-up
(i.e., as if we were traversing up the class hierarchy)null
)static java.lang.String[] resolveActiveProfiles(java.lang.Class<?> testClass)
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.
testClass
- 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
private static java.lang.Class<? extends java.lang.annotation.Annotation> loadWebAppConfigurationClass()
@WebAppConfiguration
class, using reflection in order to avoid package cycles.@WebAppConfiguration
class or null
if it
cannot be loadedprivate static MergedContextConfiguration buildWebMergedContextConfiguration(java.lang.Class<?> testClass, java.lang.String[] locations, java.lang.Class<?>[] classes, java.util.Set<java.lang.Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses, java.lang.String[] activeProfiles, ContextLoader contextLoader)
WebMergedContextConfiguration
from the supplied arguments, using reflection
in order to avoid package cycles.WebMergedContextConfiguration
or null
if
it could not be built