- java.lang.Object
-
- com.pervasive.datarush.test.AbstractDataRushTestCase
-
- Direct Known Subclasses:
AbstractOperatorTestCase
public abstract class AbstractDataRushTestCase extends Object
Base class for DataRush operator and application unit tests. This class provides convenience methods for getting resource and scratch file paths, and generating application arguments, among other things.
-
-
Field Summary
Fields Modifier and Type Field Description protected static TimeZone
AUSTIN_TIMEZONE
ATimeZone
object indicating the time zone for Austin, Texas, USA.
-
Constructor Summary
Constructors Constructor Description AbstractDataRushTestCase()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
cleanScratchDirectory()
Deletes the scratch directory for the test.protected File
createScratchDirectory()
Creates the scratch directory for the test.protected File
createScratchDirectory(String fileName)
Creates a scratch directory with the given name beneath the test's scratch directory.protected String[]
getArgs(String propertiesPath, String... resourceAndScratchPropertyKeys)
Generates an array of arguments to be fed to a DataRush application's main method.protected org.apache.commons.logging.Log
getLogger()
Gets the logger for this test.protected String
getResourcePath()
Gets the path to the directory containing resources for this test.protected static String
getResourcePath(Class<?> testClass)
Gets the path to the resource directory of the given class.protected static String
getResourcePath(Class<?> testClass, String resourceName)
Gets the file path to a specified resource for the given class.protected String
getResourcePath(String resourceName)
Gets the file path to a specified resource.protected String
getScratchPath()
Gets the path to the scratch directory for this test.protected String
getScratchPath(String fileName)
Gets the file path to a specified scratch file.protected String[]
getScriptArgs(String scriptFile)
Create arguments for drunner allowing a script to be run that has embedded$0
and$1
references.protected long
getSeed()
Generates a seed for the current test.protected long
getSeed(String testName)
Generates a seed for the current test and outputs that seed to the logger provided byAbstractDataRushTestCase#getLogger()
.
-
-
-
Method Detail
-
getLogger
protected org.apache.commons.logging.Log getLogger()
Gets the logger for this test.- Returns:
- the logger for this test
-
getSeed
protected long getSeed()
Generates a seed for the current test.This method is equivalent to
getSeed(null)
.- Returns:
- the generated seed
-
getSeed
protected long getSeed(String testName)
Generates a seed for the current test and outputs that seed to the logger provided byAbstractDataRushTestCase#getLogger()
. IftestName
is null, no log message will be output.- Parameters:
testName
- the test name to include in the log message- Returns:
- the generated seed
-
getResourcePath
protected static String getResourcePath(Class<?> testClass)
Gets the path to the resource directory of the given class.- Parameters:
testClass
- test class to use as basis for the resource path- Returns:
- the file path to the specified resource
-
getResourcePath
protected String getResourcePath(String resourceName)
Gets the file path to a specified resource. AresourceName
of null will return the path to the directory containing the resources for this test.- Parameters:
resourceName
- the resource for which to retrieve the path- Returns:
- the file path to the specified resource
-
getResourcePath
protected static String getResourcePath(Class<?> testClass, String resourceName)
Gets the file path to a specified resource for the given class. AresourceName
of null will return the path to the directory containing the resources for the given class.- Parameters:
resourceName
- the resource for which to retrieve the path- Returns:
- the file path to the specified resource
-
getResourcePath
protected String getResourcePath()
Gets the path to the directory containing resources for this test.This method is equivalent to
getResourcePath(null)
.- Returns:
- the path to the directory containing resources for this test
-
getScratchPath
protected String getScratchPath(String fileName)
Gets the file path to a specified scratch file. AfileName
of null will return the path to the scratch directory for this test.- Parameters:
fileName
- the scratch file for which to get the path- Returns:
- the file path to the specified scratch file
-
getScratchPath
protected String getScratchPath()
Gets the path to the scratch directory for this test.This method is equivalent to
getScratchPath(null)
.- Returns:
- the path to the scratch directory for this test
-
createScratchDirectory
protected File createScratchDirectory(String fileName)
Creates a scratch directory with the given name beneath the test's scratch directory.- Parameters:
fileName
- the directory to create- Returns:
- the path to the scratch directory
-
createScratchDirectory
protected File createScratchDirectory()
Creates the scratch directory for the test.- Returns:
- the path to the scratch directory
-
cleanScratchDirectory
protected boolean cleanScratchDirectory()
Deletes the scratch directory for the test.- Returns:
- true if the scratch directory and all contents are deleted successfully
-
getArgs
protected String[] getArgs(String propertiesPath, String... resourceAndScratchPropertyKeys)
Generates an array of arguments to be fed to a DataRush application's main method. This method accepts a path to a .properties file and an array of keys in the file which map to file path format strings (in which{0}
denotes the resource file directory and{1}
denotes the scratch file directory). The specified .properties file and keys are used to create a new .properties file in the scratch directory, similar to the original, but having the values of the specified keys formatted to contain the actual resource and scratch file paths. The function returns an array of application arguments pointing to this new file.As an example, an input file containing:
inputPath={0}/in.txt filterThreshold=23 outputPath={1}/results.txt
would result in new file containing:inputPath=/myproject/src/test/resources/com/foo/bar/in.txt filterThreshold=23 outputPath=/myproject/target/scratch/com/foo/bar/results.txt
if both "inputPath" and "outputPath" were provided asresourceAndScratchPropertyKeys
.- Parameters:
propertiesPath
- the path to the.properties
. This path should be relative to the path provided bygetResourcePath()
.resourceAndScratchPropertyKeys
- the array of keys mapping to file path format strings- Returns:
- an array of arguments to be fed to a DataRush application's main method
-
getScriptArgs
protected String[] getScriptArgs(String scriptFile)
Create arguments for drunner allowing a script to be run that has embedded$0
and$1
references. The$0
variable is resolved to the resource path and the$1
variable is resolved to the scratch path.The script file will be resolved to the resource path, so no need to call
getResourcePath()
before invoking this method.- Parameters:
scriptFile
- name of the script file- Returns:
- the resulting argument list
-
-