Package org.anchoranalysis.test
Class TestLoader
Object
TestLoader
Loads test data, which is found at some location on the filesystem.
- Author:
- Owen Feehan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPath to the resources directory, relative to the root of the project. -
Method Summary
Modifier and TypeMethodDescriptionvoidcopyToDirectory(File destination) Copies all the data in the test-data folder (recursively), preserving file modification times.voidcopyToDirectory(String[] subdirectoriesSource, File directoryDestination) Copies specific subdirectories from the test-data folder (recursively), preserving file modification times.createForSubdirectory(String subdirectory) Creates a new test-loader for a subdirectory of the current test.static TestLoadercreateFromExplicitDirectory(String rootDirectory) Creates a new test-data loader using an explicit file path as root.static TestLoadercreateFromExplicitDirectory(Path rootDirectory) Creates a new test-data loader using an explicit file path as root.static TestLoaderCreates a new test-data loader findingPATH_RESOURCESusing the Maven working directory.static TestLoadercreateFromMavenWorkingDirectory(String toAppendToDirectory) Creates a new test-data loader findingPATH_RESOURCES/PLUS_SOMETHINGusing the Maven working directory.booleandoesPathExist(String testFilePath) Does a resource exist with a particularfolderPath + fileName.booleandoesPathExist(String testDirectoryPath, String fileName) Does a resource exist with a particularfolderPath + fileName.getRoot()Path to where the test-data is stored.static DocumentopenXmlAbsoluteFilePath(String filePath) Opens a XML document - with an absolute path on the filesystem.static DocumentopenXmlAbsoluteFilePath(Path filePath) Opens a XML document - with an absolute path on the filesystem.openXmlFromTestPath(String testPath) Opens a XML document - with a path relative to the test root.static PathpathMavenWorkingDirectory(String toAppendToDirectory) Determines the path to a directory inside the Maven Working Directory.voidprintAllFilesFromTestDirectoryPath(String testDirectoryPath) Prints the names of all files (recursively) in a test-folder tostdout.resolveTestPath(String testPath) Resolves a path to test-data (relative path to the test-data root) to an absolute path on the file system.
-
Field Details
-
PATH_RESOURCES
Path to the resources directory, relative to the root of the project.- See Also:
-
-
Method Details
-
createFromMavenWorkingDirectory
Creates a new test-data loader findingPATH_RESOURCESusing the Maven working directory.- Returns:
- a loader associated with
MAVEN_WORKING_DIR/PATH_RESOURCES
-
createFromMavenWorkingDirectory
Creates a new test-data loader findingPATH_RESOURCES/PLUS_SOMETHINGusing 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
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
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
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
Determines the path to a directory inside the Maven Working Directory.It uses the pattern
PATH_RESOURCES/PLUS_SOMETHINGinside 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
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
Does a resource exist with a particularfolderPath + fileName.- Parameters:
testFilePath- path to a file in the test-data.- Returns:
- true if a file is found at the location, false otherwise.
-
doesPathExist
Does a resource exist with a particularfolderPath + fileName.- Parameters:
testDirectoryPath- path to a folder in the test-data (can be empty).fileName- a filename in thetestDirectoryPath.- Returns:
- true if a file is found at the location, false otherwise.
-
printAllFilesFromTestDirectoryPath
Prints the names of all files (recursively) in a test-folder tostdout.- Parameters:
testDirectoryPath- path to a folder in the test-data (can be empty).
-
openXmlFromTestPath
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
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
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
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
Path to where the test-data is stored.
-