Class TestLoader

Object
TestLoader

public class TestLoader extends Object
Loads test data, which is found at some location on the filesystem.
Author:
Owen Feehan
  • Field Details

    • PATH_RESOURCES

      public static final String PATH_RESOURCES
      Path to the resources directory, relative to the root of the project.
      See Also:
  • Method Details

    • createFromMavenWorkingDirectory

      public static TestLoader createFromMavenWorkingDirectory()
      Creates a new test-data loader finding PATH_RESOURCES using the Maven working directory.
      Returns:
      a loader associated with MAVEN_WORKING_DIR/PATH_RESOURCES
    • createFromMavenWorkingDirectory

      public static TestLoader createFromMavenWorkingDirectory(String toAppendToDirectory)
      Creates a new test-data loader finding PATH_RESOURCES/PLUS_SOMETHING using the Maven working directory.
      Parameters:
      toAppendToDirectory - appended to Maven working directory to determine final directory.
      Returns:
      a loader associated with the MAVEN_WORKING_DIR/PATH_RESOURCES/PLUS_SOMETHING
    • createFromExplicitDirectory

      public static TestLoader createFromExplicitDirectory(String rootDirectory)
      Creates a new test-data loader using an explicit file path as root.
      Parameters:
      rootDirectory - the path where the root folder is.
      Returns:
      a loader associated with the explicit root.
    • createFromExplicitDirectory

      public static TestLoader createFromExplicitDirectory(Path rootDirectory)
      Creates a new test-data loader using an explicit file path as root.
      Parameters:
      rootDirectory - the path where the root folder is.
      Returns:
      a loader associated with the explicit root.
    • createForSubdirectory

      public TestLoader createForSubdirectory(String subdirectory)
      Creates a new test-loader for a subdirectory of the current test.
      Parameters:
      subdirectory - the subdirectory to use (relative path to the current root).
      Returns:
      the new test-loader
    • pathMavenWorkingDirectory

      public static Path pathMavenWorkingDirectory(String toAppendToDirectory)
      Determines the path to a directory inside the Maven Working Directory.

      It uses the pattern PATH_RESOURCES/PLUS_SOMETHING inside the Maven working directory.

      Parameters:
      toAppendToDirectory - appended to Maven working directory to determine final directory.
      Returns:
      the path to this directory on the file-system.
    • resolveTestPath

      public Path resolveTestPath(String testPath)
      Resolves a path to test-data (relative path to the test-data root) to an absolute path on the file system.
      Parameters:
      testPath - relative-path of a test-data item. It is relative to the test-data root.
      Returns:
      the resolved-path
    • doesPathExist

      public boolean doesPathExist(String testFilePath)
      Does a resource exist with a particular folderPath + fileName.
      Parameters:
      testFilePath - path to a file in the test-data.
      Returns:
      true if a file is found at the location, false otherwise.
    • doesPathExist

      public boolean doesPathExist(String testDirectoryPath, String fileName)
      Does a resource exist with a particular folderPath + fileName.
      Parameters:
      testDirectoryPath - path to a folder in the test-data (can be empty).
      fileName - a filename in the testDirectoryPath.
      Returns:
      true if a file is found at the location, false otherwise.
    • printAllFilesFromTestDirectoryPath

      public void printAllFilesFromTestDirectoryPath(String testDirectoryPath)
      Prints the names of all files (recursively) in a test-folder to stdout.
      Parameters:
      testDirectoryPath - path to a folder in the test-data (can be empty).
    • openXmlFromTestPath

      public Document openXmlFromTestPath(String testPath)
      Opens a XML document - with a path relative to the test root.
      Parameters:
      testPath - the path to the XML file (relative to the test root).
      Returns:
      the XML document.
    • openXmlAbsoluteFilePath

      public static Document openXmlAbsoluteFilePath(String filePath)
      Opens a XML document - with an absolute path on the filesystem.
      Parameters:
      filePath - the path to the XML file (absolute path).
      Returns:
      the XML document.
    • openXmlAbsoluteFilePath

      public static Document openXmlAbsoluteFilePath(Path filePath)
      Opens a XML document - with an absolute path on the filesystem.
      Parameters:
      filePath - the path to the XML file (absolute path).
      Returns:
      the XML document.
    • copyToDirectory

      public void copyToDirectory(File destination) throws IOException
      Copies all the data in the test-data folder (recursively), preserving file modification times.
      Parameters:
      destination - destination-folder.
      Throws:
      IOException - if a copy error occurs.
    • copyToDirectory

      public void copyToDirectory(String[] subdirectoriesSource, File directoryDestination) throws IOException
      Copies specific subdirectories from the test-data folder (recursively), preserving file modification times.
      Parameters:
      subdirectoriesSource - which subdirectories to copy from (their full-path is preserved).
      directoryDestination - destination-folder.
      Throws:
      IOException - if a copy error occurs.
    • getRoot

      public Path getRoot()
      Path to where the test-data is stored.