Search in sources :

Example 11 with FlatXmlDataSetBuilder

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

the class AbstractRuleImplementationTestCase 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 {
    if (dataset != null) {
        return dataset;
    }
    if (!getInputDataFileName().isEmpty()) {
        FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
        builder.setColumnSensing(true);
        dataset = builder.build(new File(getInputDataFileName()));
        return dataset;
    } else {
        return null;
    }
}
Also used : FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 12 with FlatXmlDataSetBuilder

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

the class AbstractDBUnitTest method assertDataSet.

protected void assertDataSet(final String expectedDataSetFile, final Connection connection, final String actualTableName, final String sql) throws SQLException, DatabaseUnitException {
    try (Connection conn = connection) {
        ITable actualTable = getConnection(conn).createQueryTable(actualTableName, sql);
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(AbstractDBUnitTest.class.getClassLoader().getResourceAsStream(expectedDataSetFile)));
        assertEquals(expectedDataSet.getTable(actualTableName), actualTable);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) MySqlConnection(org.dbunit.ext.mysql.MySqlConnection) H2Connection(org.dbunit.ext.h2.H2Connection) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 13 with FlatXmlDataSetBuilder

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

the class AbstractDBUnitTest method assertDataSet.

protected void assertDataSet(final String expectedDataSetFile, final Connection connection, final String actualTableName, final String sql, final Object... params) throws SQLException, DatabaseUnitException {
    try (Connection conn = connection;
        PreparedStatement ps = conn.prepareStatement(sql)) {
        int i = 1;
        for (Object each : params) {
            ps.setObject(i++, each);
        }
        ITable actualTable = getConnection(connection).createTable(actualTableName, ps);
        IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(AbstractDBUnitTest.class.getClassLoader().getResourceAsStream(expectedDataSetFile)));
        assertEquals(expectedDataSet.getTable(actualTableName), actualTable);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) MySqlConnection(org.dbunit.ext.mysql.MySqlConnection) H2Connection(org.dbunit.ext.h2.H2Connection) PreparedStatement(java.sql.PreparedStatement) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 14 with FlatXmlDataSetBuilder

use of org.dbunit.dataset.xml.FlatXmlDataSetBuilder in project head by mifos.

the class DbUnitUtilities method getDataSetFromFile.

public IDataSet getDataSetFromFile(String filename) throws IOException, DataSetException {
    File file = new File(filename);
    FlatXmlDataSetBuilder fb = new FlatXmlDataSetBuilder();
    fb.setColumnSensing(true);
    fb.setDtdMetadata(false);
    return fb.build(file);
}
Also used : FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) File(java.io.File)

Example 15 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
     */
@Override
protected IDataSet getDataSet() throws Exception {
    FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
    FlatXmlDataSet loadedDataSet = flatXmlDataSetBuilder.build(new FileInputStream(getInputDataFileName()));
    return loadedDataSet;
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) 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