Package io.debezium.util
Interface Testing.Files
-
- Enclosing interface:
- Testing
public static interface Testing.FilesFile system utility methods.
-
-
Field Summary
Fields Modifier and Type Field Description static StringDATA_DIRstatic StringDBZ_TEST_DATA_DIR_ENV_VAR_NAMEstatic StringDBZ_TEST_DATA_DIR_SYSTEM_PROPERTY_KEY
-
Method Summary
Static Methods Modifier and Type Method Description static FilecreateTestingDirectory(String relativePath)Create a directory within the test data directory at the given relative path.static FilecreateTestingDirectory(String relativePath, boolean removeExistingContent)Create a directory within the test data directory at the given relative path.static FilecreateTestingFile()Create a randomly-named file within the test data directory.static FilecreateTestingFile(String relativePath)Create a file within the test data directory at the given relative path.static FilecreateTestingFile(Path relativePath)Create a file within the test data directory at the given relative path.static PathcreateTestingPath(String relativePath)Create the path to a file within the test data directory at the given relative path.static StringdataDir()Returns the name of the directory where tests are storing their data.static voiddelete(File fileOrFolder)A method that will delete a file or folder only if it is within the 'target' directory (for safety).static voiddelete(String path)A method that will delete a file or folder only if it is within the 'target' directory (for safety).static voiddelete(Path path)A method that will delete a file or folder only if it is within the 'target' directory (for safety).static StringdetermineTestDataDir()static booleaninTestDataDir(File file)Verify that the supplied file or directory is within the test data directory.static booleaninTestDataDir(Path path)Verify that the supplied file or directory is within the test data directory.static InputStreamreadResourceAsStream(String pathOnClasspath)Obtain an InputStream to a named resource on the classpath used to load thisTestingclass.static InputStreamreadResourceAsStream(String pathOnClasspath, Class<?> testClass)Obtain an InputStream to a named resource on the given classpath.static StringreadResourceAsString(String pathOnClasspath)Read a classpath resource into a string.
-
-
-
Field Detail
-
DBZ_TEST_DATA_DIR_ENV_VAR_NAME
static final String DBZ_TEST_DATA_DIR_ENV_VAR_NAME
- See Also:
- Constant Field Values
-
DBZ_TEST_DATA_DIR_SYSTEM_PROPERTY_KEY
static final String DBZ_TEST_DATA_DIR_SYSTEM_PROPERTY_KEY
- See Also:
- Constant Field Values
-
DATA_DIR
static final String DATA_DIR
-
-
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 classpathtestClass- 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 thisTestingclass.- 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 theDBZ_TEST_DATA_DIRsystem 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 nullremoveExistingContent- 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
-
-