Class JavaApplicationLaunchFixture
- java.lang.Object
-
- de.gebit.integrity.runner.fixtures.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
JavaApplicationLaunchFixture.ApplicationWrapper
This wrapper thread is used to run the actual application.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoader
classLoader
The classloader to use.protected static JavaApplicationLaunchFixture.ApplicationWrapper
lastApplication
The last application that was started is stored here.protected static int
WRAPPER_KILL_TIME
The fixture will wait this number of milliseconds for the application thread to die.protected static int
WRAPPER_STARTUP_TIME
The fixture will wait this number of milliseconds before first checking whether an exception occurred during that time.
-
Constructor Summary
Constructors Constructor Description JavaApplicationLaunchFixture()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
checkWrapper(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
Checks whether a provided application wrapper is considered alive.boolean
isAlive(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
Checks whether the provided application (if none was provided, the last started application is used) is still alive.protected boolean
isAliveInternal(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
Performs a liveliness check on the given application (or the last started one if none is provided).boolean
kill(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
Kills the provided application (or the last started one, if none is explicitly provided).protected boolean
killInternal(JavaApplicationLaunchFixture.ApplicationWrapper aWrapper)
Actually kills the provided application (or the last started one, if none is explicitly provided).JavaApplicationLaunchFixture.ApplicationWrapper
launch(java.lang.String aMainClassName, java.lang.String[] someArguments)
Launches the provided application by calling the static main method of the application class.protected JavaApplicationLaunchFixture.ApplicationWrapper
launchInternal(java.lang.String aMainClassName, java.lang.String[] someArguments)
Launches the provided main class by calling its main method with the provided arguments.protected JavaApplicationLaunchFixture.ApplicationWrapper
launchMain(java.lang.Class<?> aMainClass, java.lang.reflect.Method aMainMethod, java.lang.String[] someArguments)
Here the main method in the given class is actually launched and the wrapper is created.
-
-
-
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
-
lastApplication
protected static JavaApplicationLaunchFixture.ApplicationWrapper lastApplication
The last application that was started is stored here. If the fixture methods are called without theJavaApplicationLaunchFixture.ApplicationWrapper
parameter, this instance is used.
-
-
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 classsomeArguments
- 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 namesomeArguments
- 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 applicationaMainMethod
- the main methodsomeArguments
- 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
-
-