org.eclipse.jetty.toolchain.test
Class MavenTestingUtils

java.lang.Object
  extended by org.eclipse.jetty.toolchain.test.MavenTestingUtils

public final class MavenTestingUtils
extends Object

Common utility methods for working with JUnit tests cases in a maven friendly way.


Method Summary
protected static String condensePackageString(String classname)
          Condenses a classname by stripping down the package name to just the first character of each package name segment.
static File getBasedir()
           
static URI getBaseURI()
          Get the Basedir for the project as a URI
static File getProjectDir(String path)
           
static File getProjectFile(String path)
           
static File getTargetDir()
          Get the directory to the /target directory for this project.
static File getTargetFile(String path)
          Create a File object for a path in the /target directory.
static File getTargetTestingDir()
          Get the in /target/tests/ code that uses the an arbitrary name.
static File getTargetTestingDir(Class<?> testclass, String testmethodname)
          Get a dir in /target/ that uses the an arbitrary name.
static File getTargetTestingDir(String testname)
          Get a dir in /target/ that uses the an arbitrary name.
static File getTargetTestingDir(TestCase test)
          Get a dir in /target/ that uses the JUnit 3.x TestCase.getName() to make itself unique.
static URI getTargetURI(String path)
           
static URL getTargetURL(String path)
           
static String getTestIDAsPath()
           
static File getTestResourceDir(String name)
          Get a dir from the src/test/resource directory.
static File getTestResourceFile(String name)
          Get a file from the src/test/resource directory.
static File getTestResourcePath(String name)
          Get a path resource (File or Dir) from the src/test/resource directory.
static File getTestResourcesDir()
          Get the directory to the src/test/resource directory
protected static String maxStringLength(int max, String raw)
          Smash a long string to fit within the max string length, by taking the middle section of the string and replacing them with an ellipsis "..."
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBasedir

public static File getBasedir()

getBaseURI

public static URI getBaseURI()
Get the Basedir for the project as a URI

Returns:
the URI for the project basedir

getTargetDir

public static File getTargetDir()
Get the directory to the /target directory for this project.

Returns:
the directory path to the target directory.

getTargetFile

public static File getTargetFile(String path)
Create a File object 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 File getTargetTestingDir()
Get the in /target/tests/ code that uses the an arbitrary name.

Returns:
the dir in /target/tests/ that uses the an arbitrary name.

getTargetTestingDir

public static File getTargetTestingDir(String testname)
Get a dir in /target/ that uses the an arbitrary name.

Parameters:
testname - the testname to create directory against.
Returns:
the dir in /target/ that uses the an arbitrary name.

getTargetTestingDir

public static File getTargetTestingDir(TestCase test)
Get a dir in /target/ that uses the JUnit 3.x TestCase.getName() to make itself unique.

Parameters:
test - the junit 3.x testcase to base this new directory on.
Returns:
the dir in /target/ that uses the JUnit 3.x TestCase.getName() to make itself unique.

getTargetURI

public static URI getTargetURI(String path)
                        throws MalformedURLException
Throws:
MalformedURLException

getTargetURL

public static URL getTargetURL(String path)
                        throws MalformedURLException
Throws:
MalformedURLException

getTargetTestingDir

public static File getTargetTestingDir(Class<?> testclass,
                                       String testmethodname)
Get a dir in /target/ that uses the an arbitrary name.

Best if used with TestingDir junit rule.

 @Rule
 public TestingDir testdir = new TestingDir();
 
 @Test
 public void testFoo()
 {
     Assert.assertTrue("Testing dir exists",testdir.getDir().exists());
 }
 

Parameters:
testclass - the class for the test case
testmethodname - the test method name
Returns:
the File path to the testname sepecific testing directory underneath the ${basedir}/target sub directory

getTestIDAsPath

public static String getTestIDAsPath()

getProjectFile

public static File getProjectFile(String path)

getProjectDir

public static File getProjectDir(String path)

condensePackageString

protected static String condensePackageString(String classname)
Condenses a classname by stripping down the package name to just the first character of each package name segment.

 Examples:
 "org.eclipse.jetty.test.FooTest"           = "oejt.FooTest"
 "org.eclipse.jetty.server.logging.LogTest" = "orjsl.LogTest"
 

Parameters:
classname - the fully qualified class name
Returns:
the condensed name

maxStringLength

protected static String maxStringLength(int max,
                                        String raw)
Smash a long string to fit within the max string length, by taking the middle section of the string and replacing them with an ellipsis "..."

 Examples:
 .maxStringLength("Eatagramovabits", 5)
 

Parameters:
max - the maximum size of the string
raw - the raw string to smash
Returns:
the ellipsis'd version of the string.

getTestResourceDir

public static File getTestResourceDir(String name)
Get a dir from the src/test/resource directory.

Parameters:
name - the name of the path to get (it must exist as a dir)
Returns:
the dir in src/test/resource

getTestResourceFile

public static File getTestResourceFile(String name)
Get a file from the src/test/resource directory.

Parameters:
name - the name of the path to get (it must exist as a file)
Returns:
the file in src/test/resource

getTestResourcePath

public static File getTestResourcePath(String name)
Get a path resource (File or Dir) from the src/test/resource directory.

Parameters:
name - the name of the path to get (it must exist)
Returns:
the path in src/test/resource

getTestResourcesDir

public static File getTestResourcesDir()
Get the directory to the src/test/resource directory

Returns:
the directory File to the src/test/resources directory


Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.