com.zmicer.utils.junit
Class ZmicerTestUtils

java.lang.Object
  extended by com.zmicer.utils.junit.ZmicerTestUtils

public class ZmicerTestUtils
extends Object

This utility class contains functionality helping us in creating unit tests for the all kind of functionality where zmicer.utils could be used. For now it contains the 1. functionality for obtaining resources for testing classes 2. methods for working with JVM params - for settings the JVM params and then for restoring the default JVM params composition. todo [zmicer]: potentially this class would be the part of the framework allowing users to deal with the configuration for the unit tests easily. $Author:: zmicer $
$Rev:: 70 $
* $Date:: 2007-08-29 09:09:13 #$


Nested Class Summary
static interface ZmicerTestUtils.CommonTestCases
          Common test cases to be used.
 
Field Summary
static String JUST_METHOD_NAME
          Used below. please review the approptiate code.
static org.apache.log4j.Logger LOG
          Logger instance.
static String METHOD_NAME_FOLDER_PREFIX
          Used for the constructing the full name of the folder where the tests data for the concrete method of the concrete class is stored
static Map<String,Pattern> TEST_BASE_FOLDER_PATTERNS
          This storage is necessary for avoiding creating the patterns everytime - the method com.zmicer.utils.junit.ZmicerTestUtils#getFolderWithTestData() would put here the patterns and check if they are exist
Use com.zmicer.utils.junit.ZmicerTestUtils#clearPatterns() for cleaning the set of the patterns
static String TEST_DATA_FOLDER
          TEST_DATA_FOLDER string
static Pattern TEST_DATA_FOLDER_PATTERN
          The folder where the test data is stored.
 
Constructor Summary
ZmicerTestUtils()
           
 
Method Summary
static void clearPatterns()
          Clean the current set of the patterns used for the retrieving the full name to the folder with the data for tests
static String getFolderWithCommonTestData()
           
static String getFolderWithTestData()
          Please be noticed this method is a main one for the creating unit tests basing on the environment configuration.
static String getFolderWithTestData(String testDataFolderBaseName)
          Study the Java Doc to the method above placed.
static String getFullTestDataFileName(Class claz, boolean considerMethodName, String testCase, String fileName, boolean checkIfExists)
          Get the full file name using the provided data.
static String getFullTestDataFileName(String testCaseFolderName, String fileName)
          Get full file name using the test case folder and file name.
static String getFullTestDataFolderName(Class claz, boolean considerMethodName, String testCase, boolean checkIfExists)
          Get full folder name where test data for the provided class and for the certain test case is stored.
static String getFullTestDataFolderName(String testCaseFolderName)
          Get full folder name using the test case folder and file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

public static final org.apache.log4j.Logger LOG
Logger instance.


TEST_DATA_FOLDER

public static final String TEST_DATA_FOLDER
TEST_DATA_FOLDER string

See Also:
Constant Field Values

TEST_DATA_FOLDER_PATTERN

public static final Pattern TEST_DATA_FOLDER_PATTERN
The folder where the test data is stored.
note [zmicer]: take an attention - the folder could be "builderstestdata" etc. - but the folder base name should end with the "testdata" string.


TEST_BASE_FOLDER_PATTERNS

public static final Map<String,Pattern> TEST_BASE_FOLDER_PATTERNS
This storage is necessary for avoiding creating the patterns everytime - the method com.zmicer.utils.junit.ZmicerTestUtils#getFolderWithTestData() would put here the patterns and check if they are exist
Use com.zmicer.utils.junit.ZmicerTestUtils#clearPatterns() for cleaning the set of the patterns


METHOD_NAME_FOLDER_PREFIX

public static final String METHOD_NAME_FOLDER_PREFIX
Used for the constructing the full name of the folder where the tests data for the concrete method of the concrete class is stored

See Also:
Constant Field Values

JUST_METHOD_NAME

public static final String JUST_METHOD_NAME
Used below. please review the approptiate code.

See Also:
Constant Field Values
Constructor Detail

ZmicerTestUtils

public ZmicerTestUtils()
Method Detail

getFolderWithTestData

public static String getFolderWithTestData()
Please be noticed this method is a main one for the creating unit tests basing on the environment configuration. You should be sure before the using it that ZmicerTestUtils.TEST_DATA_FOLDER is set to the classpath. Otherwise this method would return null as it won't find the necessary folder.
First of all this method tries to get the test data folder value specified as the JVM parameter. Then if this parameter is not set it finds the test data folder using the pattern ZmicerTestUtils.TEST_DATA_FOLDER_PATTERN. For all the cases the check that this directory exists is performed.

Returns:
the folder name where the test data is stored. This would be the full folder name (depends on the file system). In the case it can not find the folder - IllegalArgumentException would be thrown.

getFolderWithCommonTestData

public static String getFolderWithCommonTestData()
Returns:
the path to the folder where common test data is stored: %test data folder% + File.separator + CommonTestCases.COMMON_PROPS

getFolderWithTestData

public static String getFolderWithTestData(String testDataFolderBaseName)
Study the Java Doc to the method above placed. This method allows to find the folder where the files for tetsing are placing using the base name specified by youself (on default the folder with the name "testdata" is used).

Parameters:
testDataFolderBaseName - the base name of the folder where test configurations/files and other stuff is stored. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
the folder name where the test data is stored. This would be the full folder name (depends on the file system).

getFullTestDataFolderName

public static String getFullTestDataFolderName(String testCaseFolderName)
Get full folder name using the test case folder and file name.

Parameters:
testCaseFolderName - test case folder name. Could be null.
Returns:
the full folder name. Can not be null (otherwise IllegalArgumentException would appear).

getFullTestDataFileName

public static String getFullTestDataFileName(String testCaseFolderName,
                                             String fileName)
Get full file name using the test case folder and file name.
com.zmicer.utils.FileUtilsTest.getFolderWithTestData() is used here.

Parameters:
testCaseFolderName - test case folder name. Could be null.
fileName - file name. Can not be null (otherwise IllegalArgumentException would appear).
Returns:
the full file name.

getFullTestDataFileName

public static String getFullTestDataFileName(Class claz,
                                             boolean considerMethodName,
                                             String testCase,
                                             String fileName,
                                             boolean checkIfExists)
Get the full file name using the provided data.

Parameters:
claz - class name should be used as the test case folder name. Can not be null (otherwise IllegalArgumentException would appear).
considerMethodName - says that we should construct the full file name using the assumption after the folder with test data for class there is folder with the tests data for the method running currenctly. naming convention is "method_%id%", %id% lis a name of the method currently running. It could be null. This param allows to organize the structures of folders for the testing in the structure: class base name folder/method name/test case/file name note [zmicer]: true should be set only for the test purposes (for JPatterns test engine allowing to setup the props/xml environment per the folders)
testCase - the test case for the certain class - the concept is: each classes could have lots of tests cases where the the different sets of configuration for the tests is stored. E.g. above mentioned ***\testdata\ZmicerTestUtilsTest could store folders "case1", "case2" etc. This param could be null. In that case we would consider the the root forlder (for ZmicerTestUtilsTest it is mentioned ***\testdata\ZmicerTestUtilsTest folder)
fileName - file name to be used Can not be null (otherwise IllegalArgumentException would appear).
checkIfExists - makes the check if resource is exists.
Returns:
the full file name.

getFullTestDataFolderName

public static String getFullTestDataFolderName(Class claz,
                                               boolean considerMethodName,
                                               String testCase,
                                               boolean checkIfExists)
Get full folder name where test data for the provided class and for the certain test case is stored.
This method is very important for the organizing test classes (when the covered functionality uses properties/xml etc. files for setting the configuration of the system).

Parameters:
claz - Class for which we would search for folder with the test data. In the case of ZmicerTestUtilsTest class this folder would be ***\testdata\ZmicerTestUtilsTest where *** is a file system specific path to the the test data folder where all the test data is stored. Can not be null (otherwise IllegalArgumentException would appear).
considerMethodName - says that we should construct the full file name using the assumption after the folder with test data for class there is folder with the tests data for the method running currenctly. naming convention is "method_%id%", %id% lis a name of the method currently running. It could be null. This param allows to organize the structures of folders for the testing in the structure: class base name folder/method name/test case/file name note [zmicer]: true should be set only for the test purposes (for JPatterns test engine allowing to setup the props/xml environment per the folders)
testCase - the test case for the certain class - the concept is: each classes could have lots of tests cases where the the different sets of configuration for the tests is stored. E.g. above mentioned ***\testdata\ZmicerTestUtilsTest could store folders "case1", "case2" etc. This param could be null. In that case we would consider the the root forlder (for ZmicerTestUtilsTest it is mentioned ***\testdata\ZmicerTestUtilsTest folder)
checkIfExists - makes the check if resource is exists.
Returns:
the full test data folder name.

clearPatterns

public static void clearPatterns()
Clean the current set of the patterns used for the retrieving the full name to the folder with the data for tests



Copyright © 2007 jzmicer.team. All Rights Reserved.