@Test
  public void testCompare() throws Exception {
    QueryDataSet actualDataSet = new QueryDataSet(getConnection());

    liquiBase.update(null);
    actualDataSet.addTable(
        TABLE_NAME, "SELECT TRIGGER_NAME from " + TABLE_NAME + " WHERE table_name = 'TRIGGERTEST'");
    loadedDataSet = getDataSet();

    Assertion.assertEquals(loadedDataSet, actualDataSet);
  }
Example #2
0
 /**
  * Print the contents of the given tableName to system.out<br>
  * <br>
  * Call this from any {@link BaseContextSensitiveTest} child by:
  * TestUtil.printOutTableContents(getConnection(), "encounter");
  *
  * @param sqlConnection the connection to use
  * @param tableNames the name(s) of the table(s) to print out
  * @throws Exception
  */
 public static void printOutTableContents(Connection sqlConnection, String... tableNames)
     throws Exception {
   for (String tableName : tableNames) {
     System.out.println("The contents of table: " + tableName);
     IDatabaseConnection connection = new DatabaseConnection(sqlConnection);
     DatabaseConfig config = connection.getConfig();
     config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqldbDataTypeFactory());
     QueryDataSet outputSet = new QueryDataSet(connection);
     outputSet.addTable(tableName);
     FlatXmlDataSet.write(outputSet, System.out);
   }
 }
Example #3
0
  public static void main(String[] args) throws Exception {
    Class.forName("com.mysql.jdbc.Driver");
    Connection connection =
        DriverManager.getConnection("jdbc:mysql://localhost:3306/dbunit", "root", "1234");
    IDatabaseConnection databaseConnection = new DatabaseConnection(connection);

    // 根据SQL导出部分数据
    QueryDataSet queryDataSet = new QueryDataSet(databaseConnection);
    queryDataSet.addTable("users", "select password from users where id = 10");
    FlatXmlDataSet.write(queryDataSet, new FileOutputStream("dbunitXMLConditation.xml"));

    // 导出整个库的数据
    IDataSet dataSet = databaseConnection.createDataSet();
    // 将dbunit表中的数据写入到dbunitXML.xml文件中
    FlatXmlDataSet.write(dataSet, new FileOutputStream("dbunitXML.xml"));
    FlatDtdDataSet.write(dataSet, new FileOutputStream("dbunitXML.dtd"));
  }