atg.test
Class AtgDustCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by atg.test.AtgDustCase
All Implemented Interfaces:
junit.framework.Test

public class AtgDustCase
extends junit.framework.TestCase

Replacement base class for AtgDustTestCase. Extend this class and use the following 'pattern' whenever you want to junit test some atg components:

Repository based tests are depended on one of the two steps previously described plus: If you need to generate some components "on the fly":

Example usage can be found in test.SongsRepositoryTest.

This class overrides Junit 3 and not Junit 4 because currently Junit 4 has some test runner/eclipse related bugs which makes it impossible for me to use it.

Author:
robert

Field Summary
static java.io.File GLOBAL_FORCE_SER
           
static java.io.File TIMESTAMP_SER
           
 
Constructor Summary
AtgDustCase()
           
 
Method Summary
protected  void copyConfigurationFiles(java.lang.String[] srcDirs, java.lang.String dstDir, java.lang.String... excludes)
          Every *.properties file copied using this method will have it's scope (if one is available) set to global.
protected  void createPropertyFile(java.lang.String configurationStagingLocation, java.lang.String nucleusComponentPath, java.lang.Class<?> clazz)
           
protected  void manageConfigurationFiles(java.util.Properties properties)
          Donated by Remi Dupuis
protected  void prepareRepository(java.lang.String repositoryPath, java.util.Properties connectionProperties, boolean dropTables, boolean createTables, java.lang.String... definitionFiles)
          Prepares a test against an existing database.
protected  void prepareRepository(java.lang.String repoPath, java.lang.String... definitionFiles)
          Prepares a test against an default in-memory hsql database.
protected  java.lang.Object resolveNucleusComponent(java.lang.String nucleusComponentPath)
          Method for retrieving a fully injected atg component
protected  void setConfigurationLocation(java.lang.String configurationLocation)
          Call this method to set the configuration location.
protected  void setDebug(boolean isDebug)
          Enables or disables the debug level of nucleus components.
protected  void tearDown()
          Always make sure to call this because it will do necessary clean up actions (shutting down in-memory database (if it was used) and the nucleus) so he next test can run safely.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, 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, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIMESTAMP_SER

public static final java.io.File TIMESTAMP_SER

GLOBAL_FORCE_SER

public static final java.io.File GLOBAL_FORCE_SER
Constructor Detail

AtgDustCase

public AtgDustCase()
Method Detail

copyConfigurationFiles

protected final void copyConfigurationFiles(java.lang.String[] srcDirs,
                                            java.lang.String dstDir,
                                            java.lang.String... excludes)
                                     throws java.io.IOException
Every *.properties file copied using this method will have it's scope (if one is available) set to global.

Parameters:
srcDirs - One or more directories containing needed configuration files.
dstDir - where to copy the above files to. This will also be the configuration location.
excludes - One or more directories not to include during the copy process. Use this one to speeds up the test cycle considerably. You can also call it with an empty String[] or null if nothing should be excluded
Throws:
java.io.IOException - Whenever some file related error's occur.

manageConfigurationFiles

protected final void manageConfigurationFiles(java.util.Properties properties)
                                       throws java.io.IOException
Donated by Remi Dupuis

Parameters:
properties -
Throws:
java.io.IOException

createPropertyFile

protected final void createPropertyFile(java.lang.String configurationStagingLocation,
                                        java.lang.String nucleusComponentPath,
                                        java.lang.Class<?> clazz)
                                 throws java.io.IOException
Parameters:
configurationStagingLocation - The location where the property file should be created. This will also set the configurationLocation.
nucleusComponentPath - Nucleus component path (e.g /Some/Service/Impl).
clazz - The Class implementing the nucleus component specified in previous argument.
Throws:
java.io.IOException - If we have some File related errors

prepareRepository

protected final void prepareRepository(java.lang.String repoPath,
                                       java.lang.String... definitionFiles)
                                throws java.sql.SQLException,
                                       java.io.IOException
Prepares a test against an default in-memory hsql database.

Parameters:
repoPath - the nucleus component path of the repository to be tested.
definitionFiles - one or more repository definition files.
Throws:
java.io.IOException - The moment we have some properties/configuration related error
java.sql.SQLException - Whenever there is a database related error

prepareRepository

protected final void prepareRepository(java.lang.String repositoryPath,
                                       java.util.Properties connectionProperties,
                                       boolean dropTables,
                                       boolean createTables,
                                       java.lang.String... definitionFiles)
                                throws java.sql.SQLException,
                                       java.io.IOException
Prepares a test against an existing database.

Parameters:
repositoryPath - The the repository to be tested, specified as nucleus component path.
connectionProperties - A Properties instance with the following values (in this example the properties are geared towards an mysql database):
 final Properties properties = new Properties();
 properties.put("driver", "com.mysql.jdbc.Driver");
 properties.put("url", "jdbc:mysql://localhost:3306/someDb");
 properties.put("user", "someUserName");
 properties.put("password", "somePassword");
 
dropTables - If true then existing tables will be dropped and re-created, if set to false the existing tables will be used.
createTables - if set to true all non existing tables needed for the current test run will be created, if set to false this class expects all needed tables for this test run to be already created
definitionFiles - One or more needed repository definition files.
Throws:
java.io.IOException - The moment we have some properties/configuration related error
java.sql.SQLException - Whenever there is a database related error

resolveNucleusComponent

protected java.lang.Object resolveNucleusComponent(java.lang.String nucleusComponentPath)
                                            throws java.io.IOException
Method for retrieving a fully injected atg component

Parameters:
nucleusComponentPath - Path to a nucleus component (e.g. /Some/Service/Impl).
Returns:
Fully injected instance of the component registered under previous argument or null if there is an error.
Throws:
java.io.IOException

setConfigurationLocation

protected final void setConfigurationLocation(java.lang.String configurationLocation)
Call this method to set the configuration location.

Parameters:
configurationLocation - The configuration location to set. Most of the time this location is a directory containing all repository definition files and component property files which are needed for the test.

tearDown

protected void tearDown()
                 throws java.lang.Exception
Always make sure to call this because it will do necessary clean up actions (shutting down in-memory database (if it was used) and the nucleus) so he next test can run safely.

Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception

setDebug

protected void setDebug(boolean isDebug)
Enables or disables the debug level of nucleus components.

Parameters:
isDebug - Setting this to true will enable debug on all (currently only on repository related) components, setting it to false turn's the debug off again.


Copyright © 2009. All Rights Reserved.