Class DefaultCacheAwareContextLoaderDelegate
- All Implemented Interfaces:
- CacheAwareContextLoaderDelegate
CacheAwareContextLoaderDelegate interface.
 To use a static DefaultContextCache, invoke the
 DefaultCacheAwareContextLoaderDelegate() constructor; otherwise,
 invoke the DefaultCacheAwareContextLoaderDelegate(ContextCache)
 and provide a custom ContextCache implementation.
- Since:
- 4.1
- Author:
- Sam Brannen
- 
Field SummaryFields inherited from interface org.springframework.test.context.CacheAwareContextLoaderDelegateDEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_PROPERTY_NAME
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache) Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCache.
- 
Method SummaryModifier and TypeMethodDescriptionvoidcloseContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode) Remove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.protected ContextCacheGet theContextCacheused by this context loader delegate.booleanisContextLoaded(MergedContextConfiguration mergedContextConfiguration) Determine if the application context for the suppliedMergedContextConfigurationhas been loaded (i.e., is present in theContextCache).loadContext(MergedContextConfiguration mergedContextConfiguration) Load the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.protected ApplicationContextloadContextInternal(MergedContextConfiguration mergedContextConfiguration) Load theApplicationContextfor the supplied merged context configuration.
- 
Constructor Details- 
DefaultCacheAwareContextLoaderDelegatepublic DefaultCacheAwareContextLoaderDelegate()Construct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.This default cache is static so that each context can be cached and reused for all subsequent tests that declare the same unique context configuration within the same JVM process. 
- 
DefaultCacheAwareContextLoaderDelegateConstruct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCache.- See Also:
 
 
- 
- 
Method Details- 
getContextCacheGet theContextCacheused by this context loader delegate.
- 
loadContextInternalprotected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration) throws Exception Load theApplicationContextfor the supplied merged context configuration.Supports both the SmartContextLoaderandContextLoaderSPIs.- Throws:
- Exception- if an error occurs while loading the application context
 
- 
isContextLoadedDescription copied from interface:CacheAwareContextLoaderDelegateDetermine if the application context for the suppliedMergedContextConfigurationhas been loaded (i.e., is present in theContextCache).Implementations of this method must not load the application context as a side effect. In addition, implementations of this method should not log the cache statistics via ContextCache.logStatistics().The default implementation of this method always returns false. CustomCacheAwareContextLoaderDelegateimplementations are therefore highly encouraged to override this method with a more meaningful implementation. Note that the standardCacheAwareContextLoaderDelegateimplementation in Spring overrides this method appropriately.- Specified by:
- isContextLoadedin interface- CacheAwareContextLoaderDelegate
- Parameters:
- mergedContextConfiguration- the merged context configuration used to load the application context; never- null
- Returns:
- trueif the application context has been loaded
- See Also:
 
- 
loadContextDescription copied from interface:CacheAwareContextLoaderDelegateLoad the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.If the context is present in the ContextCacheit will simply be returned; otherwise, it will be loaded, stored in the cache, and returned.The cache statistics should be logged by invoking ContextCache.logStatistics().- Specified by:
- loadContextin interface- CacheAwareContextLoaderDelegate
- Parameters:
- mergedContextConfiguration- the merged context configuration to use to load the application context; never- null
- Returns:
- the application context (never null)
- See Also:
 
- 
closeContextpublic void closeContext(MergedContextConfiguration mergedContextConfiguration, @Nullable DirtiesContext.HierarchyMode hierarchyMode) Description copied from interface:CacheAwareContextLoaderDelegateRemove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.The semantics of the supplied HierarchyModemust be honored when removing the context from the cache. See the Javadoc forDirtiesContext.HierarchyModefor details.Generally speaking, this method should only be called if the state of a singleton bean has been changed (potentially affecting future interaction with the context) or if the context needs to be prematurely removed from the cache. - Specified by:
- closeContextin interface- CacheAwareContextLoaderDelegate
- Parameters:
- mergedContextConfiguration- the merged context configuration for the application context to close; never- null
- hierarchyMode- the hierarchy mode; may be- nullif the context is not part of a hierarchy
- See Also:
 
 
-