org.springframework.test
Class AbstractSpringContextTests

java.lang.Object
  extended by TestCase
      extended by org.springframework.test.ConditionalTestCase
          extended by org.springframework.test.AbstractSpringContextTests
Direct Known Subclasses:
AbstractSingleSpringContextTests

Deprecated. as of Spring 3.0, in favor of using the listener-based test context framework (AbstractJUnit38SpringContextTests)

@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.

Since:
1.1.1
Author:
Rod Johnson, Juergen Hoeller, Sam Brannen
See Also:
AbstractSingleSpringContextTests, AbstractDependencyInjectionSpringContextTests, AbstractTransactionalSpringContextTests, AbstractTransactionalDataSourceSpringContextTests

Field Summary
private static java.util.Map<java.lang.String,ConfigurableApplicationContext> contextKeyToContextMap
          Deprecated. Map of context keys returned by subclasses of this class, to Spring contexts.
 
Fields inherited from class org.springframework.test.ConditionalTestCase
logger
 
Constructor Summary
AbstractSpringContextTests()
          Deprecated. Default constructor for AbstractSpringContextTests.
AbstractSpringContextTests(java.lang.String name)
          Deprecated. Constructor for AbstractSpringContextTests with a JUnit name.
 
Method Summary
 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.
 
Methods inherited from class org.springframework.test.ConditionalTestCase
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contextKeyToContextMap

private static java.util.Map<java.lang.String,ConfigurableApplicationContext> contextKeyToContextMap
Deprecated. 
Map of context keys returned by subclasses of this class, to Spring contexts. This needs to be static, as JUnit tests are destroyed and recreated between running individual test methods.

Constructor Detail

AbstractSpringContextTests

public AbstractSpringContextTests()
Deprecated. 
Default constructor for AbstractSpringContextTests.


AbstractSpringContextTests

public AbstractSpringContextTests(java.lang.String name)
Deprecated. 
Constructor for AbstractSpringContextTests with a JUnit name.

Method Detail

addContext

public final void addContext(java.lang.Object key,
                             ConfigurableApplicationContext context)
Deprecated. 
Explicitly add an ApplicationContext instance under a given key.

This is not meant to be used by subclasses. It is rather exposed for special test suite environments.

Parameters:
key - the context key
context - the ApplicationContext instance

hasCachedContext

protected final boolean hasCachedContext(java.lang.Object key)
Deprecated. 
Return whether there is a cached context for the given key.

Parameters:
key - the context key

isContextKeyEmpty

protected boolean isContextKeyEmpty(java.lang.Object key)
Deprecated. 
Determine if the supplied context key is empty.

By default, null values, empty strings, and zero-length arrays are considered empty.

Parameters:
key - the context key to check
Returns:
true if the supplied context key is empty

getContext

protected final ConfigurableApplicationContext getContext(java.lang.Object key)
                                                   throws java.lang.Exception
Deprecated. 
Obtain an ApplicationContext for the given key, potentially cached.

Parameters:
key - the context key; may be null.
Returns:
the corresponding ApplicationContext instance (potentially cached), or null if the provided key is empty
Throws:
java.lang.Exception

setDirty

protected final void setDirty(java.lang.Object contextKey)
Deprecated. 
Mark the context with the given key as dirty. This will cause the cached context to be reloaded before the next test case is executed.

Call this method only if you change the state of a singleton bean, potentially affecting future tests.


contextKeyString

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.

Parameters:
contextKey - the context key

loadContext

protected abstract ConfigurableApplicationContext loadContext(java.lang.Object key)
                                                       throws java.lang.Exception
Deprecated. 
Load a new ApplicationContext for the given key.

To be implemented by subclasses.

Parameters:
key - the context key
Returns:
the corresponding ApplicationContext instance (new)
Throws:
java.lang.Exception