Class MavenTestingUtils
- java.lang.Object
-
- org.eclipse.jetty.toolchain.test.MavenTestingUtils
-
public final class MavenTestingUtils extends java.lang.ObjectCommon utility methods for working with JUnit tests cases in a maven friendly way.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMavenTestingUtils.TestID
-
Field Summary
Fields Modifier and Type Field Description private static java.nio.file.PathbasePathprivate static java.nio.file.PathtargetPathprivate static java.nio.file.PathtestResourcesPath
-
Constructor Summary
Constructors Modifier Constructor Description privateMavenTestingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.FilegetBaseDir()Obtain aFilereference to the maven ${basedir} for the module.static java.nio.file.PathgetBasePath()Obtain aPathreference to the maven ${basedir} for the module.static java.net.URIgetBaseURI()Get the Basedir for the project as a URIstatic java.io.FilegetProjectDir(java.lang.String path)Get a directory reference to a required directory in the project module path, based on relative path references from maven ${basedir}.static java.nio.file.PathgetProjectDirPath(java.lang.String path)Get aPathreference to a required directory in the project module path, based on relative path references from maven ${basedir}.static java.io.FilegetProjectFile(java.lang.String path)Get aFilereference to a required file in the project module path, based on relative path references from maven ${basedir}.static java.nio.file.PathgetProjectFilePath(java.lang.String path)Get aPathreference to a required file in the project module path, based on relative path references from maven ${basedir}.static java.io.FilegetTargetDir()Get theFilereference to the/targetdirectory for this project.static java.io.FilegetTargetFile(java.lang.String path)Create aFileobject for a path in the /target directory.static java.nio.file.PathgetTargetPath()Get thePathreference to the/targetdirectory for this project.static java.nio.file.PathgetTargetPath(java.lang.String path)Create aPathobject for a path in the /target directory.static java.io.FilegetTargetTestingDir()Get aFilereference to the maven${basedir}/target/tests/directory.static java.io.FilegetTargetTestingDir(java.lang.Class<?> testclass, java.lang.String testmethodname)Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.static java.io.FilegetTargetTestingDir(java.lang.String testname)Get aFilereference to the maven${basedir}/target/tests/test-${testname}using the supplied testnamestatic java.io.FilegetTargetTestingDir(junit.framework.TestCase test)Get aFilereference to the${basedir}/target/tests/test-${testname}directory.static java.nio.file.PathgetTargetTestingPath()Get aPathreference to the maven${basedir}/target/tests/path.static java.nio.file.PathgetTargetTestingPath(java.lang.Class<?> testclass, java.lang.String testmethodname)Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.static java.nio.file.PathgetTargetTestingPath(java.lang.String testname)Get aPathreference to the maven${basedir}/target/tests/test-${testname}using the supplied testnamestatic java.nio.file.PathgetTargetTestingPath(junit.framework.TestCase test)Get aPathreference to the${basedir}/target/tests/test-${testname}directory.static java.net.URIgetTargetURI(java.lang.String path)Get a URI reference to a path (File or Dir) within the maven "${basedir}/target" directory.static java.net.URLgetTargetURL(java.lang.String path)Get a URL reference to a path (File or Dir) within the maven "${basedir}/target" directory.private static MavenTestingUtils.TestIDgetTestID()Using junit 3.x naming standards for unit tests and test method names, attempt to discover the unit test name from the execution stack.static java.io.FilegetTestResourceDir(java.lang.String name)Get a dir from the maven${basedir}/src/test/resourcedirectory.static java.io.FilegetTestResourceFile(java.lang.String name)Get a file from the maven${basedir}/src/test/resourcedirectory.static java.nio.file.PathgetTestResourcePath(java.lang.String name)Get a path resource (File or Dir) from the maven${basedir}/src/test/resourcedirectory.static java.nio.file.PathgetTestResourcePathDir(java.lang.String name)Get a dir from the maven${basedir}/src/test/resourcedirectory.static java.nio.file.PathgetTestResourcePathFile(java.lang.String name)Get a file from the maven${basedir}/src/test/resourcedirectory.static java.io.FilegetTestResourcesDir()Get theFilereference to the maven${basedir}/src/test/resourcesdirectorystatic java.nio.file.PathgetTestResourcesPath()Get thePathreference to the maven${basedir}/src/test/resourcesdirectory
-
-
-
Method Detail
-
getBaseDir
public static java.io.File getBaseDir()
Obtain aFilereference to the maven ${basedir} for the module.Convenience method for
MavenTestingUtils.getBasePath().toFile()- Returns:
- the equivalent to the maven ${basedir} property.
- See Also:
getBasePath()
-
getBasePath
public static java.nio.file.Path getBasePath()
Obtain aPathreference to the maven ${basedir} for the module.Note: while running in maven, the ${basedir} is populated by maven and used by the surefire-plugin.
While running in eclipse, the ${basedir} property is unset, resulting in this method falling back to ${user.dir} equivalent use.- Returns:
- the equivalent to the maven ${basedir} property.
-
getBaseURI
public static java.net.URI getBaseURI()
Get the Basedir for the project as a URI- Returns:
- the URI for the project basedir
-
getTargetDir
public static java.io.File getTargetDir()
Get theFilereference to the/targetdirectory for this project.Convenience method for
MavenTestingUtils.getTargetPath().toFile()- Returns:
- the directory path to the target directory.
- See Also:
getTargetPath()
-
getTargetPath
public static java.nio.file.Path getTargetPath()
Get thePathreference to the/targetdirectory for this project.This is roughly equivalent to the
${project.build.directory}property.Note: this implementation does not inspect the
pom.xmlfor non-standard locations of the${project.build.directory}property. (it always assumes/target)- Returns:
- the directory path to the
/targetdirectory.
-
getTargetFile
public static java.io.File getTargetFile(java.lang.String path)
Create aFileobject for a path in the /target directory.Convenience method for
MavenTestingUtils.getTargetPath("foo").toFile()- Parameters:
path- the path desired, no validation of existence is performed.- Returns:
- the File to the path.
- See Also:
getTargetPath(String)
-
getTargetPath
public static java.nio.file.Path getTargetPath(java.lang.String path)
Create aPathobject for a path in the /target directory.- Parameters:
path- the path desired, no validation of existence is performed.- Returns:
- the File to the path.
-
getTargetTestingDir
public static java.io.File getTargetTestingDir()
Get aFilereference to the maven${basedir}/target/tests/directory.Convenience method for
MavenTestingUtils.getTargetTestingPath().toFile()- Returns:
- the maven
${basedir}/target/tests/directory. Note: will not validate that the directory exists, or create the directory)
-
getTargetTestingPath
public static java.nio.file.Path getTargetTestingPath()
Get aPathreference to the maven${basedir}/target/tests/path.- Returns:
- the maven
${basedir}/target/tests/directory. Note: will not validate that the directory exists, or create the directory)
-
getTargetTestingDir
public static java.io.File getTargetTestingDir(java.lang.String testname)
Get aFilereference to the maven${basedir}/target/tests/test-${testname}using the supplied testnameConvenience method for
MavenTestingUtils.getTargetTestingPath(testname).toFile()- Parameters:
testname- the testname to create directory against.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory
-
getTargetTestingPath
public static java.nio.file.Path getTargetTestingPath(java.lang.String testname)
Get aPathreference to the maven${basedir}/target/tests/test-${testname}using the supplied testname- Parameters:
testname- the testname to create directory against.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory
-
getTargetTestingDir
public static java.io.File getTargetTestingDir(junit.framework.TestCase test)
Get aFilereference to the${basedir}/target/tests/test-${testname}directory. Uses the JUnit 3.xTestCase.getName()to make a unique directory name per test.Convenience method for
MavenTestingUtils.getTargetTestingPath(TestCase.getName()).toFile()- Parameters:
test- the junit 3.x testcase to base this new directory on.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory.
-
getTargetTestingPath
public static java.nio.file.Path getTargetTestingPath(junit.framework.TestCase test)
Get aPathreference to the${basedir}/target/tests/test-${testname}directory. Uses the JUnit 3.xTestCase.getName()to make a unique directory name per test.Convenience method for
MavenTestingUtils.getTargetTestingPath(TestCase.getName())- Parameters:
test- the junit 3.x testcase to base this new directory on.- Returns:
- the maven
${basedir}/target/tests/test-${testname}directory. - See Also:
getTargetTestingPath(String)
-
getTargetURI
public static java.net.URI getTargetURI(java.lang.String path)
Get a URI reference to a path (File or Dir) within the maven "${basedir}/target" directory.Convenience method for
MavenTestingUtils.getTargetPath(path).toUri()- Parameters:
path- the relative path to use- Returns:
- the URI reference to the target path
-
getTargetURL
public static java.net.URL getTargetURL(java.lang.String path) throws java.net.MalformedURLExceptionGet a URL reference to a path (File or Dir) within the maven "${basedir}/target" directory.Convenience method for
MavenTestingUtils.getTargetURI(path).toURL()- Parameters:
path- the relative path to use- Returns:
- the URL reference to the target path
- Throws:
java.net.MalformedURLException- if unable to create a new target url due to URL error.
-
getTargetTestingDir
public static java.io.File getTargetTestingDir(java.lang.Class<?> testclass, java.lang.String testmethodname)Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.Note: the @Rule
TestingDiris a better choice in most cases.Convenience method for
MavenTestingUtils.getTargetTestingDir(testclass, testmethodname).toFile()- Parameters:
testclass- the class for the test casetestmethodname- the test method name- Returns:
- the File path to the testname specific testing directory underneath the
${basedir}/target/tests/sub directory - See Also:
FS,TestingDir
-
getTargetTestingPath
public static java.nio.file.Path getTargetTestingPath(java.lang.Class<?> testclass, java.lang.String testmethodname)Obtain a testing directory reference in maven${basedir}/target/tests/${condensed-classname}/${methodname}path that uses an condensed directory name based on the testclass and subdirectory based on the testmethod being run.Note: the @Rule
TestingDiris a better choice in most cases.- Parameters:
testclass- the class for the test casetestmethodname- the test method name- Returns:
- the File path to the testname specific testing directory underneath the
${basedir}/target/tests/sub directory - See Also:
FS,TestingDir
-
getProjectFile
public static java.io.File getProjectFile(java.lang.String path)
Get aFilereference to a required file in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing file
Convenience method for
MavenTestingUtils.getProjectFilePath(path).toFile()- Parameters:
path- the relative path to reference- Returns:
- the file reference (must exist)
-
getProjectFilePath
public static java.nio.file.Path getProjectFilePath(java.lang.String path)
Get aPathreference to a required file in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing file
- Parameters:
path- the relative path to reference- Returns:
- the file reference (must exist)
-
getProjectDir
public static java.io.File getProjectDir(java.lang.String path)
Get a directory reference to a required directory in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing directory
Convenience method for
MavenTestingUtils.getProjectDirPath(path).toFile()- Parameters:
path- the relative path to reference- Returns:
- the directory reference (must exist)
-
getProjectDirPath
public static java.nio.file.Path getProjectDirPath(java.lang.String path)
Get aPathreference to a required directory in the project module path, based on relative path references from maven ${basedir}.Note: will throw assertion error if path does point to an existing directory
- Parameters:
path- the relative path to reference- Returns:
- the directory reference (must exist)
-
getTestID
private static MavenTestingUtils.TestID getTestID()
Using junit 3.x naming standards for unit tests and test method names, attempt to discover the unit test name from the execution stack.- Returns:
- the unit test id found via execution stack and junit 3.8 naming conventions.
- See Also:
#getTestIDAsPath()
-
getTestResourcesDir
public static java.io.File getTestResourcesDir()
Get theFilereference to the maven${basedir}/src/test/resourcesdirectoryConvenience method for
MavenTestingUtils.getTestResourcesPath().toFile()- Returns:
- the directory
Fileto the maven${basedir}/src/test/resourcesdirectory
-
getTestResourcesPath
public static java.nio.file.Path getTestResourcesPath()
Get thePathreference to the maven${basedir}/src/test/resourcesdirectory- Returns:
- the directory
Pathto the maven${basedir}/src/test/resourcesdirectory
-
getTestResourceDir
public static java.io.File getTestResourceDir(java.lang.String name)
Get a dir from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing directory
Convenience method for
MavenTestingUtils.getTestResourcesPathDir(name).toFile()- Parameters:
name- the name of the path to get (it must exist as a dir)- Returns:
- the dir in the maven
${basedir}/src/test/resourcepath
-
getTestResourcePathDir
public static java.nio.file.Path getTestResourcePathDir(java.lang.String name)
Get a dir from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing directory
- Parameters:
name- the name of the path to get (it must exist as a dir)- Returns:
- the dir in the maven
${basedir}/src/test/resourcepath
-
getTestResourceFile
public static java.io.File getTestResourceFile(java.lang.String name)
Get a file from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing file
- Parameters:
name- the name of the path to get (it must exist as a file)- Returns:
- the file in maven
${basedir}/src/test/resource
-
getTestResourcePathFile
public static java.nio.file.Path getTestResourcePathFile(java.lang.String name)
Get a file from the maven${basedir}/src/test/resourcedirectory.Note: will throw assertion error if path does point to an existing file
- Parameters:
name- the name of the path to get (it must exist as a file)- Returns:
- the file in maven
${basedir}/src/test/resource
-
getTestResourcePath
public static java.nio.file.Path getTestResourcePath(java.lang.String name)
Get a path resource (File or Dir) from the maven${basedir}/src/test/resourcedirectory.- Parameters:
name- the name of the path to get (it must exist)- Returns:
- the path in maven
${basedir}/src/test/resource
-
-