Java Code Examples for org.dbunit.dataset.IDataSet#getTableNames()

The following examples show how to use org.dbunit.dataset.IDataSet#getTableNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSetExecutorImplTest.java    From database-rider with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLoadDatasetsAsAResourceFromClasspath() throws IOException, DataSetException {
    DataSetExecutorImpl dse = DataSetExecutorImpl.instance(new ConnectionHolder() {
        private static final long serialVersionUID = 1L;

        @Override
        public Connection getConnection() {
            return null;
        }
    });
    IDataSet iDataSetFromXml = dse.loadDataSet("/datasets/xml/users.xml");
    String[] tableNamesXml = iDataSetFromXml.getTableNames();
    assertEquals("USER", tableNamesXml[0]);
    assertEquals("TWEET", tableNamesXml[1]);
    assertEquals("FOLLOWER", tableNamesXml[2]);



    IDataSet iDataSetFromCsv = dse.loadDataSet("/datasets/csv/USER.csv");
    String[] tableNamesCsv = iDataSetFromCsv.getTableNames();
    assertEquals("FOLLOWER", tableNamesCsv[0]);
    assertEquals("TWEET", tableNamesCsv[1]);
    assertEquals("USER", tableNamesCsv[2]);
}
 
Example 2
Source File: DataSetExecutorImplTest.java    From database-rider with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldLoadDatasetFromHttp () throws IOException, DataSetException {
    DataSetExecutorImpl dse = DataSetExecutorImpl.instance(new ConnectionHolder() {
        private static final long serialVersionUID = 1L;

        @Override
        public Connection getConnection() {
            return null;
        }
    });
    IDataSet iDataSetFromXml = dse.loadDataSet("https://raw.githubusercontent.com/database-rider/database-rider/master/rider-core/src/test/resources/datasets/xml/users.xml");
    String[] tableNamesXml = iDataSetFromXml.getTableNames();
    assertEquals("USER", tableNamesXml[0]);
    assertEquals("TWEET", tableNamesXml[1]);
    assertEquals("FOLLOWER", tableNamesXml[2]);

}
 
Example 3
Source File: DatabaseTaskHandler.java    From development with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 4
Source File: RiderDataSetBenchmark.java    From database-rider with Apache License 2.0 5 votes vote down vote up
private void assertCreatedDataSet(IDataSet iDataSet) throws DataSetException {
    if (iDataSet.getTableNames().length != 5) {
        throw new RuntimeException("Must create five tables but created " + iDataSet.getTableNames().length);
    }
    if (iDataSet.getTable("TABLE5").getRowCount() != 5) {
        throw new RuntimeException("TABLE5 must have 5 rows but has " + iDataSet.getTable("TABLE5").getRowCount());
    }
    if (iDataSet.getTable("TABLE5").getTableMetaData().getColumns().length != 11) {
        throw new RuntimeException("TABLE5 must have 11 columns per row but has " + iDataSet.getTable("TABLE5").getTableMetaData().getColumns().length);
    }
}
 
Example 5
Source File: HsqldbSequenceResetter.java    From JavaSpringMvcBlog with MIT License 5 votes vote down vote up
@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");

    }
}
 
Example 6
Source File: DataSetComparator.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 7
Source File: DataSetComparator.java    From jpa-unit with Apache License 2.0 5 votes vote down vote up
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.");
        }
    }
}
 
Example 8
Source File: SchemaUpgradeTestBase.java    From development with Apache License 2.0 5 votes vote down vote up
protected void assertDataAfterMigration(DatabaseConnection connection)
        throws Exception {
    final IDataSet expectedSet = loadDataSet(getExpectedDataset());
    for (final String tableName : expectedSet.getTableNames()) {
        assertTable(connection, expectedSet, tableName);
    }
}
 
Example 9
Source File: DataSetExecutorImplTest.java    From database-rider with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldLoadDatasetsFromURL() throws IOException, DataSetException {
    DataSetExecutorImpl dse = DataSetExecutorImpl.instance(new ConnectionHolder() {
        private static final long serialVersionUID = 1L;

        @Override
        public Connection getConnection() {
            return null;
        }
    });
    URL resourceXml = getClass().getResource("/datasets/xml/users.xml");
    IDataSet iDataSetFromXml = dse.loadDataSet(resourceXml.toString());
    String[] tableNamesXml = iDataSetFromXml.getTableNames();
    assertEquals("USER", tableNamesXml[0]);
    assertEquals("TWEET", tableNamesXml[1]);
    assertEquals("FOLLOWER", tableNamesXml[2]);

    URL resourceJson = getClass().getResource("/datasets/json/users.json");
    IDataSet iDataSetFromJson = dse.loadDataSet(resourceJson.toString());
    String[] tableNamesJson = iDataSetFromJson.getTableNames();
    assertEquals("USER", tableNamesJson[0]);
    assertEquals("TWEET", tableNamesJson[1]);
    assertEquals("FOLLOWER", tableNamesJson[2]);

    URL resourceXls = getClass().getResource("/datasets/xls/users.xls");
    IDataSet iDataSetFromXls = dse.loadDataSet(resourceXls.toString());
    String[] tableNamesXls = iDataSetFromXls.getTableNames();
    assertEquals("FOLLOWER", tableNamesXls[0]);
    assertEquals("SEQUENCE", tableNamesXls[1]);
    assertEquals("TWEET", tableNamesXls[2]);

    URL resourceYML = getClass().getResource("/datasets/yml/users.yml");
    IDataSet iDataSetFromYml = dse.loadDataSet(resourceYML.toString());
    String[] tableNamesYml = iDataSetFromYml.getTableNames();
    assertEquals("TWEET", tableNamesYml[0]);
    assertEquals("USER", tableNamesYml[1]);
    assertEquals("FOLLOWER", tableNamesYml[2]);


    URL resourceCvs = getClass().getResource("/datasets/csv/USER.csv");
    IDataSet iDataSetFromCsv = dse.loadDataSet(resourceCvs.toString());
    String[] tableNamesCsv = iDataSetFromCsv.getTableNames();
    assertEquals("FOLLOWER", tableNamesCsv[0]);
    assertEquals("TWEET", tableNamesCsv[1]);
    assertEquals("USER", tableNamesCsv[2]);


}