Class MergedContextConfiguration
- java.lang.Object
- org.springframework.test.context.MergedContextConfiguration
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
WebMergedContextConfiguration
public class MergedContextConfiguration extends Object implements Serializable
MergedContextConfigurationencapsulates the merged context configuration declared on a test class and all of its superclasses 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 taking into consideration the semantics of the
ContextConfiguration.inheritLocations(),ActiveProfiles.inheritProfiles(),TestPropertySource.inheritLocations(), andTestPropertySource.inheritProperties()flags.A
SmartContextLoaderusesMergedContextConfigurationto load anApplicationContext.MergedContextConfigurationis also used by theContextCacheas the key for caching anApplicationContextthat was loaded using properties of thisMergedContextConfiguration.- Since:
- 3.1
- Author:
- Sam Brannen, Phillip Webb
- See Also:
ContextConfiguration,ContextHierarchy,ActiveProfiles,TestPropertySource,ContextConfigurationAttributes,SmartContextLoader.loadContext(MergedContextConfiguration), Serialized Form
Constructor Summary
Constructors Constructor Description MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, String[] activeProfiles, ContextLoader contextLoader)Create a newMergedContextConfigurationinstance for the supplied parameters.MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, Set<ContextCustomizer> contextCustomizers, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent)Create a newMergedContextConfigurationinstance for the supplied parameters.MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent)Create a newMergedContextConfigurationinstance for the supplied parameters.MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, ContextLoader contextLoader)Create a newMergedContextConfigurationinstance for the supplied parameters.MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent)Create a newMergedContextConfigurationinstance for the supplied parameters.MergedContextConfiguration(MergedContextConfiguration mergedConfig)Create a newMergedContextConfigurationinstance by copying all fields from the suppliedMergedContextConfiguration.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)Determine if the supplied object is equal to thisMergedContextConfigurationinstance by comparing both object's locations, annotated classes, context initializer classes, active profiles, property source locations, property source properties, parents, and the fully qualified names of theirContextLoaders.String[]getActiveProfiles()Get the merged active bean definition profiles for the test class.Class<?>[]getClasses()Get the merged annotated classes for the test class.Set<ContextCustomizer>getContextCustomizers()Get the mergedContextCustomizersthat will be applied when the application context is loaded.Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>>getContextInitializerClasses()Get the mergedApplicationContextInitializerclasses for the test class.ContextLoadergetContextLoader()Get the resolvedContextLoaderfor the test class.String[]getLocations()Get the merged resource locations forApplicationContextconfiguration files for the test class.MergedContextConfigurationgetParent()Get theMergedContextConfigurationfor the parent application context in a context hierarchy.ApplicationContextgetParentApplicationContext()Get the parentApplicationContextfor the context defined by thisMergedContextConfigurationfrom the context cache.String[]getPropertySourceLocations()Get the merged resource locations for testPropertySourcesfor the test class.String[]getPropertySourceProperties()Get the merged testPropertySourceproperties for the test class.Class<?>getTestClass()Get the test class associated with thisMergedContextConfiguration.booleanhasClasses()Determine if thisMergedContextConfigurationinstance has class-based resources.inthashCode()Generate a unique hash code for all properties of thisMergedContextConfigurationexcluding the test class.booleanhasLocations()Determine if thisMergedContextConfigurationinstance has path-based context resource locations.booleanhasResources()Determine if thisMergedContextConfigurationinstance has either path-based context resource locations or class-based resources.protected static StringnullSafeToString(ContextLoader contextLoader)Generate a null-safeStringrepresentation of the suppliedContextLoaderbased solely on the fully qualified name of the loader or "null" if the supplied loaded isnull.StringtoString()Provide a String representation of the test class, locations, annotated classes, context initializer classes, active profiles, property source locations, property source properties, context customizers, the name of theContextLoader, and the parent configuration.
Constructor Detail
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, String[] activeProfiles, ContextLoader contextLoader)
Create a newMergedContextConfigurationinstance 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[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, ContextLoader contextLoader)
Create a newMergedContextConfigurationinstance 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- See Also:
MergedContextConfiguration(Class, String[], Class[], Set, String[], ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent)
Create a newMergedContextConfigurationinstance 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 resolvedContextLoadercacheAwareContextLoaderDelegate- a cache-aware context loader delegate with which to retrieve the parent contextparent- the parent configuration ornullif there is no parent- Since:
- 3.2.2
MergedContextConfiguration
public MergedContextConfiguration(MergedContextConfiguration mergedConfig)
Create a newMergedContextConfigurationinstance by copying all fields from the suppliedMergedContextConfiguration.- Since:
- 4.1
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent)
Create a newMergedContextConfigurationinstance for the supplied parameters.If a
nullvalue is supplied forlocations,classes,activeProfiles,propertySourceLocations, orpropertySourcePropertiesan empty array will be stored instead. If anullvalue is supplied for thecontextInitializerClassesan 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 mergedPropertySourcelocationspropertySourceProperties- the mergedPropertySourcepropertiescontextLoader- the resolvedContextLoadercacheAwareContextLoaderDelegate- a cache-aware context loader delegate with which to retrieve the parent contextparent- the parent configuration ornullif there is no parent- Since:
- 4.1
MergedContextConfiguration
public MergedContextConfiguration(Class<?> testClass, String[] locations, Class<?>[] classes, Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> contextInitializerClasses, String[] activeProfiles, String[] propertySourceLocations, String[] propertySourceProperties, Set<ContextCustomizer> contextCustomizers, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, MergedContextConfiguration parent)
Create a newMergedContextConfigurationinstance for the supplied parameters.If a
nullvalue is supplied forlocations,classes,activeProfiles,propertySourceLocations, orpropertySourcePropertiesan empty array will be stored instead. If anullvalue is supplied forcontextInitializerClassesorcontextCustomizers, 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 mergedPropertySourcelocationspropertySourceProperties- the mergedPropertySourcepropertiescontextCustomizers- the context customizerscontextLoader- the resolvedContextLoadercacheAwareContextLoaderDelegate- a cache-aware context loader delegate with which to retrieve the parent contextparent- the parent configuration ornullif there is no parent- Since:
- 4.3
Method Detail
nullSafeToString
protected static String nullSafeToString(ContextLoader contextLoader)
Generate a null-safeStringrepresentation of the suppliedContextLoaderbased solely on the fully qualified name of the loader or "null" if the supplied loaded isnull.
getTestClass
public Class<?> getTestClass()
Get the test class associated with thisMergedContextConfiguration.
getLocations
public String[] getLocations()
Get the merged resource locations forApplicationContextconfiguration files for the test class.Context resource locations typically represent XML configuration files or Groovy scripts.
getClasses
public Class<?>[] getClasses()
Get the merged annotated classes for the test class.
hasLocations
public boolean hasLocations()
Determine if thisMergedContextConfigurationinstance has path-based context resource locations.- Returns:
trueif thelocationsarray is not empty- Since:
- 4.0.4
- See Also:
hasResources(),hasClasses()
hasClasses
public boolean hasClasses()
Determine if thisMergedContextConfigurationinstance has class-based resources.- Returns:
trueif theclassesarray is not empty- Since:
- 4.0.4
- See Also:
hasResources(),hasLocations()
hasResources
public boolean hasResources()
Determine if thisMergedContextConfigurationinstance has either path-based context resource locations or class-based resources.- Returns:
trueif either thelocationsor theclassesarray is not empty- Since:
- 4.0.4
- See Also:
hasLocations(),hasClasses()
getContextInitializerClasses
public Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> getContextInitializerClasses()
Get the mergedApplicationContextInitializerclasses for the test class.
getActiveProfiles
public String[] getActiveProfiles()
Get the merged active bean definition profiles for the test class.- See Also:
ActiveProfiles
getPropertySourceLocations
public String[] getPropertySourceLocations()
Get the merged resource locations for testPropertySourcesfor the test class.- See Also:
TestPropertySource.locations(),Properties
getPropertySourceProperties
public String[] getPropertySourceProperties()
Get the merged testPropertySourceproperties for the test class.Properties will be loaded into the
Environment's set ofPropertySources.- See Also:
TestPropertySource.properties(),Properties
getContextCustomizers
public Set<ContextCustomizer> getContextCustomizers()
Get the mergedContextCustomizersthat will be applied when the application context is loaded.
getContextLoader
public ContextLoader getContextLoader()
Get the resolvedContextLoaderfor the test class.
getParent
public MergedContextConfiguration getParent()
Get theMergedContextConfigurationfor the parent application context in a context hierarchy.- Returns:
- the parent configuration or
nullif there is no parent - Since:
- 3.2.2
- See Also:
getParentApplicationContext()
getParentApplicationContext
public ApplicationContext getParentApplicationContext()
Get the parentApplicationContextfor the context defined by thisMergedContextConfigurationfrom 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
ApplicationContextornullif there is no parent - Since:
- 3.2.2
- See Also:
getParent()
equals
public boolean equals(Object other)
Determine if the supplied object is equal to thisMergedContextConfigurationinstance by comparing both object's locations, annotated classes, context initializer classes, active profiles, property source locations, property source properties, parents, and the fully qualified names of theirContextLoaders.
hashCode
public int hashCode()
Generate a unique hash code for all properties of thisMergedContextConfigurationexcluding the test class.
toString
public String toString()
Provide a String representation of the test class, locations, annotated classes, context initializer classes, active profiles, property source locations, property source properties, context customizers, the name of theContextLoader, and the parent configuration.