コード例 #1
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
 /**
  * Appends the values of the given row to the result
  *
  * @param row The row, not null
  * @param result The result to append to, not null
  */
 protected void appendRow(Row row, StringBuilder result) {
   for (Column column : row.getColumns()) {
     result.append(objectFormatter.format(column.getValue()));
     result.append(", ");
   }
   result.setLength(result.length() - 2);
 }
コード例 #2
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
 /**
  * Appends the column names of the given row to the result
  *
  * @param row The row, not null
  * @param result The result to append to, not null
  */
 protected void appendColumnNames(Row row, StringBuilder result) {
   for (Column column : row.getColumns()) {
     result.append(column.getName());
     result.append(", ");
   }
   result.setLength(result.length() - 2);
 }
コード例 #3
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
 /**
  * Appends the missing tables of the given schema difference to the result
  *
  * @param schemaDifference The difference, not null
  * @param result The result to append to, not null
  */
 protected void appendMissingTableDifferences(
     SchemaDifference schemaDifference, StringBuilder result) {
   for (Table missingTable : schemaDifference.getMissingTables()) {
     result.append("\nFound missing table ");
     result.append(schemaDifference.getSchema().getName());
     result.append(".");
     result.append(missingTable.getName());
   }
 }
コード例 #4
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
 /**
  * Appends the missing rows of the given table difference to the result
  *
  * @param tableDifference The difference, not null
  * @param result The result to append to, not null
  */
 protected void appendMissingRowDifferences(
     TableDifference tableDifference, StringBuilder result) {
   for (Row missingRow : tableDifference.getMissingRows()) {
     result.append("\n  Missing row:\n  ");
     appendColumnNames(missingRow, result);
     result.append("\n  ");
     appendRow(missingRow, result);
     result.append("\n");
   }
 }
コード例 #5
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
  /**
   * Formats the assertion failed message for the given difference.
   *
   * @param schemaDifference The difference, not null
   * @return The message, not null
   */
  protected String generateErrorMessage(SchemaDifference schemaDifference) {
    StringBuilder result =
        new StringBuilder(
            "Assertion failed. Differences found between the expected data set and actual database content.");

    String schemaName = schemaDifference.getSchema().getName();
    appendMissingTableDifferences(schemaDifference, result);
    appendTableDifferences(schemaDifference, result);
    result.append("\n\nActual database content:\n\n");
    appendSchemaContent(schemaDifference.getSchema(), schemaDifference.getActualSchema(), result);
    return result.toString();
  }
コード例 #6
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
 /**
  * Appends the table differences of the given schema difference to the result
  *
  * @param schemaDifference The difference, not null
  * @param result The result to append to, not null
  */
 protected void appendTableDifferences(SchemaDifference schemaDifference, StringBuilder result) {
   for (TableDifference tableDifference : schemaDifference.getTableDifferences()) {
     Table table = tableDifference.getTable();
     if (table.isEmpty()) {
       result.append("\nExpected table to be empty but found rows for table ");
       appendTableName(schemaDifference.getSchema(), table, result);
       result.append("\n");
       continue;
     }
     result.append("\nFound differences for table ");
     appendTableName(schemaDifference.getSchema(), table, result);
     result.append(":\n");
     appendMissingRowDifferences(tableDifference, result);
     appendBestRowDifferences(tableDifference, result);
   }
 }
コード例 #7
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
  /**
   * Appends all rows and tables of the actual schema to the result. Only tables that are in the
   * expected schema will be appended.
   *
   * @param schema The expected schema, not null
   * @param actualSchema The actual schema, not null
   * @param result The result to append to, not null
   */
  protected void appendSchemaContent(Schema schema, Schema actualSchema, StringBuilder result) {
    for (Table table : schema.getTables()) {
      Table actualTable = actualSchema.getTable(table.getName());
      if (actualTable == null) {
        continue;
      }
      appendTableName(schema, actualTable, result);
      result.append("\n");

      if (actualTable.getRows().isEmpty()) {
        result.append("  <empty table>\n");
      } else {
        result.append("  ");
        appendColumnNames(actualTable.getRows().get(0), result);
        result.append("\n");
        for (Row row : actualTable.getRows()) {
          result.append("  ");
          appendRow(row, result);
          result.append("\n");
        }
      }
      result.append("\n");
    }
  }
コード例 #8
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
 /**
  * Appends the schema and table name to the result
  *
  * @param schema The schema name, not null
  * @param table The table name, not null
  * @param result The result to append to, not null
  */
 protected void appendTableName(Schema schema, Table table, StringBuilder result) {
   result.append(schema.getName());
   result.append(".");
   result.append(table.getName());
 }
コード例 #9
0
ファイル: DataSetAssert.java プロジェクト: tomdesair/unitils
  /**
   * Appends the best matching row differences of the given table difference to the result
   *
   * @param tableDifference The difference, not null
   * @param result The result to append to, not null
   */
  protected void appendBestRowDifferences(TableDifference tableDifference, StringBuilder result) {
    for (RowDifference rowDifference : tableDifference.getBestRowDifferences()) {
      result.append("\n  Different row: \n  ");
      appendColumnNames(rowDifference.getRow(), result);
      result.append("\n  ");
      appendRow(rowDifference.getRow(), result);

      result.append("\n\n  Best matching differences:  ");
      for (Column column : rowDifference.getMissingColumns()) {
        result.append("\n  Missing column ");
        result.append(column.getName());
      }
      for (ColumnDifference columnDifference : rowDifference.getColumnDifferences()) {
        result.append("\n  ");
        result.append(columnDifference.getColumn().getName());
        result.append(": ");
        result.append(objectFormatter.format(columnDifference.getColumn().getValue()));
        result.append(" <-> ");
        Column actualColumn = columnDifference.getActualColumn();
        result.append(
            objectFormatter.format(actualColumn == null ? null : actualColumn.getValue()));
      }
      result.append("\n");
    }
  }