org.teiid.test.util
Class TestResultSetUtil

java.lang.Object
  extended by org.teiid.test.util.TestResultSetUtil

public class TestResultSetUtil
extends java.lang.Object

TestResultSetUtil was built in order to override the #printThrowable(Throwable, PrintStream) method in order to call out.print instead of out.println This is because the println adds a line terminator, and when the result file is in turn used for comparison it fails because of the line terminator.

Since:

Field Summary
static int DEFAULT_MAX_COL_WIDTH
           
 
Constructor Summary
TestResultSetUtil()
           
 
Method Summary
static java.util.List compareThrowable(java.lang.Throwable t, java.lang.String query, java.io.File expectedResultsFile, boolean printToConsole)
           
static java.io.PrintStream getPrintStream(java.io.OutputStream resultsOutput, java.io.BufferedReader expectedResultsInput, java.io.PrintStream defaultPrintStream)
          Gets a PrintStream implementation that uses the input parameters as underlying streams
static java.util.List getUnequalLines(java.io.PrintStream out)
           
static void printBatchedUpdateCounts(int[] counts, java.io.PrintStream out)
           
static void printResultSet(java.sql.ResultSet rs, java.lang.String query, int maxColWidth, boolean printMetadata, java.io.PrintStream out)
          Prints the ResultSet (and optionally the ResultSetMetaData) to a stream.
static void printResultSetMetadata(java.sql.ResultSetMetaData rsmd, java.io.PrintStream out)
          Prints the ResultSetMetaData values for each column
static void printThrowable(java.lang.Throwable t, java.lang.String sql, java.io.PrintStream out)
           
static void printUpdateCount(int updateCount, java.io.PrintStream out)
           
static java.util.List writeAndCompareResultSet(java.sql.ResultSet rs, java.lang.String query, int maxColWidth, boolean printMetadata, java.io.File resultsFile, java.io.File expectedResultsFile, boolean printToConsole)
          Compares the actual results with the expected results.
static java.util.List writeAndCompareResultSet(java.sql.ResultSet rs, java.lang.String query, int maxColWidth, boolean printMetadata, java.io.OutputStream resultsOutput, java.io.BufferedReader expectedResultsInput, java.io.PrintStream defaultPrintStream)
          Compares the actual results with the expected results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_COL_WIDTH

public static final int DEFAULT_MAX_COL_WIDTH
See Also:
Constant Field Values
Constructor Detail

TestResultSetUtil

public TestResultSetUtil()
Method Detail

compareThrowable

public static java.util.List compareThrowable(java.lang.Throwable t,
                                              java.lang.String query,
                                              java.io.File expectedResultsFile,
                                              boolean printToConsole)
                                       throws java.io.IOException,
                                              java.sql.SQLException
Throws:
java.io.IOException
java.sql.SQLException

printThrowable

public static void printThrowable(java.lang.Throwable t,
                                  java.lang.String sql,
                                  java.io.PrintStream out)

getPrintStream

public static java.io.PrintStream getPrintStream(java.io.OutputStream resultsOutput,
                                                 java.io.BufferedReader expectedResultsInput,
                                                 java.io.PrintStream defaultPrintStream)
Gets a PrintStream implementation that uses the input parameters as underlying streams

Parameters:
resultsOutput - an output file for result data. If null, results will only be written to the defaul stream.
expectedResultsInput - the reader for expected data. If null, actual data is never compared against expected results.
defaultPrintStream - if not null, this utility will always write to this stream. Typically this is System.out
Returns:
the single PrintStream that wraps all the input streams for writing and comparison.
Since:
4.2

writeAndCompareResultSet

public static java.util.List writeAndCompareResultSet(java.sql.ResultSet rs,
                                                      java.lang.String query,
                                                      int maxColWidth,
                                                      boolean printMetadata,
                                                      java.io.File resultsFile,
                                                      java.io.File expectedResultsFile,
                                                      boolean printToConsole)
                                               throws java.io.IOException,
                                                      java.sql.SQLException
Compares the actual results with the expected results.

Parameters:
rs - the result of the execution
maxColWidth - the max width a column is allowed to have
printMetadata - writes the metadata if true
resultsFile - output file to which the results will be written. Can be null.
expectedResultsFile - expected results file with which to compare the results. Can be null.
printToConsole - writes to System.out if true
Returns:
The List of line numbers which differ between the actual and expected results.
Throws:
java.io.IOException
java.sql.SQLException
Since:
4.3

writeAndCompareResultSet

public static java.util.List writeAndCompareResultSet(java.sql.ResultSet rs,
                                                      java.lang.String query,
                                                      int maxColWidth,
                                                      boolean printMetadata,
                                                      java.io.OutputStream resultsOutput,
                                                      java.io.BufferedReader expectedResultsInput,
                                                      java.io.PrintStream defaultPrintStream)
                                               throws java.sql.SQLException
Compares the actual results with the expected results.

Parameters:
rs - the result of the execution
maxColWidth - the max width a column is allowed to have
printMetadata - writes the metadata if true
resultsOutput - OutputStream to which the results will be written. Can be null.
expectedResultsInput - reader with which the expected results are read. Can be null.
defaultPrintStream - the default stream to which to write the results. Can be null.
Returns:
The List of line numbers which differ between the actual and expected results.
Throws:
java.sql.SQLException
Since:
4.3

getUnequalLines

public static java.util.List getUnequalLines(java.io.PrintStream out)

printUpdateCount

public static void printUpdateCount(int updateCount,
                                    java.io.PrintStream out)

printBatchedUpdateCounts

public static void printBatchedUpdateCounts(int[] counts,
                                            java.io.PrintStream out)

printResultSet

public static void printResultSet(java.sql.ResultSet rs,
                                  java.lang.String query,
                                  int maxColWidth,
                                  boolean printMetadata,
                                  java.io.PrintStream out)
                           throws java.sql.SQLException
Prints the ResultSet (and optionally the ResultSetMetaData) to a stream. If you're using the stream from getPrintStream(), then you can also compare data with expected results.

Parameters:
rs -
maxColWidth - the max width a column is allowed to have. The column will be wider than this value only if the column name is longer.
printMetadata -
out -
Throws:
java.sql.SQLException
Since:
4.2

printResultSetMetadata

public static void printResultSetMetadata(java.sql.ResultSetMetaData rsmd,
                                          java.io.PrintStream out)
                                   throws java.sql.SQLException
Prints the ResultSetMetaData values for each column

Parameters:
rsmd -
out -
Throws:
java.sql.SQLException
Since:
4.2


Copyright © 2011. All Rights Reserved.