|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.springframework.test.ConditionalTestCase
org.springframework.test.AbstractSpringContextTests
org.springframework.test.AbstractSingleSpringContextTests
public abstract class AbstractSingleSpringContextTests
Abstract test class that holds and exposes a single Spring ApplicationContext.
This class will cache contexts based on a context key:
normally the config locations String array describing the Spring resource
descriptors making up the context. Unless the setDirty()
method
is called by a test, the context will not be reloaded, even across different
subclasses of this test. This is particularly beneficial if your context is
slow to construct, for example if you are using Hibernate and the time taken
to load the mappings is an issue.
If you don't want this behavior, you can override the contextKey()
method, most likely to return the test class. In conjunction with this you would
probably override the getContext
method, which by default loads
the locations specified in the getConfigLocations()
method.
WARNING: When doing integration tests from within Eclipse, only use classpath resource URLs. Else, you may see misleading failures when changing context locations.
Field Summary | |
---|---|
protected ConfigurableApplicationContext |
applicationContext
Application context this test will run against |
Fields inherited from class org.springframework.test.ConditionalTestCase |
---|
logger |
Constructor Summary | |
---|---|
AbstractSingleSpringContextTests()
Default constructor for AbstractDependencyInjectionSpringContextTests. |
|
AbstractSingleSpringContextTests(String name)
Constructor for AbstractDependencyInjectionSpringContextTests with a JUnit name. |
Method Summary | |
---|---|
protected Object |
contextKey()
Return a key for this context. |
protected abstract String[] |
getConfigLocations()
Subclasses must implement this method to return the locations of their config files. |
int |
getLoadCount()
Return the current number of context load attempts. |
protected ConfigurableApplicationContext |
loadContext(Object key)
This implementation loads a context from the given String array. |
protected ConfigurableApplicationContext |
loadContextLocations(String[] locations)
Load an ApplicationContext from the given config locations. |
protected void |
onSetUp()
Subclasses can override this method in place of the setUp() method, which is final in this class. |
protected void |
onTearDown()
Subclasses can override this to add custom behavior on teardown. |
protected void |
prepareTestInstance()
Prepare this test instance, for example populating its fields. |
protected void |
setDirty()
Called to say that the "applicationContext" instance variable is dirty and should be reloaded. |
protected void |
setUp()
This implementation is final. |
protected void |
tearDown()
This implementation is final. |
Methods inherited from class org.springframework.test.AbstractSpringContextTests |
---|
addContext, contextKeyString, getContext, hasCachedContext, setDirty |
Methods inherited from class org.springframework.test.ConditionalTestCase |
---|
getDisabledTestCount, isDisabledInThisEnvironment, recordDisabled, runBare |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runTest, setName, 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 |
---|
protected ConfigurableApplicationContext applicationContext
Constructor Detail |
---|
public AbstractSingleSpringContextTests()
public AbstractSingleSpringContextTests(String name)
name
- the name of this text fixtureMethod Detail |
---|
protected final void setUp() throws Exception
onSetUp
for custom behavior.
setUp
in class TestCase
Exception
onSetUp()
protected void prepareTestInstance() throws Exception
This implementation does nothing.
Exception
protected void onSetUp() throws Exception
setUp()
method, which is final in this class.
This implementation does nothing.
Exception
- simply let any exception propagateprotected final void tearDown() throws Exception
onTearDown
for custom behavior.
tearDown
in class TestCase
Exception
onTearDown()
protected void onTearDown() throws Exception
Exception
- simply let any exception propagateprotected final Object contextKey()
getConfigLocations()
protected final ConfigurableApplicationContext loadContext(Object key) throws Exception
loadContext
in class AbstractSpringContextTests
key
- the context key
Exception
protected ConfigurableApplicationContext loadContextLocations(String[] locations) throws Exception
locations
- the config locations
Exception
public final int getLoadCount()
protected void setDirty()
protected abstract String[] getConfigLocations()
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |