org.springframework.test
Class AbstractSpringContextTests

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.springframework.test.AbstractSpringContextTests
All Implemented Interfaces:
Test
Direct Known Subclasses:
AbstractDependencyInjectionSpringContextTests

public abstract class AbstractSpringContextTests
extends TestCase

Superclass for JUnit test cases using a Spring context.

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 time to initialize. Hence it often makes sense to do that initializing once.

Normally you won't extend this class directly, but extend one of its subclasses.

Since:
1.1.1
Author:
Rod Johnson
See Also:
AbstractDependencyInjectionSpringContextTests, AbstractTransactionalSpringContextTests, AbstractTransactionalDataSourceSpringContextTests

Field Summary
protected  Log logger
          Logger available to subclasses.
 
Constructor Summary
AbstractSpringContextTests()
          Default constructor for AbstractSpringContextTests.
AbstractSpringContextTests(String name)
          Constructor for AbstractSpringContextTests with a JUnit name.
 
Method Summary
protected  String contextKeyString(Object contextKey)
          Subclasses can override this to return a String representation of their contextKey for use in logging
protected  ConfigurableApplicationContext getContext(Object key)
           
protected  boolean hasCachedContext(Object contextKey)
           
protected  ConfigurableApplicationContext loadContext(Object key)
           
protected  ConfigurableApplicationContext loadContextLocations(String[] locations)
          Subclasses can invoke this to get a context key for the given location.
protected  void setDirty(String[] locations)
          Set custom locations dirty.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
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, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Logger available to subclasses.

Constructor Detail

AbstractSpringContextTests

public AbstractSpringContextTests()
Default constructor for AbstractSpringContextTests.


AbstractSpringContextTests

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

Method Detail

setDirty

protected void setDirty(String[] locations)
Set custom locations dirty. This will cause them to be reloaded from the cache before the next test case is executed.

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


hasCachedContext

protected boolean hasCachedContext(Object contextKey)

contextKeyString

protected String contextKeyString(Object contextKey)
Subclasses can override this to return a String representation of their contextKey for use in logging


getContext

protected ConfigurableApplicationContext getContext(Object key)

loadContextLocations

protected ConfigurableApplicationContext loadContextLocations(String[] locations)
Subclasses can invoke this to get a context key for the given location. This doesn't affect the applicationContext instance variable in this class. Dependency Injection cannot be applied from such contexts.


loadContext

protected ConfigurableApplicationContext loadContext(Object key)


Copyright (c) 2002-2007 The Spring Framework Project.