Class JavaApplicationLaunchFixture


  • public class JavaApplicationLaunchFixture
    extends java.lang.Object
    Generic fixture usable to start, check and kill a Java application class with a static main method.
    Author:
    Rene Schneider - initial API and implementation
    • Field Detail

      • classLoader

        @Inject
        protected java.lang.ClassLoader classLoader
        The classloader to use.
      • WRAPPER_STARTUP_TIME

        protected static final int WRAPPER_STARTUP_TIME
        The fixture will wait this number of milliseconds before first checking whether an exception occurred during that time.
        See Also:
        Constant Field Values
      • WRAPPER_KILL_TIME

        protected static final int WRAPPER_KILL_TIME
        The fixture will wait this number of milliseconds for the application thread to die.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JavaApplicationLaunchFixture

        public JavaApplicationLaunchFixture()
    • Method Detail

      • launch

        public JavaApplicationLaunchFixture.ApplicationWrapper launch​(java.lang.String aMainClassName,
                                                                      java.lang.String[] someArguments)
                                                               throws java.lang.Throwable
        Launches the provided application by calling the static main method of the application class.
        Parameters:
        aMainClassName - the name of the application class
        someArguments - the arguments to provide to the main method
        Returns:
        an application wrapper instance which can optionally be saved to handle multiple applications
        Throws:
        java.lang.Throwable
      • launchInternal

        protected JavaApplicationLaunchFixture.ApplicationWrapper launchInternal​(java.lang.String aMainClassName,
                                                                                 java.lang.String[] someArguments)
                                                                          throws java.lang.Throwable
        Launches the provided main class by calling its main method with the provided arguments.
        Parameters:
        aMainClassName - the main class name
        someArguments - the arguments
        Returns:
        the launched application, contained in an JavaApplicationLaunchFixture.ApplicationWrapper instance
        Throws:
        java.lang.Throwable - if something goes wrong
      • isAlive

        public boolean isAlive​(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
        Checks whether the provided application (if none was provided, the last started application is used) is still alive.
        Parameters:
        aWrapper - the application to check (if null, the last started application is used)
        Returns:
      • isAliveInternal

        protected boolean isAliveInternal​(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
        Performs a liveliness check on the given application (or the last started one if none is provided).
        Parameters:
        aWrapper - the application to check
        Returns:
        true if alive, false if not
      • kill

        public boolean kill​(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
        Kills the provided application (or the last started one, if none is explicitly provided).
        Parameters:
        aWrapper - the application to kill
        Returns:
        true if killing was successful, false otherwise
      • killInternal

        protected boolean killInternal​(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
        Actually kills the provided application (or the last started one, if none is explicitly provided).
        Parameters:
        aWrapper - the application to kill
        Returns:
        true if killing was successful, false otherwise
      • launchMain

        protected JavaApplicationLaunchFixture.ApplicationWrapper launchMain​(java.lang.Class<?> aMainClass,
                                                                             java.lang.reflect.Method aMainMethod,
                                                                             java.lang.String[] someArguments)
                                                                      throws java.lang.Throwable
        Here the main method in the given class is actually launched and the wrapper is created.
        Parameters:
        aMainClass - the main class of the application
        aMainMethod - the main method
        someArguments - arguments to be provided to the call
        Returns:
        the resulting application wrapper
        Throws:
        java.lang.Throwable - if the shit hits the fan
      • checkWrapper

        protected boolean checkWrapper​(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
                                throws java.lang.Throwable
        Checks whether a provided application wrapper is considered alive.
        Parameters:
        aWrapper - the wrapped application to check
        Returns:
        true if it is alive, false otherwise
        Throws:
        java.lang.Throwable