Class MergedContextConfiguration
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
WebMergedContextConfiguration
MergedContextConfiguration
encapsulates the merged context
configuration declared on a test class and all of its superclasses and
enclosing classes via @ContextConfiguration
,
@ActiveProfiles
, and
@TestPropertySource
.
Merged context resource locations, annotated classes, active profiles,
property resource locations, and in-lined properties represent all declared
values in the test class hierarchy and enclosing class hierarchy taking into
consideration the semantics of the ContextConfiguration.inheritLocations()
,
ActiveProfiles.inheritProfiles()
,
TestPropertySource.inheritLocations()
, and
TestPropertySource.inheritProperties()
flags.
A SmartContextLoader
uses MergedContextConfiguration
to load an ApplicationContext
.
MergedContextConfiguration
is also used by the
ContextCache
as the key for caching an
ApplicationContext
that was loaded using properties of this MergedContextConfiguration
.
- Since:
- 3.1
- Author:
- Sam Brannen, Phillip Webb
- See Also:
-
Constructor Summary
ConstructorDescriptionMergedContextConfiguration
(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Deprecated.MergedContextConfiguration
(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) MergedContextConfiguration
(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, List<PropertySourceDescriptor> propertySourceDescriptors, String @Nullable [] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Create a newMergedContextConfiguration
instance for the supplied parameters.MergedContextConfiguration
(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, ContextLoader contextLoader) Create a newMergedContextConfiguration
instance for the supplied parameters.MergedContextConfiguration
(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Create a newMergedContextConfiguration
instance for the supplied parameters.MergedContextConfiguration
(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, String @Nullable [] activeProfiles, ContextLoader contextLoader) Create a newMergedContextConfiguration
instance for the supplied parameters.MergedContextConfiguration
(MergedContextConfiguration mergedConfig) Create a newMergedContextConfiguration
instance by copying all fields from the suppliedMergedContextConfiguration
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Determine if the supplied object is equal to thisMergedContextConfiguration
instance by comparing both objects' locations, annotated classes, context initializer classes, active profiles, property source descriptors, property source properties, context customizers, parents, and the fully qualified names of theirContextLoaders
.String[]
Get the merged active bean definition profiles for the test class.Class<?>[]
Get the merged annotated classes for the test class.Get the mergedContextCustomizers
that will be applied when the application context is loaded.Set<Class<? extends ApplicationContextInitializer<?>>>
Get the mergedApplicationContextInitializer
classes for the test class.Get the resolvedContextLoader
for the test class.String[]
Get the merged resource locations forApplicationContext
configuration files for the test class.Get theMergedContextConfiguration
for the parent application context in a context hierarchy.Get the parentApplicationContext
for the context defined by thisMergedContextConfiguration
from the context cache.Get the merged descriptors for resource locations for testPropertySources
for the test class.String[]
Deprecated.since 6.1 in favor ofgetPropertySourceDescriptors()
String[]
Get the merged inlined properties for the test class.Class<?>
Get the test class associated with thisMergedContextConfiguration
.boolean
Determine if thisMergedContextConfiguration
instance has class-based resources.int
hashCode()
Generate a unique hash code for all properties of thisMergedContextConfiguration
excluding the test class.boolean
Determine if thisMergedContextConfiguration
instance has path-based context resource locations.boolean
Determine if thisMergedContextConfiguration
instance has either path-based context resource locations or class-based resources.protected static String
nullSafeClassName
(@Nullable ContextLoader contextLoader) Generate a null-safeString
representation of the suppliedContextLoader
based solely on the fully qualified name of the loader or "null" if the supplied loader isnull
.protected static String[]
processStrings
(String @Nullable [] array) toString()
Provide a String representation of the test class, locations, annotated classes, context initializer classes, active profiles, property source descriptors, property source properties, context customizers, the name of theContextLoader
, and the parent configuration.
-
Constructor Details
-
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, String @Nullable [] activeProfiles, ContextLoader contextLoader) Create a newMergedContextConfiguration
instance for the supplied parameters.- Parameters:
testClass
- the test class for which the configuration was mergedlocations
- the merged context resource locationsclasses
- the merged annotated classesactiveProfiles
- the merged active bean definition profilescontextLoader
- the resolvedContextLoader
-
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, ContextLoader contextLoader) Create a newMergedContextConfiguration
instance for the supplied parameters.- Parameters:
testClass
- the test class for which the configuration was mergedlocations
- the merged context resource locationsclasses
- the merged annotated classescontextInitializerClasses
- the merged context initializer classesactiveProfiles
- the merged active bean definition profilescontextLoader
- the resolvedContextLoader
-
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Create a newMergedContextConfiguration
instance for the supplied parameters.- Parameters:
testClass
- the test class for which the configuration was mergedlocations
- the merged context resource locationsclasses
- the merged annotated classescontextInitializerClasses
- the merged context initializer classesactiveProfiles
- the merged active bean definition profilescontextLoader
- the resolvedContextLoader
cacheAwareContextLoaderDelegate
- a cache-aware context loader delegate with which to retrieve the parentApplicationContext
parent
- the parent configuration ornull
if there is no parent- Since:
- 3.2.2
-
MergedContextConfiguration
Create a newMergedContextConfiguration
instance by copying all fields from the suppliedMergedContextConfiguration
.- Since:
- 4.1
-
MergedContextConfiguration
@Deprecated(since="6.1") public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Deprecated.Create a newMergedContextConfiguration
instance for the supplied parameters.If a
null
value is supplied forlocations
,classes
,activeProfiles
,propertySourceLocations
, orpropertySourceProperties
an empty array will be stored instead. If anull
value is supplied for thecontextInitializerClasses
an empty set will be stored instead. Furthermore, active profiles will be sorted, and duplicate profiles will be removed.- Parameters:
testClass
- the test class for which the configuration was mergedlocations
- the merged context resource locationsclasses
- the merged annotated classescontextInitializerClasses
- the merged context initializer classesactiveProfiles
- the merged active bean definition profilespropertySourceLocations
- the mergedPropertySource
locationspropertySourceProperties
- the mergedPropertySource
propertiescontextLoader
- the resolvedContextLoader
cacheAwareContextLoaderDelegate
- a cache-aware context loader delegate with which to retrieve the parentApplicationContext
parent
- the parent configuration ornull
if there is no parent- Since:
- 4.1
-
MergedContextConfiguration
@Deprecated(since="6.1") public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Deprecated.Create a newMergedContextConfiguration
instance for the supplied parameters.If a
null
value is supplied forlocations
,classes
,activeProfiles
,propertySourceLocations
, orpropertySourceProperties
an empty array will be stored instead. If anull
value is supplied forcontextInitializerClasses
orcontextCustomizers
, an empty set will be stored instead. Furthermore, active profiles will be sorted, and duplicate profiles will be removed.- Parameters:
testClass
- the test class for which the configuration was mergedlocations
- the merged context resource locationsclasses
- the merged annotated classescontextInitializerClasses
- the merged context initializer classesactiveProfiles
- the merged active bean definition profilespropertySourceLocations
- the mergedPropertySource
locationspropertySourceProperties
- the mergedPropertySource
propertiescontextCustomizers
- the context customizerscontextLoader
- the resolvedContextLoader
cacheAwareContextLoaderDelegate
- a cache-aware context loader delegate with which to retrieve the parentApplicationContext
parent
- the parent configuration ornull
if there is no parent- Since:
- 4.3
-
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String @Nullable [] locations, Class<?> @Nullable [] classes, @Nullable Set<Class<? extends ApplicationContextInitializer<?>>> contextInitializerClasses, String @Nullable [] activeProfiles, List<PropertySourceDescriptor> propertySourceDescriptors, String @Nullable [] propertySourceProperties, @Nullable Set<ContextCustomizer> contextCustomizers, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) Create a newMergedContextConfiguration
instance for the supplied parameters.If a
null
value is supplied forlocations
,classes
,activeProfiles
, orpropertySourceProperties
an empty array will be stored instead. If anull
value is supplied forcontextInitializerClasses
orcontextCustomizers
, an empty set will be stored instead. Furthermore, active profiles will be sorted, and duplicate profiles will be removed.- Parameters:
testClass
- the test class for which the configuration was mergedlocations
- the merged context resource locationsclasses
- the merged annotated classescontextInitializerClasses
- the merged context initializer classesactiveProfiles
- the merged active bean definition profilespropertySourceDescriptors
- the merged property source descriptorspropertySourceProperties
- the merged inlined propertiescontextCustomizers
- the context customizerscontextLoader
- the resolvedContextLoader
cacheAwareContextLoaderDelegate
- a cache-aware context loader delegate with which to retrieve the parentApplicationContext
parent
- the parent configuration ornull
if there is no parent- Since:
- 6.1
-
-
Method Details
-
getTestClass
Get the test class associated with thisMergedContextConfiguration
. -
getLocations
Get the merged resource locations forApplicationContext
configuration files for the test class.Context resource locations typically represent XML configuration files or Groovy scripts.
-
getClasses
Get the merged annotated classes for the test class. -
hasLocations
public boolean hasLocations()Determine if thisMergedContextConfiguration
instance has path-based context resource locations.- Returns:
true
if thelocations
array is not empty- Since:
- 4.0.4
- See Also:
-
hasClasses
public boolean hasClasses()Determine if thisMergedContextConfiguration
instance has class-based resources.- Returns:
true
if theclasses
array is not empty- Since:
- 4.0.4
- See Also:
-
hasResources
public boolean hasResources()Determine if thisMergedContextConfiguration
instance has either path-based context resource locations or class-based resources. -
getContextInitializerClasses
Get the mergedApplicationContextInitializer
classes for the test class. -
getActiveProfiles
Get the merged active bean definition profiles for the test class.- See Also:
-
getPropertySourceDescriptors
Get the merged descriptors for resource locations for testPropertySources
for the test class.Properties will be loaded into the
Environment
's set ofPropertySources
.- Since:
- 6.1
- See Also:
-
getPropertySourceLocations
Deprecated.since 6.1 in favor ofgetPropertySourceDescriptors()
Get the merged resource locations of properties files for the test class.- See Also:
-
getPropertySourceProperties
Get the merged inlined properties for the test class.Properties will be loaded into the
Environment
's set ofPropertySources
.- See Also:
-
getContextCustomizers
Get the mergedContextCustomizers
that will be applied when the application context is loaded. -
getContextLoader
Get the resolvedContextLoader
for the test class. -
getParent
Get theMergedContextConfiguration
for the parent application context in a context hierarchy.- Returns:
- the parent configuration or
null
if there is no parent - Since:
- 3.2.2
- See Also:
-
getParentApplicationContext
Get the parentApplicationContext
for the context defined by thisMergedContextConfiguration
from the context cache.If the parent context has not yet been loaded, it will be loaded, stored in the cache, and then returned.
- Returns:
- the parent
ApplicationContext
ornull
if there is no parent - Since:
- 3.2.2
- See Also:
-
equals
Determine if the supplied object is equal to thisMergedContextConfiguration
instance by comparing both objects' locations, annotated classes, context initializer classes, active profiles, property source descriptors, property source properties, context customizers, parents, and the fully qualified names of theirContextLoaders
. -
hashCode
public int hashCode()Generate a unique hash code for all properties of thisMergedContextConfiguration
excluding the test class. -
toString
Provide a String representation of the test class, locations, annotated classes, context initializer classes, active profiles, property source descriptors, property source properties, context customizers, the name of theContextLoader
, and the parent configuration. -
processStrings
-
nullSafeClassName
Generate a null-safeString
representation of the suppliedContextLoader
based solely on the fully qualified name of the loader or "null" if the supplied loader isnull
.
-
MergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)