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 theCacheAwareContextLoaderDelegate
interface.To use a static
DefaultContextCache
, invoke theDefaultCacheAwareContextLoaderDelegate()
constructor; otherwise, invoke theDefaultCacheAwareContextLoaderDelegate(ContextCache)
and provide a customContextCache
implementation.- Since:
- 4.1
- Author:
- Sam Brannen
Constructor Summary
Constructors Constructor Description DefaultCacheAwareContextLoaderDelegate()
Construct a newDefaultCacheAwareContextLoaderDelegate
using a staticDefaultContextCache
.DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)
Construct a newDefaultCacheAwareContextLoaderDelegate
using the suppliedContextCache
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode)
Remove the application context for the suppliedMergedContextConfiguration
from theContextCache
and close it if it is an instance ofConfigurableApplicationContext
.protected ContextCache
getContextCache()
Get theContextCache
used by this context loader delegate.ApplicationContext
loadContext(MergedContextConfiguration mergedContextConfiguration)
Load the application context for the suppliedMergedContextConfiguration
by delegating to theContextLoader
configured in the givenMergedContextConfiguration
.protected ApplicationContext
loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
Load theApplicationContext
for the supplied merged context configuration.
Constructor Detail
DefaultCacheAwareContextLoaderDelegate
public DefaultCacheAwareContextLoaderDelegate()
Construct a newDefaultCacheAwareContextLoaderDelegate
using 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 newDefaultCacheAwareContextLoaderDelegate
using the suppliedContextCache
.
Method Detail
getContextCache
protected ContextCache getContextCache()
Get theContextCache
used by this context loader delegate.
loadContextInternal
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration) throws Exception
Load theApplicationContext
for the supplied merged context configuration.Supports both the
SmartContextLoader
andContextLoader
SPIs.- Throws:
Exception
- if an error occurs while loading the application context
loadContext
public ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration)
Description copied from interface:CacheAwareContextLoaderDelegate
Load the application context for the suppliedMergedContextConfiguration
by delegating to theContextLoader
configured in the givenMergedContextConfiguration
.If the context is present in the
ContextCache
it 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:
loadContext
in 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:CacheAwareContextLoaderDelegate
Remove the application context for the suppliedMergedContextConfiguration
from theContextCache
and close it if it is an instance ofConfigurableApplicationContext
.The semantics of the supplied
HierarchyMode
must be honored when removing the context from the cache. See the Javadoc forDirtiesContext.HierarchyMode
for 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:
closeContext
in interfaceCacheAwareContextLoaderDelegate
- Parameters:
mergedContextConfiguration
- the merged context configuration for the application context to close; nevernull
hierarchyMode
- the hierarchy mode; may benull
if the context is not part of a hierarchy