Package com.sun.ts.lib.util

# Class TestUtil

java.lang.Object
com.sun.ts.lib.util.TestUtil

public final class TestUtil extends Object
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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEBUG_OUTPUT_LEVEL`
  `static final String[]`
  `EMPTY_STRING_ARRAY`
  `static final int`
  `ERROR_STREAM`
  `static boolean`
  `harnessDebug`
  `static int`
  `iWhereAreWe`
  `static final int`
  `MILLI`
  `static String`
  `NEW_LINE`
  `static final int`
  `NORMAL_OUTPUT_LEVEL`
  `static final int`
  `OUTPUT_STREAM`
  `static String`
  `sTestName`
  `static boolean`
  `traceflag`
  `static final int`
  `VM_HARNESS`
  `static final int`
  `VM_JAVATEST`
  `static final int`
  `VM_UNDER_TEST`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TestUtil()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `flushStream()`
  `static String`
  `getDistString()`
  `static Properties`
  `getProperties()`
  This method returns the properties object
  `static String`
  `getProperty(String s)`
  This method returns the property value for the appropriate property key
  `static String`
  `getProperty(String s, String defaultValue)`
  This method returns the property value for the appropriate property key
  `static String`
  `getProperty(Properties props, String key)`
  Reads a property from the properties object and logs a message if the value is not set
  `static String`
  `getProperty(Properties props, String key, String defaultValue)`
  Reads a property from the properties object and logs a message if the value is not set
  `static String`
  `getRelativePath(String oldVal)`
  `static String`
  `getResponse(URLConnection connection)`
  Convience method to handle sucking in the data from a connection.
  `static Properties`
  `getResponseProperties(String string)`
  Loads any properties that might be in a given String.
  `static Properties`
  `getResponseProperties(URLConnection connection)`
  One shot method to get Properties directly from a URLConnection.
  `static String`
  `getSystemProperty(String key)`
  Wrapper for System.getProperty(String) that logs missing properties
  `static String`
  `getSystemProperty(String key, String def)`
  `static String`
  `getTableName(String value)`
  Parse a the table name from the ddl string such as: "create table foo" or "delete from foo"
  `static String`
  `getTransactionStatus(int status)`
  returns the transaction status value as a String given its integer representation
  `static void`
  `init(Properties p)`
  This static method must be called once by each new remote VM.
  `static void`
  `initClient(Properties p)`
  This static method must be called once by the harness VM.
  `static void`
  `initJavaTest()`
  `static void`
  `initNoLogging(Properties p)`
  This static method must be called once by a VM which does not rely upon any remote logging.
  `static void`
  `list(Properties p)`
  prints the contents of a properties object to the logging stream
  `static void`
  `logErr(String s)`
  prints an error string to the error stream.
  `static void`
  `logErr(String s, Throwable e)`
  prints an error string to the error stream.
  `static void`
  `logHarness(String s)`
  `static void`
  `logHarness(String s, Throwable t)`
  used by TSTestFinder and TSScript to log output to the standard output stream
  `static void`
  `logHarnessDebug(String s)`
  used by harness to log debug output to the standard output stream
  `static void`
  `logMsg(String s)`
  prints a string to the log stream.
  `static void`
  `logMsg(String s, Throwable t)`
  prints a string as well as the provided Throwable's stacktrace to the log stream.
  `static void`
  `logTrace(String s)`
  prints a debug string to the log stream.
  `static void`
  `logTrace(String s, Throwable t)`
  Prints a debug string as well as the provided Throwable's stacktrace.
  `static void`
  `printProperties(Properties props)`
  `static void`
  `printStackTrace(Throwable e)`
  prints the stacktrace of a Throwable to the logging stream
  `static String`
  `printStackTraceToString(Throwable e)`
  prints the stacktrace of a Throwable to a string
  `static void`
  `printTransactionStatus(int status)`
  prints the transaction status value as a String given its integer representation
  `static String`
  `replaceLastSrc(String src, String replacement)`
  `static URLConnection`
  `sendPostData(Properties p, URL url)`
  `static void`
  `separator1()`
  prints a line of dashes to the logging stream
  `static void`
  `separator2()`
  prints a line of asterisks to the logging stream
  `static void`
  `setAdditionalWriter(PrintWriter pw)`
  `static void`
  `setCurrentTest(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 void`
  `setTrace(boolean b)`
  turns on/off debugging.
  `static void`
  `sleep(int s)`
  pauses the calling thread for the specified number of milliseconds
  `static void`
  `sleepMsec(int s)`
  pauses the calling thread for the specified number of milliseconds
  `static void`
  `sleepSec(int s)`
  pauses the calling thread for the specified number of seconds
  `static String`
  `srcToDist(String src)`
  `static Properties`
  `strToProps(String strProps)`
  `static String`
  `toEncodedString(Properties args)`
  `static void`
  `writeObject(TestReportInfo info)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### traceflag

    public static boolean traceflag

  - ### sTestName

    public static String sTestName

  - ### EMPTY_STRING_ARRAY

    public static final String[] EMPTY_STRING_ARRAY

  - ### VM_UNDER_TEST

    public static final int VM_UNDER_TEST
    See Also:
      - Constant Field Values

  - ### VM_HARNESS

    public static final int VM_HARNESS
    See Also:
      - Constant Field Values

  - ### VM_JAVATEST

    public static final int VM_JAVATEST
    See Also:
      - Constant Field Values

  - ### DEBUG_OUTPUT_LEVEL

    public static final int DEBUG_OUTPUT_LEVEL
    See Also:
      - Constant Field Values

  - ### NORMAL_OUTPUT_LEVEL

    public static final int NORMAL_OUTPUT_LEVEL
    See Also:
      - Constant Field Values

  - ### ERROR_STREAM

    public static final int ERROR_STREAM
    See Also:
      - Constant Field Values

  - ### OUTPUT_STREAM

    public static final int OUTPUT_STREAM
    See Also:
      - Constant Field Values

  - ### NEW_LINE

    public static String NEW_LINE

  - ### iWhereAreWe

    public static int iWhereAreWe

  - ### harnessDebug

    public static boolean harnessDebug

  - ### MILLI

    public static final int MILLI
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### TestUtil

    public TestUtil()

- ## Method Details

  - ### logHarnessDebug

    public static void logHarnessDebug(String s)
    used by harness to log debug output to the standard output stream
    Parameters:
      `s` - the output string

  - ### logHarness

    public static void logHarness(String s, Throwable t)
    used 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

    public static void logHarness(String s)

  - ### getProperties

    public static Properties getProperties()
    This method returns the properties object
    Returns:
      the properties object

  - ### getProperty

    public static String getProperty(String s)
    This method returns the property value for the appropriate property key
    Parameters:
      `s` - the property name
    Returns:
      the property value

  - ### getProperty

    public static String getProperty(String s, String defaultValue)
    This method returns the property value for the appropriate property key
    Parameters:
      `s` - the property name
    Returns:
      the property value

  - ### getProperty

    public static String getProperty(Properties props, String key)
    Reads 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

  - ### getProperty

    public static String getProperty(Properties props, String key, String defaultValue)
    Reads 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

  - ### getSystemProperty

    public static String getSystemProperty(String key)
    Wrapper for System.getProperty(String) that logs missing properties
    Parameters:
      `key` - the property key
    Returns:
      the property value

  - ### getSystemProperty

    public static String getSystemProperty(String key, String def)

  - ### getTransactionStatus

    public static String getTransactionStatus(int status)
    returns 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

  - ### printTransactionStatus

    public 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

  - ### sleepSec

    public static void sleepSec(int s)
    pauses the calling thread for the specified number of seconds
    Parameters:
      `s` - number of seconds

  - ### sleep

    public static void sleep(int s)
    pauses the calling thread for the specified number of milliseconds
    Parameters:
      `s` - number of milliseconds

  - ### sleepMsec

    public static void sleepMsec(int s)
    pauses the calling thread for the specified number of milliseconds
    Parameters:
      `s` - number of milliseconds

  - ### flushStream

    public static void flushStream()

  - ### writeObject

    public static void writeObject(TestReportInfo info)

  - ### init

    public static void init(Properties p) throws RemoteLoggingInitException
    This 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

  - ### initJavaTest

    public static void initJavaTest()

  - ### setAdditionalWriter

    public static void setAdditionalWriter(PrintWriter pw)

  - ### initNoLogging

    public static void initNoLogging(Properties p)
    This static method must be called once by a VM which does not rely upon any remote logging. param p properties containing harness trace flag

  - ### initClient

    public static void initClient(Properties p)
    This 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

  - ### setCurrentTest

    public static void setCurrentTest(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.
    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

  - ### logMsg

    public static void logMsg(String s)
    prints 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

  - ### logMsg

    public static void logMsg(String s, Throwable t)
    prints 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*

  - ### setTrace

    public 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.

  - ### logTrace

    public static void logTrace(String s)
    prints 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

  - ### logTrace

    public static void logTrace(String s, Throwable t)
    Prints 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

  - ### logErr

    public static void logErr(String s, Throwable e)
    prints 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

  - ### logErr

    public static void logErr(String s)
    prints 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

  - ### list

    public static void list(Properties p)
    prints the contents of a properties object to the logging stream
    Parameters:
      `p` - properties to print

  - ### printStackTrace

    public static void printStackTrace(Throwable e)
    prints the stacktrace of a Throwable to the logging stream
    Parameters:
      `e` - exception to print the stacktrace of

  - ### printStackTraceToString

    public static String printStackTraceToString(Throwable e)
    prints the stacktrace of a Throwable to a string
    Parameters:
      `e` - exception to print the stacktrace of

  - ### separator2

    public static void separator2()
    prints a line of asterisks to the logging stream

  - ### separator1

    public static void separator1()
    prints a line of dashes to the logging stream

  - ### getResponse

    public static String getResponse(URLConnection connection) throws IOException
    Convience method to handle sucking in the data from a connection.
    Throws:
      `IOException`

  - ### getResponseProperties

    public static Properties getResponseProperties(String string) throws IOException
    Loads any properties that might be in a given String.
    Throws:
      `IOException`

  - ### getResponseProperties

    public static Properties getResponseProperties(URLConnection connection) throws IOException
    One shot method to get Properties directly from a URLConnection.
    Throws:
      `IOException`

  - ### toEncodedString

    public static String toEncodedString(Properties args)

  - ### sendPostData

    public static URLConnection sendPostData(Properties p, URL url) throws IOException
    Throws:
      `IOException`

  - ### getTableName

    public static String getTableName(String value)
    Parse 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

    public static String srcToDist(String src)

  - ### replaceLastSrc

    public static String replaceLastSrc(String src, String replacement)

  - ### getDistString

    public static String getDistString()

  - ### getRelativePath

    public static String getRelativePath(String oldVal)

  - ### strToProps

    public static Properties strToProps(String strProps)

  - ### printProperties

    public static void printProperties(Properties props)