Package com.sun.ts.lib.util
Class TestUtil
java.lang.Object
com.sun.ts.lib.util.TestUtil
TestUtil is a final utility class responsible for implementing logging across multiple VMs. It also contains many
 convenience methods for logging property object contents, stacktraces, and header lines.
- Author:
- Kyle Grucci
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidstatic Stringstatic PropertiesThis method returns the properties objectstatic StringThis method returns the property value for the appropriate property keystatic StringgetProperty(String s, String defaultValue) This method returns the property value for the appropriate property keystatic StringgetProperty(Properties props, String key) Reads a property from the properties object and logs a message if the value is not setstatic StringgetProperty(Properties props, String key, String defaultValue) Reads a property from the properties object and logs a message if the value is not setstatic StringgetRelativePath(String oldVal) static StringgetResponse(URLConnection connection) Convience method to handle sucking in the data from a connection.static PropertiesgetResponseProperties(String string) Loads any properties that might be in a given String.static PropertiesgetResponseProperties(URLConnection connection) One shot method to get Properties directly from a URLConnection.static StringgetSystemProperty(String key) Wrapper for System.getProperty(String) that logs missing propertiesstatic StringgetSystemProperty(String key, String def) static StringgetTableName(String value) Parse a the table name from the ddl string such as: "create table foo" or "delete from foo"static StringgetTransactionStatus(int status) returns the transaction status value as a String given its integer representationstatic voidinit(Properties p) This static method must be called once by each new remote VM.static voidThis static method must be called once by the harness VM.static voidstatic voidThis static method must be called once by a VM which does not rely upon any remote logging.static voidlist(Properties p) prints the contents of a properties object to the logging streamstatic voidprints an error string to the error stream.static voidprints an error string to the error stream.static voidlogHarness(String s) static voidlogHarness(String s, Throwable t) used by TSTestFinder and TSScript to log output to the standard output streamstatic voidused by harness to log debug output to the standard output streamstatic voidprints a string to the log stream.static voidprints a string as well as the provided Throwable's stacktrace to the log stream.static voidprints a debug string to the log stream.static voidPrints a debug string as well as the provided Throwable's stacktrace.static voidprintProperties(Properties props) static voidprints the stacktrace of a Throwable to the logging streamstatic Stringprints the stacktrace of a Throwable to a stringstatic voidprintTransactionStatus(int status) prints the transaction status value as a String given its integer representationstatic StringreplaceLastSrc(String src, String replacement) static URLConnectionsendPostData(Properties p, URL url) static voidprints a line of dashes to the logging streamstatic voidprints a line of asterisks to the logging streamstatic voidstatic voidsetCurrentTest(String testName, PrintWriter outStream, PrintWriter errStream) This static method must be called once by the harness VM in order to set the output and error streams and the name of the current test.static voidsetTrace(boolean b) turns on/off debugging.static voidsleep(int s) pauses the calling thread for the specified number of millisecondsstatic voidsleepMsec(int s) pauses the calling thread for the specified number of millisecondsstatic voidsleepSec(int s) pauses the calling thread for the specified number of secondsstatic Stringstatic PropertiesstrToProps(String strProps) static StringtoEncodedString(Properties args) static voidwriteObject(TestReportInfo info) 
- 
Field Details- 
traceflagpublic static boolean traceflag
- 
sTestName
- 
EMPTY_STRING_ARRAY
- 
VM_UNDER_TESTpublic static final int VM_UNDER_TEST- See Also:
 
- 
VM_HARNESSpublic static final int VM_HARNESS- See Also:
 
- 
VM_JAVATESTpublic static final int VM_JAVATEST- See Also:
 
- 
DEBUG_OUTPUT_LEVELpublic static final int DEBUG_OUTPUT_LEVEL- See Also:
 
- 
NORMAL_OUTPUT_LEVELpublic static final int NORMAL_OUTPUT_LEVEL- See Also:
 
- 
ERROR_STREAMpublic static final int ERROR_STREAM- See Also:
 
- 
OUTPUT_STREAMpublic static final int OUTPUT_STREAM- See Also:
 
- 
NEW_LINE
- 
iWhereAreWepublic static int iWhereAreWe
- 
harnessDebugpublic static boolean harnessDebug
- 
MILLIpublic static final int MILLI- See Also:
 
 
- 
- 
Constructor Details- 
TestUtilpublic TestUtil()
 
- 
- 
Method Details- 
logHarnessDebugused by harness to log debug output to the standard output stream- Parameters:
- s- the output string
 
- 
logHarnessused by TSTestFinder and TSScript to log output to the standard output stream- Parameters:
- s- the output string
- t- a Throwable whose stacktrace gets printed
 
- 
logHarness
- 
getPropertiesThis method returns the properties object- Returns:
- the properties object
 
- 
getPropertyThis method returns the property value for the appropriate property key- Parameters:
- s- the property name
- Returns:
- the property value
 
- 
getPropertyThis method returns the property value for the appropriate property key- Parameters:
- s- the property name
- Returns:
- the property value
 
- 
getPropertyReads a property from the properties object and logs a message if the value is not set- Parameters:
- props- the properties object
- key- the property key
- Returns:
- the property value, null if not set
 
- 
getPropertyReads a property from the properties object and logs a message if the value is not set- Parameters:
- props- the properties object
- key- the property key
- defaultValue- the default value
- Returns:
- the property value, defaultValue if not set
 
- 
getSystemPropertyWrapper for System.getProperty(String) that logs missing properties- Parameters:
- key- the property key
- Returns:
- the property value
 
- 
getSystemProperty
- 
getTransactionStatusreturns the transaction status value as a String given its integer representation- Parameters:
- status- integer representation of a transaction status
- Returns:
- string representation of a transaction status
 
- 
printTransactionStatuspublic static void printTransactionStatus(int status) prints the transaction status value as a String given its integer representation- Parameters:
- status- integer representation of a transaction status
 
- 
sleepSecpublic static void sleepSec(int s) pauses the calling thread for the specified number of seconds- Parameters:
- s- number of seconds
 
- 
sleeppublic static void sleep(int s) pauses the calling thread for the specified number of milliseconds- Parameters:
- s- number of milliseconds
 
- 
sleepMsecpublic static void sleepMsec(int s) pauses the calling thread for the specified number of milliseconds- Parameters:
- s- number of milliseconds
 
- 
flushStreampublic static void flushStream()
- 
writeObject
- 
initThis static method must be called once by each new remote VM. Once called, a socket connection is created back to the host running the test harness. All calls to logMsg, logErr, and logTrace are immediately sent back to the harness host.- Parameters:
- p- properties containing harness host, port, and trace flag
- Throws:
- RemoteLoggingInitException- if an exception occurs while the server side is setting up the socket connection back to the client host
 
- 
initJavaTestpublic static void initJavaTest()
- 
setAdditionalWriter
- 
initNoLoggingThis static method must be called once by a VM which does not rely upon any remote logging. param p properties containing harness trace flag
- 
initClientThis static method must be called once by the harness VM. Once called, a serversocket begins listening for Remote VMs to connect on the port specified by harness.log.port.- Parameters:
- p- properties containing harness trace flag
 
- 
setCurrentTestThis static method must be called once by the harness VM in order to set the output and error streams and the name of the current test.- Parameters:
- testName- the currently running testname as specified in the source code tags
- outStream- stream printed to by the logMsg and logTrace methods
- errStream- stream printed to by the logErr methods
 
- 
logMsgprints a string to the log stream. All tests should use this method for standard logging messages- Parameters:
- s- string to print to the log stream
 
- 
logMsgprints a string as well as the provided Throwable's stacktrace to the log stream. All tests should use this method for standard logging messages- Parameters:
- s- string to print to the log stream
- t- - throwable whose stacktrace gets printed*
 
- 
setTracepublic static void setTrace(boolean b) turns on/off debugging. Once on, all calls to the logTrace method result in messages being printed to the log stream. If off, all logTrace calls are not printed.- Parameters:
- b- If- true, debugging is on. If false, debugging is turned off.
 
- 
logTraceprints a debug string to the log stream. All tests should use this method for verbose logging messages. Whether or not the string is printed is determined by the last call to the setTrace method.- Parameters:
- s- string to print to the log stream
 
- 
logTracePrints a debug string as well as the provided Throwable's stacktrace. Use this if certain exceptions are only desired while tracing.- Parameters:
- s- - string to print to the log stream
- t- - throwable whose stactrace gets printed
 
- 
logErrprints an error string to the error stream. All tests should use this method for error messages.- Parameters:
- s- string to print to the error stream
- e- a Throwable whose stacktrace gets printed
 
- 
logErrprints an error string to the error stream. All tests should use this method for error messages.- Parameters:
- s- string to print to the error stream
 
- 
listprints the contents of a properties object to the logging stream- Parameters:
- p- properties to print
 
- 
printStackTraceprints the stacktrace of a Throwable to the logging stream- Parameters:
- e- exception to print the stacktrace of
 
- 
printStackTraceToStringprints the stacktrace of a Throwable to a string- Parameters:
- e- exception to print the stacktrace of
 
- 
separator2public static void separator2()prints a line of asterisks to the logging stream
- 
separator1public static void separator1()prints a line of dashes to the logging stream
- 
getResponseConvience method to handle sucking in the data from a connection.- Throws:
- IOException
 
- 
getResponsePropertiesLoads any properties that might be in a given String.- Throws:
- IOException
 
- 
getResponsePropertiesOne shot method to get Properties directly from a URLConnection.- Throws:
- IOException
 
- 
toEncodedString
- 
sendPostData- Throws:
- IOException
 
- 
getTableNameParse a the table name from the ddl string such as: "create table foo" or "delete from foo"- Parameters:
- value- buffer to parse
- Returns:
- The name of the table
 
- 
srcToDist
- 
replaceLastSrc
- 
getDistString
- 
getRelativePath
- 
strToProps
- 
printProperties
 
-