Search in sources :

Example 21 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project sharding-jdbc by shardingjdbc.

the class AbstractSQLTest method importDataSet.

protected final void importDataSet() throws Exception {
    for (DatabaseType databaseType : getDatabaseTypes()) {
        if (databaseType == getCurrentDatabaseType() || null == getCurrentDatabaseType()) {
            DatabaseEnvironment dbEnv = new DatabaseEnvironment(databaseType);
            for (String each : getInitDataSetFiles()) {
                InputStream is = AbstractSQLTest.class.getClassLoader().getResourceAsStream(each);
                IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
                IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getDatabaseName(each)), dbEnv.getUsername(), dbEnv.getPassword(), dbEnv.getSchema(getDatabaseName(each)));
                databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
                databaseTester.setDataSet(dataSet);
                databaseTester.onSetup();
            }
        }
    }
}
Also used : DatabaseEnvironment(io.shardingjdbc.core.common.env.DatabaseEnvironment) DatabaseType(io.shardingjdbc.core.constant.DatabaseType) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IDatabaseTester(org.dbunit.IDatabaseTester) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) ShardingJdbcDatabaseTester(io.shardingjdbc.core.common.env.ShardingJdbcDatabaseTester)

Example 22 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project Asqatasun by Asqatasun.

the class AbstractDaoTestCase method getDataSet.

/**
 * Charge le jeu de données à partir d'un fichier XML d'import
 * @return
 * @throws java.lang.Exception
 */
@Override
protected IDataSet getDataSet() throws Exception {
    FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
    builder.setColumnSensing(true);
    ReplacementDataSet dataSet = new ReplacementDataSet(builder.build(new FileInputStream(getDataSetFilename())));
    dataSet.addReplacementObject("[NULL]", null);
    return dataSet;
}
Also used : ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) FileInputStream(java.io.FileInputStream)

Aggregations

FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)22 Connection (java.sql.Connection)9 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)7 IDataSet (org.dbunit.dataset.IDataSet)7 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)6 ITable (org.dbunit.dataset.ITable)6 File (java.io.File)4 PreparedStatement (java.sql.PreparedStatement)3 IDatabaseTester (org.dbunit.IDatabaseTester)3 DatabaseConnection (org.dbunit.database.DatabaseConnection)3 ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)3 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)3 MySqlConnection (org.dbunit.ext.mysql.MySqlConnection)3 ShardingJdbcDatabaseTester (io.shardingjdbc.core.common.env.ShardingJdbcDatabaseTester)2 DatabaseType (io.shardingjdbc.core.constant.DatabaseType)2 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FilteredDataSet (org.dbunit.dataset.FilteredDataSet)2