Class TestSupport
java.lang.Object
org.apache.tinkerpop.gremlin.util.TestSupport
- Direct Known Subclasses:
TestHelper
This is a utility class that is for support of various testing activities and is not meant to be used in other
contexts. It is not explicitly in a test package given our dependency hierarchy.
- Author:
- Stephen Mallette (http://stephen.genoprime.com)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcleanPathSegment(String toClean) Removes characters that aren't acceptable in a file path (mostly for windows).static FilegenerateTempFile(Class<?> clazz, String fileName, String fileNameSuffix) Creates aFilereference in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp.static FilegenerateTempFileFromResource(Class<?> graphClass, Class<?> resourceClass, String resourceName, String extension) Copies a file stored as part of a resource to the file system in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp/resources.static FilegenerateTempFileFromResource(Class<?> graphClass, Class<?> resourceClass, String resourceName, String extension, boolean overwrite) Copies a file stored as part of a resource to the file system in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp/resources.static FilegenerateTempFileFromResource(Class<?> resourceClass, String resourceName, String extension) Copies a file stored as part of a resource to the file system in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp/resources.static FilegetRootOfBuildDirectory(Class<?> clazz) Gets and/or creates the root of the test data directory.static StringmakeTestDataDirectory(Class<?> clazz, String... childPath) Creates aFilereference that .static StringmakeTestDataFile(Class<?> clazz, String fileName) static StringmakeTestDataFile(Class<?> clazz, String subdir, String fileName) static FilemakeTestDataPath(Class<?> clazz, String... childPath) Creates aFilereference that points to a directory relative to the supplied class in the/targetdirectory.
-
Field Details
-
TEST_DATA_RELATIVE_DIR
- See Also:
-
-
Constructor Details
-
TestSupport
protected TestSupport()
-
-
Method Details
-
makeTestDataPath
Creates aFilereference that points to a directory relative to the supplied class in the/targetdirectory. EachchildPathpassed introduces a new sub-directory and all are placed below theTEST_DATA_RELATIVE_DIR. For example, calling this method with "a", "b", and "c" as thechildPatharguments would yield a relative directory like:test-case-data/clazz/a/b/c. It is a good idea to use the test class for theclazzargument so that it's easy to find the data if necessary after test execution.Avoid using makeTestDataPath(...).getAbsolutePath() and makeTestDataPath(...).toString() that produces platform-dependent paths, that are incompatible with regular expressions and escape characters. Instead use
Storage.toPath(File) -
makeTestDataDirectory
Creates aFilereference that . For example, calling this method with "a", "b", and "c" as thechildPatharguments would yield a relative directory like:test-case-data/clazz/a/b/c. It is a good idea to use the test class for theclazzargument so that it's easy to find the data if necessary after test execution.- Returns:
- UNIX-formatted path to a directory in the underlying
Storage. The directory is relative to the supplied class in the/targetdirectory. EachchildPathpassed introduces a new sub-directory and all are placed below theTEST_DATA_RELATIVE_DIR
-
makeTestDataFile
- Parameters:
clazz-fileName-- Returns:
- UNIX-formatted path to a fileName in the underlying
Storage. The file is relative to the supplied class in the/targetdirectory.
-
makeTestDataFile
- Parameters:
clazz-subdir-fileName-- Returns:
- UNIX-formatted path to a subdir/fileName in the underlying
Storage. The file is relative to the supplied class in the/targetdirectory.
-
getRootOfBuildDirectory
Gets and/or creates the root of the test data directory. This method is here as a convenience and should not be used to store test data. UsemakeTestDataPath(Class, String...)instead. -
generateTempFile
public static File generateTempFile(Class<?> clazz, String fileName, String fileNameSuffix) throws IOException Creates aFilereference in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp.- Throws:
IOException
-
generateTempFileFromResource
public static File generateTempFileFromResource(Class<?> resourceClass, String resourceName, String extension) throws IOException Copies a file stored as part of a resource to the file system in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp/resources.- Throws:
IOException
-
generateTempFileFromResource
public static File generateTempFileFromResource(Class<?> graphClass, Class<?> resourceClass, String resourceName, String extension) throws IOException Copies a file stored as part of a resource to the file system in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp/resources.- Throws:
IOException
-
generateTempFileFromResource
public static File generateTempFileFromResource(Class<?> graphClass, Class<?> resourceClass, String resourceName, String extension, boolean overwrite) throws IOException Copies a file stored as part of a resource to the file system in the path returned frommakeTestDataPath(java.lang.Class<?>, java.lang.String...)in a subdirectory calledtemp/resources.- Throws:
IOException
-
cleanPathSegment
Removes characters that aren't acceptable in a file path (mostly for windows).
-