Class ConsoleTestExecutor
- java.lang.Object
-
- de.gebit.integrity.runner.console.ConsoleTestExecutor
-
public class ConsoleTestExecutor extends java.lang.Object
A basic program to run Integrity tests from the console. This class has a main method, but you can also instantiate it on your own from a different entry point, like your own main method or similar. If you instantiate it for yourself, you can supply a setup class (subclass ofIntegrityDSLSetup
) which can be used to influence the Guice initialization, for example in order to replace certain services provided via Guice injection with subclasses of your own.
There are various designated hooking points in this class which are designed to be overridden in subclasses, with the ultimate purpose of making it easy to implement common customizations with very little code (duplication).- Author:
- Rene Schneider - initial API and implementation
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
enableZombieThreadWarning
Whether to check for zombie threads at the end of test execution.static int
EXIT_CODE_PARAMETER_ERROR
Exit code returned on a parameter error (necessary parameter missing, unknown parameter given etc.).static int
EXIT_CODE_RUNTIME_ERROR
Exit code returned on a runtime error during test execution.static int
EXIT_CODE_SUCCESS
Exit code returned if everything went well.protected java.lang.Class<? extends IntegrityDSLSetup>
setupClass
The setup class to use.protected java.util.WeakHashMap<java.lang.Thread,java.lang.Boolean>
threadsRunningBeforeTestExecution
Stores a list of (weakly referenced) threads which were already running before the test run is started.
-
Constructor Summary
Constructors Constructor Description ConsoleTestExecutor()
Creates a new instance using the default setup class.ConsoleTestExecutor(java.lang.Class<? extends IntegrityDSLSetup> aSetupClass)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addParameterizedConstants(java.util.Map<java.lang.String,java.lang.String> someParameterizedConstants)
This method can be overridden to add some parameterized constants, which are defined in a test suite, if it is not desired to define those constants via VM arguments.void
checkForZombieThreads()
Searches for any threads still running which were not running whenprepareZombieThreadCheck()
was executed and prints them on the console.protected java.util.List<TestRunnerCallback>
createAdditionalCallbacks()
This is a designated override point to allow for additional callbacks to be easily integrated into a test run.protected TestRunnerCallback
createConsoleTestCallback()
Creates the console printout test runner callback.protected TestResourceProvider
createResourceProvider(java.util.List<java.io.File> aPathList)
Creates theTestResourceProvider
instance.protected TestRunnerCallback
createXmlWriterTestCallback(TestResourceProvider aResourceProvider, java.lang.String anXmlFileName, java.lang.String anExecutionName, TransformHandling aTransformHandling, boolean aCaptureConsoleFlag)
Instantiates the XML Test Writer Callback which is used to write the XML test results.protected TransformHandling
evaluateTransformHandling(SimpleCommandLineParser.StringOption anXsltOption)
Evaluates the given option and chooses a transformation handling from it.protected java.lang.String
getRootSuiteNameFrom(java.lang.String[] someRemainingParameters)
Extracts the root suite name from the remaining parameters.protected java.util.List<java.io.File>
getScriptsList(java.lang.String[] someRemainingParameters)
Returns all script references from the remaining unparsed parameters.protected java.io.PrintStream
getStdErr()
Return the standard error stream to use.protected java.io.PrintStream
getStdOut()
Return the standard output stream to use.protected TestRunner
initializeTestRunner(TestModel aModel, TestRunnerCallback aCallback, java.util.Map<java.lang.String,java.lang.String> someParameterizedConstants, java.lang.String aResultLocale, java.lang.Integer aRemotingPort, java.lang.String aRemotingBindHost, java.lang.Long aRandomSeed, java.lang.String[] someCommandLineArguments)
Initializes aTestRunner
instance using the providedTestModel
.static void
main(java.lang.String[] someArgs)
Main method.void
prepareZombieThreadCheck()
Takes note of all threads which are currently running by using thethreadsRunningBeforeTestExecution
map.protected java.util.List<java.lang.Thread>
retrieveListOfAllThreads()
Gets a list of all threads known to the JVM.int
run(java.lang.String[] someArgs)
This is basically the actual "main" method.protected void
runTests(TestRunner aRunner, SuiteDefinition aRootSuite, VariantDefinition aVariant, boolean aBlockForRemotingFlag)
Run the tests on the providedTestRunner
.int
runWithZombieThreadDetection(java.lang.String[] someArgs)
Works likerun(String[])
, but performs zombie thread detection as well.
-
-
-
Field Detail
-
EXIT_CODE_SUCCESS
public static final int EXIT_CODE_SUCCESS
Exit code returned if everything went well.- See Also:
- Constant Field Values
-
EXIT_CODE_PARAMETER_ERROR
public static final int EXIT_CODE_PARAMETER_ERROR
Exit code returned on a parameter error (necessary parameter missing, unknown parameter given etc.).- See Also:
- Constant Field Values
-
EXIT_CODE_RUNTIME_ERROR
public static final int EXIT_CODE_RUNTIME_ERROR
Exit code returned on a runtime error during test execution.- See Also:
- Constant Field Values
-
setupClass
protected java.lang.Class<? extends IntegrityDSLSetup> setupClass
The setup class to use.
-
threadsRunningBeforeTestExecution
protected java.util.WeakHashMap<java.lang.Thread,java.lang.Boolean> threadsRunningBeforeTestExecution
Stores a list of (weakly referenced) threads which were already running before the test run is started.
-
enableZombieThreadWarning
protected boolean enableZombieThreadWarning
Whether to check for zombie threads at the end of test execution.
-
-
Constructor Detail
-
ConsoleTestExecutor
public ConsoleTestExecutor()
Creates a new instance using the default setup class.
-
ConsoleTestExecutor
public ConsoleTestExecutor(java.lang.Class<? extends IntegrityDSLSetup> aSetupClass)
Creates a new instance.- Parameters:
aSetupClass
- the setup class to use
-
-
Method Detail
-
main
public static void main(java.lang.String[] someArgs)
Main method.- Parameters:
someArgs
-
-
prepareZombieThreadCheck
public void prepareZombieThreadCheck()
Takes note of all threads which are currently running by using thethreadsRunningBeforeTestExecution
map. This is used in conjunction withcheckForZombieThreads()
.
-
retrieveListOfAllThreads
protected java.util.List<java.lang.Thread> retrieveListOfAllThreads()
Gets a list of all threads known to the JVM. Due to the Thread API it is non-trivial to get such a list reliably, which is why that is encapsulated here. The returned list is guaranteed to not contain null items.- Returns:
- a list of threads
-
checkForZombieThreads
public void checkForZombieThreads()
Searches for any threads still running which were not running whenprepareZombieThreadCheck()
was executed and prints them on the console. This mechanism is designed to find
-
runWithZombieThreadDetection
public int runWithZombieThreadDetection(java.lang.String[] someArgs)
Works likerun(String[])
, but performs zombie thread detection as well. SeecheckForZombieThreads()
for details.- Parameters:
someArgs
- the command-line arguments- Returns:
- the exit code
-
run
public int run(java.lang.String[] someArgs)
This is basically the actual "main" method. It instantiates the test model, runner etc. and executes the test.- Parameters:
someArgs
- the command-line arguments- Returns:
- the exit code
-
getStdErr
protected java.io.PrintStream getStdErr()
Return the standard error stream to use.- Returns:
- the standard error stream
-
getStdOut
protected java.io.PrintStream getStdOut()
Return the standard output stream to use.- Returns:
- the standard output stream
-
createConsoleTestCallback
protected TestRunnerCallback createConsoleTestCallback()
Creates the console printout test runner callback. This is an override spot for subclasses.- Returns:
- the console test callback to use
-
createXmlWriterTestCallback
protected TestRunnerCallback createXmlWriterTestCallback(TestResourceProvider aResourceProvider, java.lang.String anXmlFileName, java.lang.String anExecutionName, TransformHandling aTransformHandling, boolean aCaptureConsoleFlag)
Instantiates the XML Test Writer Callback which is used to write the XML test results. This is an override spot for subclasses.- Parameters:
aResourceProvider
- the resource provider to use (classloader is taken from there)anXmlFileName
- the file to write the result intoanExecutionName
- the title of the resultaTransformHandling
- how the XML -> XHTML transform shall be handledaCaptureConsoleFlag
- whether stdout and stderr shall be captured- Returns:
- the XML test writer callback to use
-
getRootSuiteNameFrom
protected java.lang.String getRootSuiteNameFrom(java.lang.String[] someRemainingParameters)
Extracts the root suite name from the remaining parameters.- Parameters:
someRemainingParameters
- Where to extract the root suite name from.- Returns:
- the root suite name
-
getScriptsList
protected java.util.List<java.io.File> getScriptsList(java.lang.String[] someRemainingParameters)
Returns all script references from the remaining unparsed parameters.- Parameters:
someRemainingParameters
- Unparsed parameters not matched by the options.- Returns:
- List of script file references.
-
evaluateTransformHandling
protected TransformHandling evaluateTransformHandling(SimpleCommandLineParser.StringOption anXsltOption)
Evaluates the given option and chooses a transformation handling from it.- Parameters:
anXsltOption
- Option to be evaluated.- Returns:
- The chosen transformation handling.
-
createAdditionalCallbacks
protected java.util.List<TestRunnerCallback> createAdditionalCallbacks()
This is a designated override point to allow for additional callbacks to be easily integrated into a test run. Any callbacks returned here are added to the basic callbacks created for a test run (usually a console output callback and an XML file output callback, but these can be customized by startup options).- Returns:
-
addParameterizedConstants
protected void addParameterizedConstants(java.util.Map<java.lang.String,java.lang.String> someParameterizedConstants)
This method can be overridden to add some parameterized constants, which are defined in a test suite, if it is not desired to define those constants via VM arguments. The default implementation does nothing.- Parameters:
someParameterizedConstants
- the map containing the constants and their values
-
createResourceProvider
protected TestResourceProvider createResourceProvider(java.util.List<java.io.File> aPathList) throws java.io.IOException
Creates theTestResourceProvider
instance.- Parameters:
aPathList
- the list with the test script paths- Returns:
- a resource provider instance
- Throws:
java.io.IOException
-
initializeTestRunner
protected TestRunner initializeTestRunner(TestModel aModel, TestRunnerCallback aCallback, java.util.Map<java.lang.String,java.lang.String> someParameterizedConstants, java.lang.String aResultLocale, java.lang.Integer aRemotingPort, java.lang.String aRemotingBindHost, java.lang.Long aRandomSeed, java.lang.String[] someCommandLineArguments) throws java.io.IOException
Initializes aTestRunner
instance using the providedTestModel
.- Parameters:
aModel
- the modelaCallback
- the callback to usesomeParameterizedConstants
- all parameterized constants to provide to the test runneraResultLocale
- the locale to be used for the test result generation (if not provided, use the non-localized default strings, which usually are in English)aRemotingPort
- the remoting port to use by the test runneraRemotingBindHost
- the host to bind the remoting port toaRandomSeed
- the seed value for the RNGsomeCommandLineArguments
- the command line arguments to use for forking- Returns:
- the initialized test runner
- Throws:
java.io.IOException
-
runTests
protected void runTests(TestRunner aRunner, SuiteDefinition aRootSuite, VariantDefinition aVariant, boolean aBlockForRemotingFlag)
Run the tests on the providedTestRunner
.- Parameters:
aRunner
- the runneraRootSuite
- the root suite to runaVariant
- the variant to runaBlockForRemotingFlag
- whether to wait for remoting to start the tests
-
-