Class DefaultCacheAwareContextLoaderDelegate
- java.lang.Object
- org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate
- All Implemented Interfaces:
CacheAwareContextLoaderDelegate
public class DefaultCacheAwareContextLoaderDelegate extends Object implements CacheAwareContextLoaderDelegate
Default implementation of theCacheAwareContextLoaderDelegateinterface.To use a static
DefaultContextCache, invoke theDefaultCacheAwareContextLoaderDelegate()constructor; otherwise, invoke theDefaultCacheAwareContextLoaderDelegate(ContextCache)and provide a customContextCacheimplementation.- Since:
- 4.1
- Author:
- Sam Brannen
Constructor Summary
Constructors Constructor Description DefaultCacheAwareContextLoaderDelegate()Construct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCache.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode)Remove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.protected ContextCachegetContextCache()Get theContextCacheused by this context loader delegate.ApplicationContextloadContext(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 Detail
DefaultCacheAwareContextLoaderDelegate
public 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.
DefaultCacheAwareContextLoaderDelegate
public DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)
Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCache.
Method Detail
getContextCache
protected ContextCache getContextCache()
Get theContextCacheused by this context loader delegate.
loadContextInternal
protected 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
loadContext
public ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration)
Description 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 interfaceCacheAwareContextLoaderDelegate- Parameters:
mergedContextConfiguration- the merged context configuration to use to load the application context; nevernull- Returns:
- the application context
closeContext
public void closeContext(MergedContextConfiguration mergedContextConfiguration, 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 interfaceCacheAwareContextLoaderDelegate- Parameters:
mergedContextConfiguration- the merged context configuration for the application context to close; nevernullhierarchyMode- the hierarchy mode; may benullif the context is not part of a hierarchy