Interface Testing.Files

  • Enclosing interface:
    Testing

    public static interface Testing.Files
    File system utility methods.
    • Method Detail

      • determineTestDataDir

        static String determineTestDataDir()
      • readResourceAsStream

        static InputStream readResourceAsStream​(String pathOnClasspath,
                                                Class<?> testClass)
        Obtain an InputStream to a named resource on the given classpath.
        Parameters:
        pathOnClasspath - the path of the resource on the classpath
        testClass - the test class, used for accessing the class loader
        Returns:
        the string representation
      • readResourceAsStream

        static InputStream readResourceAsStream​(String pathOnClasspath)
        Obtain an InputStream to a named resource on the classpath used to load this Testing class.
        Parameters:
        pathOnClasspath - the path of the resource on the classpath
        Returns:
        the string representation
      • readResourceAsString

        static String readResourceAsString​(String pathOnClasspath)
        Read a classpath resource into a string.
        Parameters:
        pathOnClasspath - the path of the resource on the classpath
        Returns:
        the string representation
      • createTestingDirectory

        static File createTestingDirectory​(String relativePath)
        Create a directory within the test data directory at the given relative path.
        Parameters:
        relativePath - the path of the directory within the test data directory; may not be null
        Returns:
        the reference to the existing readable and writable directory
      • dataDir

        static String dataDir()
        Returns the name of the directory where tests are storing their data. Default value is 'target/data'. This value can be overridden by value of the DBZ_TEST_DATA_DIR system or environment variable.
      • createTestingFile

        static File createTestingFile()
        Create a randomly-named file within the test data directory.
        Returns:
        the reference to the existing readable and writable file
      • createTestingFile

        static File createTestingFile​(String relativePath)
        Create a file within the test data directory at the given relative path.
        Parameters:
        relativePath - the path of the file within the test data directory; may not be null
        Returns:
        the reference to the existing readable and writable file
      • createTestingFile

        static File createTestingFile​(Path relativePath)
        Create a file within the test data directory at the given relative path.
        Parameters:
        relativePath - the path of the file within the test data directory; may not be null
        Returns:
        the reference to the existing readable and writable file
      • createTestingPath

        static Path createTestingPath​(String relativePath)
        Create the path to a file within the test data directory at the given relative path.
        Parameters:
        relativePath - the path of the file within the test data directory; may not be null
        Returns:
        the reference to the existing readable and writable file
      • createTestingDirectory

        static File createTestingDirectory​(String relativePath,
                                           boolean removeExistingContent)
                                    throws IOException
        Create a directory within the test data directory at the given relative path.
        Parameters:
        relativePath - the path of the directory within the test data directory; may not be null
        removeExistingContent - true if any existing content should be removed
        Returns:
        the reference to the existing readable and writable directory
        Throws:
        IOException - if there is a problem deleting the files at this path
      • delete

        static void delete​(String path)
        A method that will delete a file or folder only if it is within the 'target' directory (for safety). Folders are removed recursively.
        Parameters:
        path - the path to the file or folder in the target directory
      • delete

        static void delete​(File fileOrFolder)
        A method that will delete a file or folder only if it is within the 'target' directory (for safety). Folders are removed recursively.
        Parameters:
        fileOrFolder - the file or folder in the target directory
      • delete

        static void delete​(Path path)
        A method that will delete a file or folder only if it is within the 'target' directory (for safety). Folders are removed recursively.
        Parameters:
        path - the path to the file or folder in the target directory
      • inTestDataDir

        static boolean inTestDataDir​(File file)
        Verify that the supplied file or directory is within the test data directory.
        Parameters:
        file - the file or directory; may not be null
        Returns:
        true if inside the test data directory, or false otherwise
      • inTestDataDir

        static boolean inTestDataDir​(Path path)
        Verify that the supplied file or directory is within the test data directory.
        Parameters:
        path - the path to the file or directory; may not be null
        Returns:
        true if inside the test data directory, or false otherwise