Griffon 1.2.0

org.codehaus.griffon.test.support
[Groovy] Class GriffonTestTypeSupport

java.lang.Object
  org.codehaus.griffon.test.support.GriffonTestTypeSupport
All Implemented Interfaces:
GriffonTestType

abstract class GriffonTestTypeSupport

Provides a convenient base for GriffonTestType implementations.


Field Summary
private File sourceDir

private ClassLoader testClassLoader

 
Property Summary
Binding buildBinding

The binding from the build environment

File compiledClassesDir

The location where the type's source was compiled to

String name

The name of this test type

String relativeSourcePath

The path to this type's source, relative to the root of all test source

GriffonTestTargetPattern testTargetPatterns

The test target patterns that should be used to filter the tests to run

 
Constructor Summary
GriffonTestTypeSupport(String name, String relativeSourcePath)

Sets the name and relativeSourcePath

 
Method Summary
void cleanup()

Called after the tests have completed, regardless of success or not.

protected SystemOutAndErrSwapper createSystemOutAndErrSwapper()

Creates swapper with echo parameters based on testOptions.echoOut and testOptions.echoErr in the build binding.

protected int doPrepare()

Do any preparation and return the (approximate) number of tests that will be run.

protected GriffonTestTypeResult doRun(GriffonTestEventPublisher eventPublisher)

Performs the tests, and appropriately calls GriffonTestEventPublisher to communicate the status.

protected void eachSourceFile(Closure body)

Calls body with the GriffonTestTargetPattern that matched the source, and the File for the source.

protected List findSourceFiles(GriffonTestTargetPattern targetPattern)

Finds source based on the testSuffixes and testExtensions that match the targetPattern.

protected GriffonApplication getApplication()

Will return the application if it is present, but will throw an IllegalStateException if it is not.

protected File getSourceDir()

The location of this type's source

protected ClassLoader getTestClassLoader()

A class loader with class path additions of this type's source dir and compile classed dir.

protected List getTestExtensions()

Override to have the tests for this type require a certain file extension

protected List getTestSuffixes()

Override to have the tests for this type require a certain suffix

protected Class loadClass(String className)

Loods the class named by className using a class loader that can load the test classes, throwing a RuntimeException if the class can't be loaded.

int prepare(GriffonTestTargetPattern[] testTargetPatterns, File compiledClassesDir, Binding buildBinding)

Sets the appropriate instance variables from the parameters, and calls doPrepare()

GriffonTestTypeResult run(GriffonTestEventPublisher eventPublisher)

Sets the current thread's contextClassLoader to the test class loader, calls doRun(GriffonTestEventPublisher) and then restores the original contextClassLoader.

protected Class sourceFileToClass(File sourceFile)

Convenience method for obtaining the class file for a test class

protected File sourceFileToClassFile(File sourceFile)

Convenience method for obtaining the class file for a test class

protected String sourceFileToClassName(File sourceFile)

Gets the corresponding class name for a source file of this test type.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

sourceDir

private File sourceDir


testClassLoader

private ClassLoader testClassLoader


 
Property Detail

buildBinding

Binding buildBinding
The binding from the build environment


compiledClassesDir

File compiledClassesDir
The location where the type's source was compiled to


name

final String name
The name of this test type


relativeSourcePath

final String relativeSourcePath
The path to this type's source, relative to the root of all test source


testTargetPatterns

GriffonTestTargetPattern testTargetPatterns
The test target patterns that should be used to filter the tests to run


 
Constructor Detail

GriffonTestTypeSupport

GriffonTestTypeSupport(String name, String relativeSourcePath)
Sets the name and relativeSourcePath


 
Method Detail

cleanup

void cleanup()
Called after the tests have completed, regardless of success or not. This implementation does nothing.


createSystemOutAndErrSwapper

protected SystemOutAndErrSwapper createSystemOutAndErrSwapper()
Creates swapper with echo parameters based on testOptions.echoOut and testOptions.echoErr in the build binding.


doPrepare

protected int doPrepare()
Do any preparation and return the (approximate) number of tests that will be run. If a number less than 1 is returned, this test type will not be run. Typically, implementations with call getTestClassLoader() and load the appropriate tests that match the testTargetPatterns.


doRun

protected GriffonTestTypeResult doRun(GriffonTestEventPublisher eventPublisher)
Performs the tests, and appropriately calls GriffonTestEventPublisher to communicate the status.


eachSourceFile

protected void eachSourceFile(Closure body)
Calls body with the GriffonTestTargetPattern that matched the source, and the File for the source.


findSourceFiles

protected List findSourceFiles(GriffonTestTargetPattern targetPattern)
Finds source based on the testSuffixes and testExtensions that match the targetPattern.


getApplication

protected GriffonApplication getApplication()
Will return the application if it is present, but will throw an IllegalStateException if it is not. This should only be called when Griffon is bootstrapped up (i.e. not for unit tests)


getSourceDir

protected File getSourceDir()
The location of this type's source


getTestClassLoader

protected ClassLoader getTestClassLoader()
A class loader with class path additions of this type's source dir and compile classed dir. Note: should not be called before prepare is called by the testing system.


getTestExtensions

protected List getTestExtensions()
Override to have the tests for this type require a certain file extension This implementation returns ["groovy", "java"]


getTestSuffixes

protected List getTestSuffixes()
Override to have the tests for this type require a certain suffix This implementation returns [""] (i.e. no required suffix)


loadClass

protected Class loadClass(String className)
Loods the class named by className using a class loader that can load the test classes, throwing a RuntimeException if the class can't be loaded.


prepare

int prepare(GriffonTestTargetPattern[] testTargetPatterns, File compiledClassesDir, Binding buildBinding)
Sets the appropriate instance variables from the parameters, and calls doPrepare()


run

GriffonTestTypeResult run(GriffonTestEventPublisher eventPublisher)
Sets the current thread's contextClassLoader to the test class loader, calls doRun(GriffonTestEventPublisher) and then restores the original contextClassLoader.


sourceFileToClass

protected Class sourceFileToClass(File sourceFile)
Convenience method for obtaining the class file for a test class


sourceFileToClassFile

protected File sourceFileToClassFile(File sourceFile)
Convenience method for obtaining the class file for a test class


sourceFileToClassName

protected String sourceFileToClassName(File sourceFile)
Gets the corresponding class name for a source file of this test type.


 

Groovy Documentation