AbstractJUnit4SpringContextTests
)@Deprecated public abstract class AbstractSpringContextTests extends ConditionalTestCase
Superclass for JUnit 3.8 test cases using Spring
ApplicationContexts
.
Maintains a static cache of contexts by key. This has significant performance benefit if initializing the context would take time. While initializing a Spring context itself is very quick, some beans in a context, such as a LocalSessionFactoryBean for working with Hibernate, may take some time to initialize. Hence it often makes sense to do that initializing once.
Any ApplicationContext created by this class will be asked to register a JVM shutdown hook for itself. Unless the context gets closed early, all context instances will be automatically closed on JVM shutdown. This allows for freeing external resources held by beans within the context, e.g. temporary files.
Normally you won't extend this class directly but rather one of its subclasses.
AbstractSingleSpringContextTests
,
AbstractDependencyInjectionSpringContextTests
,
AbstractTransactionalSpringContextTests
,
AbstractTransactionalDataSourceSpringContextTests
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,ConfigurableApplicationContext> |
contextKeyToContextMap
Deprecated.
Map of context keys returned by subclasses of this class, to Spring
contexts.
|
logger
Constructor and Description |
---|
AbstractSpringContextTests()
Deprecated.
Default constructor for AbstractSpringContextTests.
|
AbstractSpringContextTests(java.lang.String name)
Deprecated.
Constructor for AbstractSpringContextTests with a JUnit name.
|
Modifier and Type | Method and Description |
---|---|
void |
addContext(java.lang.Object key,
ConfigurableApplicationContext context)
Deprecated.
Explicitly add an ApplicationContext instance under a given key.
|
protected java.lang.String |
contextKeyString(java.lang.Object contextKey)
Deprecated.
Subclasses can override this to return a String representation of their
context key for use in caching and logging.
|
protected ConfigurableApplicationContext |
getContext(java.lang.Object key)
Deprecated.
Obtain an ApplicationContext for the given key, potentially cached.
|
protected boolean |
hasCachedContext(java.lang.Object key)
Deprecated.
Return whether there is a cached context for the given key.
|
protected boolean |
isContextKeyEmpty(java.lang.Object key)
Deprecated.
Determine if the supplied context
key is empty. |
protected abstract ConfigurableApplicationContext |
loadContext(java.lang.Object key)
Deprecated.
Load a new ApplicationContext for the given key.
|
protected void |
setDirty(java.lang.Object contextKey)
Deprecated.
Mark the context with the given key as dirty.
|
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare
private static java.util.Map<java.lang.String,ConfigurableApplicationContext> contextKeyToContextMap
public AbstractSpringContextTests()
public AbstractSpringContextTests(java.lang.String name)
public final void addContext(java.lang.Object key, ConfigurableApplicationContext context)
This is not meant to be used by subclasses. It is rather exposed for special test suite environments.
key
- the context keycontext
- the ApplicationContext instanceprotected final boolean hasCachedContext(java.lang.Object key)
key
- the context keyprotected boolean isContextKeyEmpty(java.lang.Object key)
key
is empty.
By default, null
values, empty strings, and zero-length
arrays are considered empty.
key
- the context key to checktrue
if the supplied context key is emptyprotected final ConfigurableApplicationContext getContext(java.lang.Object key) throws java.lang.Exception
key
- the context key; may be null
.null
if the provided key
is emptyjava.lang.Exception
protected final void setDirty(java.lang.Object contextKey)
Call this method only if you change the state of a singleton bean, potentially affecting future tests.
protected java.lang.String contextKeyString(java.lang.Object contextKey)
contextKey
- the context keyprotected abstract ConfigurableApplicationContext loadContext(java.lang.Object key) throws java.lang.Exception
To be implemented by subclasses.
key
- the context keyjava.lang.Exception