Class 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 of IntegrityDSLSetup) 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 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 -
      • 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 when prepareZombieThreadCheck() was executed and prints them on the console. This mechanism is designed to find
      • runWithZombieThreadDetection

        public int runWithZombieThreadDetection​(java.lang.String[] someArgs)
        Works like run(String[]), but performs zombie thread detection as well. See checkForZombieThreads() 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 into
        anExecutionName - the title of the result
        aTransformHandling - how the XML -> XHTML transform shall be handled
        aCaptureConsoleFlag - 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 the TestResourceProvider 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 a TestRunner instance using the provided TestModel.
        Parameters:
        aModel - the model
        aCallback - the callback to use
        someParameterizedConstants - all parameterized constants to provide to the test runner
        aResultLocale - 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 runner
        aRemotingBindHost - the host to bind the remoting port to
        aRandomSeed - the seed value for the RNG
        someCommandLineArguments - 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 provided TestRunner.
        Parameters:
        aRunner - the runner
        aRootSuite - the root suite to run
        aVariant - the variant to run
        aBlockForRemotingFlag - whether to wait for remoting to start the tests