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
logger
Constructor and Description |
---|
AbstractSpringContextTests()
Deprecated.
Default constructor for AbstractSpringContextTests.
|
AbstractSpringContextTests(String name)
Deprecated.
Constructor for AbstractSpringContextTests with a JUnit name.
|
Modifier and Type | Method and Description |
---|---|
void |
addContext(Object key,
ConfigurableApplicationContext context)
Deprecated.
Explicitly add an ApplicationContext instance under a given key.
|
protected String |
contextKeyString(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(Object key)
Deprecated.
Obtain an ApplicationContext for the given key, potentially cached.
|
protected boolean |
hasCachedContext(Object key)
Deprecated.
Return whether there is a cached context for the given key.
|
protected boolean |
isContextKeyEmpty(Object key)
Deprecated.
Determine if the supplied context
key is empty. |
protected abstract ConfigurableApplicationContext |
loadContext(Object key)
Deprecated.
Load a new ApplicationContext for the given key.
|
protected void |
setDirty(Object contextKey)
Deprecated.
Mark the context with the given key as dirty.
|
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, tearDown, toString
public AbstractSpringContextTests()
public AbstractSpringContextTests(String name)
public final void addContext(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(Object key)
key
- the context keyprotected boolean isContextKeyEmpty(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(Object key) throws Exception
key
- the context key; may be null
.null
if the provided key
is emptyException
protected final void setDirty(Object contextKey)
Call this method only if you change the state of a singleton bean, potentially affecting future tests.
protected String contextKeyString(Object contextKey)
contextKey
- the context keyprotected abstract ConfigurableApplicationContext loadContext(Object key) throws Exception
To be implemented by subclasses.
key
- the context keyException