Пример #1
0
  /**
   * Performs a preformatted statement or group of statements and throws if the result does not
   * match the expected one.
   *
   * @param line start line in the script file for this test
   * @param stat Statement object used to access the database
   * @param sourceName Identifies the script which failed
   * @param s Contains the type, expected result and SQL for the test
   */
  static void test(Statement stat, String s, String sourceName, int line) {

    // maintain the interface for this method
    HsqlArrayList section = new HsqlArrayList();

    section.add(s);
    testSection(stat, section, sourceName, line);
  }
Пример #2
0
  /**
   * Runs a preformatted script.
   *
   * <p>Where a result set is required, each line in the script will be interpreted as a seperate
   * expected row in the ResultSet returned by the query. Within each row, fields should be
   * delimited using either comma (the default), or a user defined delimiter which should be
   * specified in the System property TestUtilFieldDelimiter
   *
   * @param aConnection Connection object for the database
   * @param sourceName Identifies the script which failed
   * @param inReader Source of commands to be tested
   */
  public static void testScript(Connection aConnection, String sourceName, Reader inReader)
      throws SQLException, IOException {

    Statement statement = aConnection.createStatement();
    LineNumberReader reader = new LineNumberReader(inReader);
    LineGroupReader sqlReader = new LineGroupReader(reader);
    int startLine = 0;

    System.out.println("Opened test script file: " + sourceName);

    /**
     * we read the lines from the start of one section of the script "/*" until the start of the
     * next section, collecting the lines in the list. When a new section starts, we pass the list
     * of lines to the test method to be processed.
     */
    try {
      while (true) {
        HsqlArrayList section = sqlReader.getSection();

        startLine = sqlReader.getStartLineNumber();

        if (section.size() == 0) {
          break;
        }

        testSection(statement, section, sourceName, startLine);
      }

      statement.close();

      // The following catch blocks are just to report the source location
      // of the failure.
    } catch (SQLException se) {
      System.out.println(
          "Error encountered at command beginning at " + sourceName + ':' + startLine);

      throw se;
    } catch (RuntimeException re) {
      System.out.println(
          "Error encountered at command beginning at " + sourceName + ':' + startLine);

      throw re;
    }

    System.out.println("Processed " + reader.getLineNumber() + " lines from " + sourceName);
  }