org.kuali.rice.test
Class RiceTestCase

java.lang.Object
  extended by org.kuali.rice.test.BaseRiceTestCase
      extended by org.kuali.rice.test.RiceTestCase
All Implemented Interfaces:
MethodAware
Direct Known Subclasses:
RiceInternalSuiteDataTestCase

public abstract class RiceTestCase
extends BaseRiceTestCase

Useful superclass for all Rice test cases. Handles setup of test utilities and a test environment. Configures the Spring test environment providing a template method for custom context files in test mode. Also provides a template method for running custom transactional setUp. Tear down handles automatic tear down of objects created inside the test environment.

Since:
0.9
Author:
Kuali Rice Team (rice.collab@kuali.org)

Field Summary
protected static String DEFAULT_TEST_HARNESS_SPRING_BEANS
           
protected static String failedSuiteTestName
           
protected static org.apache.log4j.Logger LOG
           
protected  List<Lifecycle> perTestLifeCycles
           
protected static boolean SUITE_LIFE_CYCLES_FAILED
           
protected static boolean SUITE_LIFE_CYCLES_RAN
           
protected  List<Lifecycle> suiteLifeCycles
           
 
Fields inherited from class org.kuali.rice.test.BaseRiceTestCase
log, method
 
Constructor Summary
RiceTestCase()
           
 
Method Summary
protected  void configureLogging()
          configures logging using custom properties file if specified, or the default one.
protected  String dumpMemory()
           
protected  String getBaseDir()
          Returns the basedir for the module under which the tests are currently executing.
protected  List<String> getConfigLocations()
          Subclasses may override this method to customize the location(s) of the Rice configuration.
protected  String getFullTestName()
           
protected  Lifecycle getLoadApplicationLifecycle()
          This should return a Lifecycle that can be used to load the application being tested.
protected abstract  String getModuleName()
          same as the module directory in the project.
protected  String getModuleTestConfigLocation()
           
protected  List<Lifecycle> getPerTestLifecycles()
           
protected  String getRiceMasterDefaultConfigFile()
           
protected  List<Lifecycle> getSuiteLifecycles()
          Returns the List of Lifecycles to start when the unit test suite is started
protected  Config getTestHarnessConfig()
           
protected  List<String> getTestHarnessSpringBeansLocation()
          Returns the location of the test harness spring beans context file.
 SpringResourceLoader getTestHarnessSpringResourceLoader()
           
protected  String getUserDir()
          the absolute path on the file system to the root folder of the maven module containing a child of this class e.g.
protected  void loadPerTestData()
          A method that can be overridden to load test data on a test-by-test basis
protected  void loadSuiteTestData()
          A method that can be overridden to load test data for the unit test Suite.
protected  void logAfterRun()
           
protected  void logBeforeRun()
           
protected  void report(String report)
           
protected  void setBaseDirSystemProperty(String moduleBaseDir)
          maven will set this property and find resources from the config based on it.
protected  void setClearTables(boolean clearTables)
           
protected  void setModuleName(String moduleName)
           
 void setUp()
           
protected  void setUpInternal()
          Internal setUp() implementation which is invoked by the main setUp() and wrapped with exception handling
protected  void startLifecycles(List<Lifecycle> lifecycles)
          Executes the start() method of each of the lifecycles in the given list.
protected  void startSuiteDataLoaderLifecycles()
          This block is walking up the class hierarchy of the current unit test looking for PerSuiteUnitTestData annotations.
protected  void stopLifecycles(List<Lifecycle> lifecycles)
          Executes the stop() method of each of the lifecyles in the given list.
 void tearDown()
           
 
Methods inherited from class org.kuali.rice.test.BaseRiceTestCase
getName, getPerTestDataLoaderLifecycle, resetLogLevels, setLogLevel, setName, setTestMethod
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final org.apache.log4j.Logger LOG

DEFAULT_TEST_HARNESS_SPRING_BEANS

protected static final String DEFAULT_TEST_HARNESS_SPRING_BEANS
See Also:
Constant Field Values

SUITE_LIFE_CYCLES_RAN

protected static boolean SUITE_LIFE_CYCLES_RAN

SUITE_LIFE_CYCLES_FAILED

protected static boolean SUITE_LIFE_CYCLES_FAILED

failedSuiteTestName

protected static String failedSuiteTestName

perTestLifeCycles

protected List<Lifecycle> perTestLifeCycles

suiteLifeCycles

protected List<Lifecycle> suiteLifeCycles
Constructor Detail

RiceTestCase

public RiceTestCase()
Method Detail

setUp

public void setUp()
           throws Exception
Overrides:
setUp in class BaseRiceTestCase
Throws:
Exception

setUpInternal

protected void setUpInternal()
                      throws Exception
Internal setUp() implementation which is invoked by the main setUp() and wrapped with exception handling

Subclasses should override this method if they want to add set up steps that should occur in the standard set up process, wrapped by exception handling.

Throws:
Exception

startSuiteDataLoaderLifecycles

protected void startSuiteDataLoaderLifecycles()
                                       throws Exception
This block is walking up the class hierarchy of the current unit test looking for PerSuiteUnitTestData annotations. If it finds one, it will run it once, then add it to a set so that it does not get run again. This is needed so that multiple tests can extend from the same suite and so that there can be multiple suites throughout the test source branch.

Throws:
Exception - if a PerSuiteDataLoaderLifecycle is unable to be started

setBaseDirSystemProperty

protected void setBaseDirSystemProperty(String moduleBaseDir)
maven will set this property and find resources from the config based on it. This makes eclipse testing work because we have to put the basedir in our config files in order to find things when testing from maven


getUserDir

protected String getUserDir()
the absolute path on the file system to the root folder of the maven module containing a child of this class e.g. for krad: [rice-project-dir]/it/krad

the user.dir property can be set on the CLI or IDE run configuration e.g. -Duser.dir=/some/dir

Returns:
the value of a system property 'user.dir' if it exists, null if not

getBaseDir

protected String getBaseDir()
Returns the basedir for the module under which the tests are currently executing.


setModuleName

protected void setModuleName(String moduleName)

tearDown

public void tearDown()
              throws Exception
Overrides:
tearDown in class BaseRiceTestCase
Throws:
Exception

logBeforeRun

protected void logBeforeRun()

logAfterRun

protected void logAfterRun()

getFullTestName

protected String getFullTestName()

configureLogging

protected void configureLogging()
                         throws IOException
configures logging using custom properties file if specified, or the default one. Log4j also uses any file called log4.properties in the classpath

To configure a custom logging file, set a JVM system property on using -D. For example -Dalt.log4j.config.location=file:/home/me/kuali/test/dev/log4j.properties

The above option can also be set in the run configuration for the unit test in the IDE. To avoid log4j using files called log4j.properties that are defined in the classpath, add the following system property: -Dlog4j.defaultInitOverride=true

Throws:
IOException

startLifecycles

protected void startLifecycles(List<Lifecycle> lifecycles)
                        throws Exception
Executes the start() method of each of the lifecycles in the given list.

Throws:
Exception

stopLifecycles

protected void stopLifecycles(List<Lifecycle> lifecycles)
                       throws Exception
Executes the stop() method of each of the lifecyles in the given list. The List of lifecycles is processed in reverse order.

Throws:
Exception

getSuiteLifecycles

protected List<Lifecycle> getSuiteLifecycles()
Returns the List of Lifecycles to start when the unit test suite is started


getLoadApplicationLifecycle

protected Lifecycle getLoadApplicationLifecycle()
This should return a Lifecycle that can be used to load the application being tested. For example, this could start a Jetty Server which loads the application, or load a Spring context to establish a set of services, or any other application startup activities that the test depends upon.


getPerTestLifecycles

protected List<Lifecycle> getPerTestLifecycles()
Returns:
Lifecycles run every test run

loadSuiteTestData

protected void loadSuiteTestData()
                          throws Exception
A method that can be overridden to load test data for the unit test Suite.

Throws:
Exception

loadPerTestData

protected void loadPerTestData()
                        throws Exception
A method that can be overridden to load test data on a test-by-test basis

Throws:
Exception

report

protected void report(String report)

dumpMemory

protected String dumpMemory()

getTestHarnessSpringResourceLoader

public SpringResourceLoader getTestHarnessSpringResourceLoader()

getTestHarnessSpringBeansLocation

protected List<String> getTestHarnessSpringBeansLocation()
Returns the location of the test harness spring beans context file. Subclasses may override to specify a different location.

Returns:
the location of the test harness spring beans context file.

getTestHarnessConfig

protected Config getTestHarnessConfig()
                               throws Exception
Throws:
Exception

getConfigLocations

protected List<String> getConfigLocations()
Subclasses may override this method to customize the location(s) of the Rice configuration. By default it is: classpath:META-INF/" + getModuleName().toLowerCase() + "-test-config.xml"

Returns:
List of config locations to add to this tests config location.

getModuleTestConfigLocation

protected String getModuleTestConfigLocation()

getRiceMasterDefaultConfigFile

protected String getRiceMasterDefaultConfigFile()

getModuleName

protected abstract String getModuleName()
same as the module directory in the project.

Returns:
name of module that the tests located

setClearTables

protected void setClearTables(boolean clearTables)


Copyright © 2005-2013 The Kuali Foundation. All Rights Reserved.