本文整理汇总了Java中org.dbunit.dataset.IDataSet.getTable方法的典型用法代码示例。如果您正苦于以下问题:Java IDataSet.getTable方法的具体用法?Java IDataSet.getTable怎么用?Java IDataSet.getTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dbunit.dataset.IDataSet
的用法示例。
在下文中一共展示了IDataSet.getTable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testJsonLoaderLoadUsingProperResource
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testJsonLoaderLoadUsingProperResource() throws Exception {
// WHEN
final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.jsonLoader();
// THEN
assertThat(loader, notNullValue());
// WHEN
final IDataSet dataSet = loader.load(getFile("test-data.json"));
// THEN
assertThat(dataSet, notNullValue());
final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
assertThat(tableNames.size(), equalTo(2));
assertThat(tableNames, hasItems("JSON_TABLE_1", "JSON_TABLE_2"));
final ITable table1 = dataSet.getTable("JSON_TABLE_1");
assertThat(table1.getRowCount(), equalTo(3));
final ITable table2 = dataSet.getTable("JSON_TABLE_2");
assertThat(table2.getRowCount(), equalTo(1));
}
示例2: testYamlLoaderLoadUsingProperResource
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testYamlLoaderLoadUsingProperResource() throws Exception {
// WHEN
final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.yamlLoader();
// THEN
assertThat(loader, notNullValue());
// WHEN
final IDataSet dataSet = loader.load(getFile("test-data.yaml"));
// THEN
assertThat(dataSet, notNullValue());
final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
assertThat(tableNames.size(), equalTo(2));
assertThat(tableNames, hasItems("YAML_TABLE_1", "YAML_TABLE_2"));
final ITable table1 = dataSet.getTable("YAML_TABLE_1");
assertThat(table1.getRowCount(), equalTo(3));
final ITable table2 = dataSet.getTable("YAML_TABLE_2");
assertThat(table2.getRowCount(), equalTo(1));
}
示例3: testXmlLoaderLoadUsingProperResource
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testXmlLoaderLoadUsingProperResource() throws Exception {
// WHEN
final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xmlLoader();
// THEN
assertThat(loader, notNullValue());
// WHEN
final IDataSet dataSet = loader.load(getFile("test-data.xml"));
// THEN
assertThat(dataSet, notNullValue());
final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
assertThat(tableNames.size(), equalTo(2));
assertThat(tableNames, hasItems("XML_TABLE_1", "XML_TABLE_2"));
final ITable table1 = dataSet.getTable("XML_TABLE_1");
assertThat(table1.getRowCount(), equalTo(3));
final ITable table2 = dataSet.getTable("XML_TABLE_2");
assertThat(table2.getRowCount(), equalTo(1));
}
示例4: file
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
@Ignore("Somehow the given zip file (xlsx) is invalid, even Excel opens it without issues")
public void testXlsxLoaderLoadUsingProperResource() throws Exception {
// WHEN
final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader();
// THEN
assertThat(loader, notNullValue());
// WHEN
final IDataSet dataSet = loader.load(getFile("test-data.xlsx"));
// THEN
assertThat(dataSet, notNullValue());
final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
assertThat(tableNames.size(), equalTo(2));
assertThat(tableNames, hasItems("XLS_TABLE_1", "XLS_TABLE_2"));
final ITable table1 = dataSet.getTable("XLS_TABLE_1");
assertThat(table1.getRowCount(), equalTo(3));
final ITable table2 = dataSet.getTable("XLS_TABLE_2");
assertThat(table2.getRowCount(), equalTo(1));
}
示例5: testCsvLoaderLoadUsingProperResource
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testCsvLoaderLoadUsingProperResource() throws Exception {
// WHEN
final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.csvLoader();
// THEN
assertThat(loader, notNullValue());
// WHEN
final IDataSet dataSet = loader.load(getFile("test-data"));
// THEN
assertThat(dataSet, notNullValue());
final List<String> tableNames = Arrays.asList(dataSet.getTableNames());
assertThat(tableNames.size(), equalTo(2));
assertThat(tableNames, hasItems("CSV_TABLE_1", "CSV_TABLE_2"));
final ITable table1 = dataSet.getTable("CSV_TABLE_1");
assertThat(table1.getRowCount(), equalTo(3));
final ITable table2 = dataSet.getTable("CSV_TABLE_2");
assertThat(table2.getRowCount(), equalTo(1));
}
示例6: 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();
}
}
示例7: testDefaultBehavior
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testDefaultBehavior() throws Exception {
ClikeFlatXmlDataSetLoader dataSetLoader = new ClikeFlatXmlDataSetLoader();
IDataSet dataset = dataSetLoader.loadDataSet(this.getClass(), "clike-flat-xmldataset.xml");
ITable sampleTable = dataset.getTable("Sample");
// sleep 10 millis, to 'now' is later for sampleTable.currentValue
Thread.sleep(10);
Date now = new Date();
assertThat(sampleTable.getValue(0, "nullValue"), is(nullValue()));
assertThat(sampleTable.getValue(0, "currentValue"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(0, "futureValue"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(0, "futureValue2"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(0, "futureValue3"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(0, "pastValue"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(0, "pastValue2"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(0, "pastValue3"), is(instanceOf(Date.class)));
// default dateflowSize is 2, not replace value to date.class
assertThat(sampleTable.getValue(0, "optionValue"), is(instanceOf(String.class)));
assertThat((Date)sampleTable.getValue(0, "currentValue"), lessThan(now));
assertThat((Date)sampleTable.getValue(0, "futureValue"), greaterThan(now));
assertThat((Date)sampleTable.getValue(0, "futureValue2"), greaterThan((Date)sampleTable.getValue(0, "futureValue")));
assertThat((Date)sampleTable.getValue(0, "futureValue3"), greaterThan((Date)sampleTable.getValue(0, "futureValue2")));
assertThat((Date)sampleTable.getValue(0, "pastValue"), lessThan((Date)sampleTable.getValue(0, "currentValue")));
assertThat((Date)sampleTable.getValue(0, "pastValue2"), lessThan((Date)sampleTable.getValue(0, "pastValue")));
assertThat((Date)sampleTable.getValue(0, "pastValue3"), lessThan((Date)sampleTable.getValue(0, "pastValue2")));
}
示例8: testCustomKey
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testCustomKey() throws Exception {
ClikeFlatXmlDataSetLoader dataSetLoader = new ClikeFlatXmlDataSetLoader();
dataSetLoader.setCurrentDateKey("NOW");
dataSetLoader.setFutureDateKey("FUTURE");
dataSetLoader.setPastDateKey("PAST");
dataSetLoader.setNullKey("NULL");
IDataSet dataset = dataSetLoader.loadDataSet(this.getClass(), "clike-flat-xmldataset.xml");
ITable sampleTable = dataset.getTable("Sample");
Date now = new Date();
assertThat(sampleTable.getValue(1, "nullValue"), is(nullValue()));
assertThat(sampleTable.getValue(1, "currentValue"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(1, "futureValue"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(1, "futureValue2"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(1, "futureValue3"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(1, "pastValue"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(1, "pastValue2"), is(instanceOf(Date.class)));
assertThat(sampleTable.getValue(1, "pastValue3"), is(instanceOf(Date.class)));
assertThat((Date)sampleTable.getValue(1, "currentValue"), lessThan(now));
assertThat((Date)sampleTable.getValue(1, "futureValue"), greaterThan(now));
assertThat((Date)sampleTable.getValue(1, "futureValue2"), greaterThan((Date)sampleTable.getValue(1, "futureValue")));
assertThat((Date)sampleTable.getValue(1, "futureValue3"), greaterThan((Date)sampleTable.getValue(1, "futureValue2")));
assertThat((Date)sampleTable.getValue(1, "pastValue"), lessThan((Date)sampleTable.getValue(1, "currentValue")));
assertThat((Date)sampleTable.getValue(1, "pastValue2"), lessThan((Date)sampleTable.getValue(1, "pastValue")));
assertThat((Date)sampleTable.getValue(1, "pastValue3"), lessThan((Date)sampleTable.getValue(1, "pastValue2")));
}
示例9: assertDatabaseState
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
/**
* Asserts that the database is in a given state.
*
* @param expectedState file name of dataset holding the expected state
*/
@SuppressWarnings("deprecation")
protected void assertDatabaseState(String expectedState) throws Exception {
// Fetch database data after executing your code
IDataSet databaseDataSet = getConnection().createDataSet();
IDataSet initialDataSet = new FlatXmlDataSet(new File(expectedState), false, true);
// compare tables
for (ITable table: initialDataSet.getTables()) {
ITable actualTable = databaseDataSet.getTable(table.getTableMetaData().getTableName());
ITable filteredTable = DefaultColumnFilter.includedColumnsTable(actualTable,
table.getTableMetaData().getColumns());
Assertion.assertEquals(new SortedTable(table), new SortedTable(filteredTable));
}
}
示例10: assertEqualDatasets
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
/**
* Asserts that the two database states are equal.
*
* @param expectedState file name of dataset holding the expected state
* @param actualState file name of dataset holding the actual state
*/
@SuppressWarnings("deprecation")
protected void assertEqualDatasets(File expectedState, File actualState) throws Exception {
IDataSet expected = new FlatXmlDataSet(expectedState, false, true);
IDataSet actual = new FlatXmlDataSet(actualState, false, true);
// compare tables
for (ITable table: expected.getTables()) {
ITable actualTable = actual.getTable(table.getTableMetaData().getTableName());
Assertion.assertEquals(new SortedTable(table), new SortedTable(actualTable));
}
}
示例11: 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();
}
}
示例12: testDataflowSize
import org.dbunit.dataset.IDataSet; //导入方法依赖的package包/类
@Test
public void testDataflowSize() throws Exception {
ClikeFlatXmlDataSetLoader dataSetLoader = new ClikeFlatXmlDataSetLoader();
IDataSet dataset = dataSetLoader.loadDataSet(this.getClass(), "clike-flat-xmldataset.xml");
ITable sampleTable = dataset.getTable("Sample");
// default dateflowSize is 2, not replace value to date.class
assertThat(sampleTable.getValue(0, "optionValue"), is(instanceOf(String.class)));
dataSetLoader.setDateflowSize(3);
IDataSet dataset2 = dataSetLoader.loadDataSet(this.getClass(), "clike-flat-xmldataset.xml");
ITable sampleTable2 = dataset2.getTable("Sample");
// dateflowSize is 3, replace value to date.class
assertThat(sampleTable2.getValue(0, "optionValue"), is(instanceOf(Date.class)));
assertThat((Date)sampleTable2.getValue(0, "optionValue"), greaterThan((Date)sampleTable.getValue(0, "futureValue3")));
}