|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.core.AttributeAccessorSupport
org.springframework.test.context.TestContext
public class TestContext
TestContext encapsulates the context in which a test is executed, agnostic of the actual testing framework in use.
| Field Summary | |
|---|---|
private ContextCache |
contextCache
|
private ContextLoader |
contextLoader
|
private java.lang.String[] |
locations
|
private static Log |
logger
|
private static long |
serialVersionUID
|
private static java.lang.String |
STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME
|
private java.lang.Class<?> |
testClass
|
private java.lang.Throwable |
testException
|
private java.lang.Object |
testInstance
|
private java.lang.reflect.Method |
testMethod
|
| Constructor Summary | |
|---|---|
TestContext(java.lang.Class<?> testClass,
ContextCache contextCache)
Delegates to TestContext(Class, ContextCache, String) with a
value of null for the default ContextLoader
class name. |
|
TestContext(java.lang.Class<?> testClass,
ContextCache contextCache,
java.lang.String defaultContextLoaderClassName)
Construct a new test context for the supplied test class
and context cache and parse the corresponding
@ContextConfiguration annotation, if
present. |
|
| Method Summary | |
|---|---|
private java.lang.String |
contextKeyString(java.io.Serializable key)
Convert the supplied context key to a String representation
for use in caching, logging, etc. |
ApplicationContext |
getApplicationContext()
Get the application context for this test
context, possibly cached. |
java.lang.Class<?> |
getTestClass()
Get the test class for this test context. |
java.lang.Throwable |
getTestException()
Get the exception that was thrown during execution of
the test method. |
java.lang.Object |
getTestInstance()
Get the current test instance for this test context. |
java.lang.reflect.Method |
getTestMethod()
Get the current test method for this test context. |
private ApplicationContext |
loadApplicationContext()
Load an ApplicationContext for this test context using the
configured ContextLoader and resource locations. |
void |
markApplicationContextDirty()
Call this method to signal that the application
context associated with this test context is dirty and should
be reloaded. |
private java.lang.Class<? extends ContextLoader> |
retrieveContextLoaderClass(java.lang.Class<?> clazz,
java.lang.String defaultContextLoaderClassName)
Retrieve the ContextLoader Class to use for the supplied
test class. |
private java.lang.String[] |
retrieveContextLocations(ContextLoader contextLoader,
java.lang.Class<?> clazz)
Retrieve ApplicationContext resource locations for the supplied
class, using the supplied ContextLoader to
process the
locations. |
java.lang.String |
toString()
Provide a String representation of this test context's state. |
(package private) void |
updateState(java.lang.Object testInstance,
java.lang.reflect.Method testMethod,
java.lang.Throwable testException)
Update this test context to reflect the state of the currently executing test. |
| Methods inherited from class org.springframework.core.AttributeAccessorSupport |
|---|
attributeNames, copyAttributesFrom, equals, getAttribute, hasAttribute, hashCode, removeAttribute, setAttribute |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final long serialVersionUID
private static final java.lang.String STANDARD_DEFAULT_CONTEXT_LOADER_CLASS_NAME
private static final Log logger
private final ContextCache contextCache
private final ContextLoader contextLoader
private final java.lang.String[] locations
private final java.lang.Class<?> testClass
private java.lang.Object testInstance
private java.lang.reflect.Method testMethod
private java.lang.Throwable testException
| Constructor Detail |
|---|
TestContext(java.lang.Class<?> testClass,
ContextCache contextCache)
TestContext(Class, ContextCache, String) with a
value of null for the default ContextLoader
class name.
TestContext(java.lang.Class<?> testClass,
ContextCache contextCache,
java.lang.String defaultContextLoaderClassName)
test class
and context cache and parse the corresponding
@ContextConfiguration annotation, if
present.
If the supplied class name for the default ContextLoader is
null or empty and no ContextLoader
class is explicitly supplied via the
@ContextConfiguration annotation, a
GenericXmlContextLoader will be used instead.
testClass - the test class for which the test context should be
constructed (must not be null)contextCache - the context cache from which the constructed test
context should retrieve application contexts (must not be
null)defaultContextLoaderClassName - the name of the default
ContextLoader class to use (may be null)| Method Detail |
|---|
private java.lang.Class<? extends ContextLoader> retrieveContextLoaderClass(java.lang.Class<?> clazz,
java.lang.String defaultContextLoaderClassName)
Retrieve the ContextLoader Class to use for the supplied
test class.
loader attribute of
@ContextConfiguration is configured
with an explicit class, that class will be returned.loader class is not specified, the class hierarchy
will be traversed to find a parent class annotated with
@ContextConfiguration; go to step #1.loader class is found after traversing
the class hierarchy, an attempt will be made to load and return the class
with the supplied defaultContextLoaderClassName.
clazz - the class for which to retrieve ContextLoader
class; must not be nulldefaultContextLoaderClassName - the name of the default
ContextLoader class to use; must not be null or
empty
ContextLoader class to use for the specified
class
java.lang.IllegalArgumentException - if @ContextConfiguration is not present on the supplied class
private java.lang.String[] retrieveContextLocations(ContextLoader contextLoader,
java.lang.Class<?> clazz)
ApplicationContext resource locations for the supplied
class, using the supplied ContextLoader to
process the
locations.
Note that the inheritLocations flag of @ContextConfiguration will be taken into consideration.
Specifically, if the inheritLocations flag is set to
true, locations defined in the annotated class will be
appended to the locations defined in superclasses.
contextLoader - the ContextLoader to use for processing the
locations (must not be null)clazz - the class for which to retrieve the resource locations (must
not be null)
java.lang.IllegalArgumentException - if @ContextConfiguration is not present on the supplied class
private ApplicationContext loadApplicationContext()
throws java.lang.Exception
ApplicationContext for this test context using the
configured ContextLoader and resource locations.
java.lang.Exception - if an error occurs while loading the application
contextprivate java.lang.String contextKeyString(java.io.Serializable key)
key to a String representation
for use in caching, logging, etc.
public ApplicationContext getApplicationContext()
application context for this test
context, possibly cached.
java.lang.IllegalStateException - if an error occurs while retrieving the
application contextpublic final java.lang.Class<?> getTestClass()
test class for this test context.
null)public final java.lang.Object getTestInstance()
test instance for this test context.
Note: this is a mutable property.
null)updateState(Object,Method,Throwable)public final java.lang.reflect.Method getTestMethod()
test method for this test context.
Note: this is a mutable property.
null)updateState(Object, Method, Throwable)public final java.lang.Throwable getTestException()
exception that was thrown during execution of
the test method.
Note: this is a mutable property.
null if no
exception was thrownupdateState(Object, Method, Throwable)public void markApplicationContextDirty()
application
context associated with this test context is dirty and should
be reloaded. Do this if a test has modified the context (for example, by
replacing a bean definition).
void updateState(java.lang.Object testInstance,
java.lang.reflect.Method testMethod,
java.lang.Throwable testException)
testInstance - the current test instance (may be null)testMethod - the current test method (may be null)testException - the exception that was thrown in the test method, or
null if no exception was thrownpublic java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||