com.ibm.team.fvt.tests.scenario
Class ScenarioUtils

java.lang.Object
  extended by com.ibm.team.fvt.tests.scenario.ScenarioUtils

public class ScenarioUtils
extends java.lang.Object

Utils for Scenario tests execution.

The first utility is to read Scenario parameters.
They can be defined either in a properties files specified by the System property PARAM_FILE_PATH_ID or directly by System properties specified in the VM arguments tab of the launch configuration.

The second utility is to provide debug function allowing to dump debug information either in the console or in a file if the System property DEBUG_DIRECTORY is set.

This class also provides following utilities:


Field Summary
static java.text.SimpleDateFormat COMPACT_DATE_FORMAT
           
static java.lang.String COMPACT_DATE_STRING
           
static boolean DEBUG
          Global flag whether to print debug information on console or not.
static java.lang.String DEBUG_DIRECTORY
          Returns the directory to use to store debug file.
static java.lang.String EMPTY_STRING
           
static java.lang.String LINE_SEPARATOR
           
static java.lang.String LOG_FILE_NAME
          Parameter telling which directory to use to put debug file.
static int MAX_RECOVERY_TRIES
           
static long ONE_HOUR
           
static int ONE_MINUTE
           
static boolean PRINT
          Global flag whether to print output on console or not.
static java.lang.String SPACE_STRING
           
static java.text.SimpleDateFormat TIME_FORMAT
           
static java.lang.String USER_DIR_ID
           
 
Constructor Summary
ScenarioUtils()
           
 
Method Summary
static java.io.File createDir(java.lang.String dirPath)
          Return the File corresponding to the given path.
static java.io.File createDir(java.lang.String dirPath, java.lang.String subdirName)
          Return the File corresponding to the given path and the sub-directory.
static void debugClose()
          Close the debug stream.
static void debugOpen()
          Open debug stream.
static void debugPrint(java.lang.String text)
          Print a text in the debug stream.
static void debugPrintException(java.lang.Throwable t)
          Print only meaningful element of an exception statck trace
static void debugPrintExpectedStrings(java.lang.String kind, java.lang.String status, java.lang.String... strings)
          Debug method to print expected strings of a given kind of HTML element.
static void debugPrintln()
          Print a new line in the debug stream.
static void debugPrintln(java.lang.String... text)
          Print a line in the debug stream.
static void debugPrintln(java.lang.String text)
          Print a line in the debug stream.
static void debugPrintln(java.lang.String text, int indent)
          Print an indented line in the debug stream.
static void debugPrintStackTrace(int tabs)
          Print only meaningful element of the given stack trace for the caller
static void debugPrintStackTrace(java.lang.StackTraceElement[] elements)
          Print only meaningful element of the given stack trace
static void debugPrintStackTrace(java.lang.StackTraceElement[] elements, int tabs)
          Print only meaningful element of the given stack trace
static java.lang.String elapsedTimeString(long start)
          Returns a string to display the elasped time since the given start point.
static java.lang.String getClassSimpleName(java.lang.Class<?> clazz)
          Return the class name without package prefix.
static boolean getParameterBooleanValue(java.lang.String name)
          Return the boolean value from the System property value set in the launch config.
static boolean getParameterBooleanValue(java.lang.String name, boolean defaultValue)
          Return the boolean value from the System property value set in the launch config.
static double getParameterDoubleValue(java.lang.String name)
          Return the double value from the System property value set in the launch config.
static double getParameterDoubleValue(java.lang.String name, double defaultValue)
          Return the double value from the System property value set in the launch config.
static int getParameterIntValue(java.lang.String name)
          Return the integer value from the System property value set in the launch config.
static int getParameterIntValue(java.lang.String name, int defaultValue)
          Return the integer value from the System property value set in the launch config.
static java.lang.String getParameterValue(java.lang.String... names)
          Return the string value from the first defined System property from the list set in the launch config.
static java.lang.String getParameterValue(java.lang.String name)
          Return the parameter string value from the System property set in the launch config.
static java.lang.String getParameterValue(java.lang.String name, java.lang.String defaultValue)
          Return the parameter string value from the System property set in the launch config.
static java.lang.String getTextFromList(java.util.List<java.lang.String> strings)
          Return the given strings list as a flat text separated with comma.
static java.lang.String getTextFromList(java.util.List<java.lang.String> strings, java.lang.String separator)
          Return the given strings list as a flat text separated with the given separator.
static java.lang.String getTextFromList(java.lang.String[] strings)
          Return the given strings list as a flat text separated with comma.
static java.lang.String getTextFromList(java.lang.String[] strings, java.lang.String separator)
          Return the given strings list as a flat text separated with the given separator.
static void pause(int millisecs)
          Pause during the given milli-seconds time.
static void print(java.lang.Object text)
          Print a text to the console.
static void printException(java.lang.Throwable t)
          Print only meaningful element of an exception statck trace
static void println()
          Print a empty line to the console.
static void println(java.lang.Object text)
          Print a text with a new line at the end to the console.
static void printStackTrace(int tabs)
          Print only meaningful element of the given stack trace for the caller
static void printStackTrace(java.lang.StackTraceElement[] elements, int tabs)
          Print only meaningful element of the given stack trace
static void printStepStart(ScenarioStep step)
          Print the starting point for the given test case.
static void setDebugWriter()
           
static void sleep(int seconds)
          Sleep during the given seconds time.
static java.lang.String timeString(long time)
          Returns a string to display the given time as a duration formatted as: "XXXms" if the duration is less than 0.1s (e.g.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_DIR_ID

public static final java.lang.String USER_DIR_ID
See Also:
Constant Field Values

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

SPACE_STRING

public static final java.lang.String SPACE_STRING
See Also:
Constant Field Values

LINE_SEPARATOR

public static final java.lang.String LINE_SEPARATOR

ONE_MINUTE

public static final int ONE_MINUTE
See Also:
Constant Field Values

ONE_HOUR

public static final long ONE_HOUR
See Also:
Constant Field Values

COMPACT_DATE_FORMAT

public static final java.text.SimpleDateFormat COMPACT_DATE_FORMAT

COMPACT_DATE_STRING

public static final java.lang.String COMPACT_DATE_STRING

TIME_FORMAT

public static final java.text.SimpleDateFormat TIME_FORMAT

MAX_RECOVERY_TRIES

public static final int MAX_RECOVERY_TRIES
See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
Global flag whether to print debug information on console or not.

Default is true.


DEBUG_DIRECTORY

public static final java.lang.String DEBUG_DIRECTORY
Returns the directory to use to store debug file.

To specify it, then use the following parameter:

Note that this parameter is ignored even if specified when DEBUG parameter is set to false.


LOG_FILE_NAME

public static final java.lang.String LOG_FILE_NAME
Parameter telling which directory to use to put debug file.

Name: "log.file.name"
Value: String, a valid file name matching the OS on which you're running the BVT test
Default value: debug.log
Usage: -Dlog.file.name=my_debug_file.log in the VM Arguments field of the launch configuration.

Note that this parameter is ignored if DEBUG parameter is set to false.


PRINT

public static final boolean PRINT
Global flag whether to print output on console or not. Default is true.

Constructor Detail

ScenarioUtils

public ScenarioUtils()
Method Detail

createDir

public static java.io.File createDir(java.lang.String dirPath)
Return the File corresponding to the given path.

If the directory does not exist, then it creates it.

Parameters:
dirPath - The path of the directory
Returns:
The File corresponding to the directory or null if it didn't exist and that was not possible to create it.

createDir

public static java.io.File createDir(java.lang.String dirPath,
                                     java.lang.String subdirName)
Return the File corresponding to the given path and the sub-directory.

If the directories do not exist, then it creates them.

Parameters:
dirPath - The path of the directory
subdirName - The sub-directory name
Returns:
The File corresponding to the directory or null if it didn't exist and that was not possible to create it.

debugClose

public static void debugClose()
Close the debug stream.


debugOpen

public static void debugOpen()
Open debug stream.


debugPrint

public static void debugPrint(java.lang.String text)
Print a text in the debug stream.

Parameters:
text - The line to print in the stream.

debugPrintException

public static void debugPrintException(java.lang.Throwable t)
Print only meaningful element of an exception statck trace

Parameters:
t - The exception

debugPrintExpectedStrings

public static void debugPrintExpectedStrings(java.lang.String kind,
                                             java.lang.String status,
                                             java.lang.String... strings)
Debug method to print expected strings of a given kind of HTML element.


debugPrintln

public static void debugPrintln()
Print a new line in the debug stream.


debugPrintln

public static void debugPrintln(java.lang.String text)
Print a line in the debug stream.

Parameters:
text - The line to print to the stream.

debugPrintln

public static void debugPrintln(java.lang.String... text)
Print a line in the debug stream.

Parameters:
text - The line to print in the stream.

debugPrintln

public static void debugPrintln(java.lang.String text,
                                int indent)
Print an indented line in the debug stream.

Parameters:
text - The line to print in the stream.

debugPrintStackTrace

public static void debugPrintStackTrace(int tabs)
Print only meaningful element of the given stack trace for the caller

Parameters:
tabs - The number of tabs to indent each element

debugPrintStackTrace

public static void debugPrintStackTrace(java.lang.StackTraceElement[] elements)
Print only meaningful element of the given stack trace

Parameters:
elements - The full stack trace elements

debugPrintStackTrace

public static void debugPrintStackTrace(java.lang.StackTraceElement[] elements,
                                        int tabs)
Print only meaningful element of the given stack trace

Parameters:
elements - The full stack trace elements
tabs - The number of tabs to indent each element

elapsedTimeString

public static java.lang.String elapsedTimeString(long start)
Returns a string to display the elasped time since the given start point.

Parameters:
start - The start of the time measure.
Returns:
The elapsed time as a human readable String.

getClassSimpleName

public static java.lang.String getClassSimpleName(java.lang.Class<?> clazz)
Return the class name without package prefix.

Returns:
the simple class name as a String.

getParameterBooleanValue

public static boolean getParameterBooleanValue(java.lang.String name)
Return the boolean value from the System property value set in the launch config.

Parameters:
name - The parameter name
Returns:
The value as an boolean corresponding to the system property or false if it is not defined.

getParameterBooleanValue

public static boolean getParameterBooleanValue(java.lang.String name,
                                               boolean defaultValue)
Return the boolean value from the System property value set in the launch config.

Parameters:
name - The parameter name
defaultValue - The value returned if the system property is not defined.
Returns:
The value as an boolean corresponding to the system property or the default value if it is not defined.

getParameterDoubleValue

public static double getParameterDoubleValue(java.lang.String name)
Return the double value from the System property value set in the launch config.

Parameters:
name - The parameter name
Returns:
The value as an double corresponding to the system property or the default value if it is not defined or if the corresponding system property does not define a valid double.

getParameterDoubleValue

public static double getParameterDoubleValue(java.lang.String name,
                                             double defaultValue)
Return the double value from the System property value set in the launch config.

Parameters:
name - The parameter name
defaultValue - The value returned if the system property is not defined.
Returns:
The value as an double corresponding to the system property or the default value if it is not defined or if the corresponding system property does not define a valid double.

getParameterIntValue

public static int getParameterIntValue(java.lang.String name)
Return the integer value from the System property value set in the launch config.

Parameters:
name - The parameter name
Returns:
The value as an int corresponding to the system property or 0 if it is not defined.
Throws:
java.lang.NumberFormatException - If the corresponding system property does not define a valid integer.

getParameterIntValue

public static int getParameterIntValue(java.lang.String name,
                                       int defaultValue)
Return the integer value from the System property value set in the launch config.

Parameters:
name - The parameter name
defaultValue - The value returned if the system property is not defined.
Returns:
The value as an int corresponding to the system property or the default value if it is not defined or if the corresponding system property does not define a valid integer.

getParameterValue

public static java.lang.String getParameterValue(java.lang.String name)
Return the parameter string value from the System property set in the launch config.

Parameters:
name - The parameter name
Returns:
The value as a String corresponding to the system prorty or null if the system property is not defined.

getParameterValue

public static java.lang.String getParameterValue(java.lang.String... names)
Return the string value from the first defined System property from the list set in the launch config.

Parameters:
names - A list of possible parameter names
Returns:
The value as a String corresponding to the first defined system property defined or null if none was found.

getParameterValue

public static java.lang.String getParameterValue(java.lang.String name,
                                                 java.lang.String defaultValue)
Return the parameter string value from the System property set in the launch config.

Parameters:
name - The parameter name
defaultValue - The value returned if the parameter is not defined.
Returns:
The value as a String corresponding to the system property or defaultValue if the system property is not defined.

getTextFromList

public static java.lang.String getTextFromList(java.util.List<java.lang.String> strings)
Return the given strings list as a flat text separated with comma.

Returns:
The text as as String

getTextFromList

public static java.lang.String getTextFromList(java.util.List<java.lang.String> strings,
                                               java.lang.String separator)
Return the given strings list as a flat text separated with the given separator.

Parameters:
strings - The list of strings
separator - String to use to separate strings
Returns:
The text as as String

getTextFromList

public static java.lang.String getTextFromList(java.lang.String[] strings)
Return the given strings list as a flat text separated with comma.

Returns:
The text as as String

getTextFromList

public static java.lang.String getTextFromList(java.lang.String[] strings,
                                               java.lang.String separator)
Return the given strings list as a flat text separated with the given separator.

Parameters:
strings - The list of strings
separator - String to use to separate strings
Returns:
The text as as String

pause

public static void pause(int millisecs)
Pause during the given milli-seconds time.

Parameters:
millisecs -

print

public static void print(java.lang.Object text)
Print a text to the console. The output is done iff the PRINT flag is set.

Parameters:
text - The text to print to the console.

printException

public static void printException(java.lang.Throwable t)
Print only meaningful element of an exception statck trace

Parameters:
t - The exception

println

public static void println()
Print a empty line to the console. The output is done iff the PRINT flag is set.


println

public static void println(java.lang.Object text)
Print a text with a new line at the end to the console. The output is done iff the PRINT flag is set.

Parameters:
text - The text to print to the console.

printStackTrace

public static void printStackTrace(int tabs)
Print only meaningful element of the given stack trace for the caller

Parameters:
tabs - The number of tabs to indent each element

printStackTrace

public static void printStackTrace(java.lang.StackTraceElement[] elements,
                                   int tabs)
Print only meaningful element of the given stack trace

Parameters:
elements - The full stack trace elements
tabs - The number of tabs to indent each element

printStepStart

public static void printStepStart(ScenarioStep step)
Print the starting point for the given test case.

Parameters:
step - The scenario step

setDebugWriter

public static void setDebugWriter()

sleep

public static void sleep(int seconds)
Sleep during the given seconds time.

Parameters:
seconds - The number of seconds to sleep.

timeString

public static java.lang.String timeString(long time)
Returns a string to display the given time as a duration formatted as:

Parameters:
time - The time to format as a long.
Returns:
The time as a human readable readable String.