本文整理匯總了Java中org.dbunit.dataset.IDataSet.getTableNames方法的典型用法代碼示例。如果您正苦於以下問題:Java IDataSet.getTableNames方法的具體用法?Java IDataSet.getTableNames怎麽用?Java IDataSet.getTableNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dbunit.dataset.IDataSet
的用法示例。
在下文中一共展示了IDataSet.getTableNames方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dropTables
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
public static void dropTables(String filePath) throws DataSetException,
IOException, SQLException {
IDataSet tablesToDelete = new FlatXmlDataSetBuilder().build(new File(
filePath));
String[] tableNames = tablesToDelete.getTableNames();
Statement stmt = conn.createStatement();
String queryString = "DROP TABLE %s CASCADE";
for (int i = tableNames.length - 1; i >= 0; i--) {
// first drop constraints to the table
deleteConstraints(tableNames[i]);
// now drop the table itself
String tableName = tableNames[i];
try {
String query = String.format(queryString, tableName);
stmt.executeUpdate(query);
System.out.println(query);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
stmt.close();
}
示例2: testLoadDataSet_multiInputStreams
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
/**
* Test the loading of a data set out of 2 files:
* this will load the LessColumnsLastDataSet.xml and LessColumnsFirstDataSet.xml dataset
*/
@Test
public void testLoadDataSet_multiInputStreams() throws Exception {
File file1 = toFile(getClass().getResource("LessColumnsLastDataSet.xml"));
File file2 = toFile(getClass().getResource("LessColumnsFirstDataSet.xml"));
MultiSchemaDataSet result = multiSchemaXmlDataSetReader.readDataSetXml(file1, file2);
// there should be 1 dataset for the default schema A
assertLenientEquals(new String[]{"SCHEMA_A"}, result.getSchemaNames());
// the dataset should contain 4 tables with the same name
IDataSet dataSet = result.getDataSetForSchema("SCHEMA_A");
String[] actual = dataSet.getTableNames();
assertLenientEquals(new String[]{"TABLE_A"}, actual);
assertEquals(4, dataSet.getTable("TABLE_A").getRowCount());
}
示例3: assertDataAfterMigration
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
protected void assertDataAfterMigration(DatabaseConnection connection)
throws Exception {
final IDataSet expectedSet = loadDataSet(getExpectedDataset());
for (final String tableName : expectedSet.getTableNames()) {
assertTable(connection, expectedSet, tableName);
}
}
示例4: compareNotExpectedWithActual
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
/**
* Vergelijkt een actuele dataset met een niet-verwachte dataset. Alle records in de niet-verwachte dataset dienen
* niet voor te komen in de actuele dataset. Tabellen/records die niet in de not-expected set voorkomen worden
* genegeerd.
* <p>
* @param notExpected De not-expected dataset.
* @throws DatabaseUnitException on error
* @throws SQLException on error
*/
protected void compareNotExpectedWithActual(final IDataSet notExpected) throws DatabaseUnitException, SQLException {
if (notExpected == null) {
throw new IllegalArgumentException("Argument 'notExpected' is null");
}
final IDatabaseConnection connection = createConnection();
try {
final IDataSet actual = createActualSet(connection);
final String[] notExpTableNames = notExpected.getTableNames();
for (final String currentTableName : notExpTableNames) {
final ITable expTable = notExpected.getTable(currentTableName);
final ITable actTable = actual.getTable(currentTableName);
final ITable filteredActTable = new RowFilterTable(actTable, new PrimaryKeyRowFilter(expTable));
final int actualRowCount = filteredActTable.getRowCount();
if (0 != actualRowCount) {
final String foutmelding =
"Er zijn "
+ actualRowCount
+ " records gevonden in de tabel "
+ currentTableName.toUpperCase()
+ " die voorkomen in de NOT EXPECTED dataset";
LOG.error(foutmelding);
LOG.error("****** De volgende 'NotExpected' records zijn aangetroffen in de database:");
LOG.error(FORMATTER.format(filteredActTable));
Assert.fail(foutmelding + " (zie ERROR-log voor details)");
}
}
} finally {
connection.close();
}
}
示例5: execute
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
@Override
public void execute(IDatabaseConnection connection, IDataSet dataSet) throws DatabaseUnitException, SQLException {
String[] tables = dataSet.getTableNames();
Statement statement = connection.getConnection().createStatement();
for (String table : tables) {
statement.execute("TRUNCATE TABLE " + table + " RESTART IDENTITY AND COMMIT NO CHECK");
}
}
示例6: compare
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
public void compare(final IDataSet currentDataSet, final IDataSet expectedDataSet, final AssertionErrorCollector errorCollector)
throws DatabaseUnitException {
if (expectedDataSet.getTableNames().length == 0) {
shouldBeEmpty(currentDataSet, errorCollector);
} else {
compareContent(currentDataSet, expectedDataSet, errorCollector);
}
}
示例7: shouldBeEmpty
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
private void shouldBeEmpty(final IDataSet dataSet, final AssertionErrorCollector errorCollector) throws DatabaseUnitException {
for (final String tableName : dataSet.getTableNames()) {
final int rowCount = dataSet.getTable(tableName).getRowCount();
if (rowCount != 0) {
errorCollector.collect(tableName + " was expected to be empty, but has <" + rowCount + "> entries.");
}
}
}
示例8: compareExpectedWithActual
import org.dbunit.dataset.IDataSet; //導入方法依賴的package包/類
/**
* Vergelijkt een actuele dataset met de verwachte dataset. Alle records in de verwachte dataset dienen ook voor te
* komen in de actuele dataset. Tabellen die niet in de expected set voorkomen worden genegeerd.
* <p>
* @param expected De expected dataset.
* @throws DatabaseUnitException on error
* @throws SQLException on error
*/
protected void compareExpectedWithActual(final IDataSet expected) throws SQLException, DatabaseUnitException {
if (expected == null) {
throw new IllegalArgumentException("Argument 'expected' is null");
}
final IDatabaseConnection connection = createConnection();
try {
final IDataSet actual = createActualSet(connection);
final String[] expTableNames = expected.getTableNames();
for (final String currentTableName : expTableNames) {
// prepareer verwachtte tabel
final ITable expTable = expected.getTable(currentTableName);
final Column[] columnsExp = expTable.getTableMetaData().getColumns();
// Zoek naar kolommen met waarde: [NOTNULLCHECK] zodat deze geexclude worden. Deze worden later per rij
// gecontroleerd
final Set<String> excludeButNotEmptyColumnsSet = new HashSet<>();
final Map<Integer, String> excludeButNotEmptyColumns = new HashMap<>();
for (final Column column : columnsExp) {
for (int i = 0; i < expTable.getRowCount(); i++) {
final Object value = expTable.getValue(i, column.getColumnName());
if (value != null && value.toString().equals("[NOTNULLCHECK]")) {
excludeButNotEmptyColumnsSet.add(column.getColumnName());
excludeButNotEmptyColumns.put(i, column.getColumnName());
}
}
}
final String[] excludeButNotEmptyColumnsArray = excludeButNotEmptyColumnsSet.toArray(new String[0]);
final ITable filteredTableExp = DefaultColumnFilter.excludedColumnsTable(expTable, excludeButNotEmptyColumnsArray);
final ITable sortedExp = new SortedTable(filteredTableExp);
final ITable currentTimestampColumnFilteredExp = new ColumnFilterTable(sortedExp, new CurrentTimestampColumnFilter());
// prepareer actuele tabel
final ITable actTable = actual.getTable(currentTableName);
final ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(actTable, excludeButNotEmptyColumnsArray);
final ITable sortedActTable = new SortedTable(filteredTable);
final ITable primaryKeyFilteredActTable = new RowFilterTable(sortedActTable, new PrimaryKeyRowFilter(expTable));
final ITable currentTimestampRowFilteredActTable = new RowFilterTable(primaryKeyFilteredActTable, new CurrentTimestampRowFilter(expTable));
final ITable currentTimestampColumnFilteredActTable =
new ColumnFilterTable(currentTimestampRowFilteredActTable, new CurrentTimestampColumnFilter());
try {
ASSERT.assertEquals(currentTimestampColumnFilteredExp, currentTimestampColumnFilteredActTable);
if (excludeButNotEmptyColumns.size() > 0) {
for (int rij = 0; rij < actTable.getRowCount(); rij++) {
final String excludeColumName = excludeButNotEmptyColumns.get(rij);
if (excludeColumName != null && actTable.getValue(rij, excludeColumName) == null) {
LOG.error("****** NotNullCheck column was leeg in actual result: " + excludeColumName);
throw new AssertionFailedError();
}
}
}
} catch (final AssertionFailedError assertionError) {
LOG.error("****** De volgende records zijn aangetroffen in de database:");
LOG.error(FORMATTER.format(sortedActTable));
LOG.error("****** Terwijl minimaal de volgende EXPECTED records verwacht worden:");
LOG.error(FORMATTER.format(sortedExp));
throw assertionError;
}
}
} finally {
connection.close();
}
}