Class AbstractDataRushTestCase

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 Details

    • AUSTIN_TIMEZONE

      protected static final TimeZone AUSTIN_TIMEZONE
      A TimeZone object indicating the time zone for Austin, Texas, USA.
  • Constructor Details

    • AbstractDataRushTestCase

      public AbstractDataRushTestCase()
  • Method Details

    • getLogger

      protected org.apache.logging.log4j.Logger 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 by AbstractDataRushTestCase#getLogger(). If testName 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. A resourceName 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. A resourceName 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. A fileName 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 as resourceAndScratchPropertyKeys.
      Parameters:
      propertiesPath - the path to the .properties. This path should be relative to the path provided by getResourcePath().
      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