org.springunit.framework
Class HierarchicalSpringUnitContext<S extends AbstractDependencyInjectionSpringContextTests>

java.lang.Object
  extended by org.springunit.framework.HierarchicalSpringUnitContext<S>

public class HierarchicalSpringUnitContext<S extends AbstractDependencyInjectionSpringContextTests>
extends Object

Manages the contexts of a SpringUnit test. Stores an ordered list of the classes that comprise the class hierarchy for the test (testClasses). The first element in the list is the class of the test, the last element is the descendent of the descendent of AbstractDependencyInjectionSpringContextTests or AbstractTransactionalSpringContextTests that is an ancestor of the test class.
Using the list of classes in the hierarchy, creates and provides a corresponding list of resources that describe configuration data used to populate the corresponding contexts.
Given a name for a data value, a name of a test and the test object itself, traverses the hierarchy of contexts to return the requested data value, if it exists.

Author:
Ted Velkoff

Constructor Summary
protected HierarchicalSpringUnitContext(Class<? extends S> testClass)
          Given the class of the current test (testClass), construct an ordered list of classes, where the first class is testClass, the second class is the superclass of testClass (if any), the third class is the superclass of the second (if any), etc., and the last class is the immediate descendent of the immediate descendent of AbstractDependencyInjectionSpringContextTests or AbstractTransactionalSpringContextTests.
 
Method Summary
protected  String[] getConfigLocations()
          Given the list of test classes in the hierarchy, return the list of resource names that satisfy the naming convention "Classname.xml".
Caches the list of locations so this need only be computed once.
protected
<T> T
getObject(String key, String fName, Object test)
          Search for object identified by key in the hierarchy of classes descending from the descendent of AbstractDependencyInjectionSpringContextTests or AbstractTransactionalSpringContextTests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HierarchicalSpringUnitContext

protected HierarchicalSpringUnitContext(Class<? extends S> testClass)
Given the class of the current test (testClass), construct an ordered list of classes, where the first class is testClass, the second class is the superclass of testClass (if any), the third class is the superclass of the second (if any), etc., and the last class is the immediate descendent of the immediate descendent of AbstractDependencyInjectionSpringContextTests or AbstractTransactionalSpringContextTests.

Parameters:
testClass - Class of test whose class hierarchy is to be constructed.
Method Detail

getConfigLocations

protected String[] getConfigLocations()
Given the list of test classes in the hierarchy, return the list of resource names that satisfy the naming convention "Classname.xml".
Caches the list of locations so this need only be computed once.

Returns:
Array of string filenames

getObject

protected <T> T getObject(String key,
                          String fName,
                          Object test)
               throws Exception
Search for object identified by key in the hierarchy of classes descending from the descendent of AbstractDependencyInjectionSpringContextTests or AbstractTransactionalSpringContextTests. This hierarchy is expressed as a list (testClasses) with lowest first and highest last. Iterates through this list, calling getObject(key, getName(), c) until a non-null result is returned or every member of the list has been visited.

Parameters:
key - Identifier of data value to find
fName - Name of test
test - SpringUnit test whose context will be searched
Returns:
Object of type T if found or null
Throws:
Exception - if errors occur when using reflection to access the SpringUnitContext for any class in the list


Copyright © 2007 null. All Rights Reserved.