Search in sources :

Example 1 with IDataSet

use of org.dbunit.dataset.IDataSet in project head by mifos.

the class MifosIntegrationTestCase method dbVerificationTearDown.

private void dbVerificationTearDown() throws Exception, FileNotFoundException, MalformedURLException {
    if (verifyDatabaseState) {
        Connection connection = StaticHibernateUtil.getSessionTL().connection();
        connection.setAutoCommit(false);
        DatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
        IDataSet upgradeDataDump = new FilteredDataSet(excludeTables, dbUnitConnection.createDataSet());
        String tmpDir = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator");
        FlatXmlDataSet.write(upgradeDataDump, new FileOutputStream(tmpDir + "upgradeDataDump.xml"));
        FlatXmlDataSetBuilder fxmlBuilder = new FlatXmlDataSetBuilder();
        upgradeDataDump = fxmlBuilder.build(new File(tmpDir + "upgradeDataDump.xml"));
        Assertion.assertEquals(latestDataDump, upgradeDataDump);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Connection(java.sql.Connection) DatabaseConnection(org.dbunit.database.DatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder) File(java.io.File) FilteredDataSet(org.dbunit.dataset.FilteredDataSet)

Example 2 with IDataSet

use of org.dbunit.dataset.IDataSet in project head by mifos.

the class DbUnitUtilities method dumpDatabase.

public void dumpDatabase(String fileName, Connection jdbcConnection) throws SQLException, DatabaseUnitException, FileNotFoundException, IOException {
    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
    IDataSet fullDataSet = connection.createDataSet();
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream(fileName));
}
Also used : FileOutputStream(java.io.FileOutputStream) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet)

Example 3 with IDataSet

use of org.dbunit.dataset.IDataSet in project head by mifos.

the class DbUnitUtilities method loadDataFromFile.

public void loadDataFromFile(String filename, DriverManagerDataSource dataSource) throws DatabaseUnitException, SQLException, IOException {
    Connection jdbcConnection = null;
    IDataSet dataSet = getDataSetFromDataSetDirectoryFile(filename);
    try {
        jdbcConnection = DataSourceUtils.getConnection(dataSource);
        IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
        DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
    } finally {
        if (jdbcConnection != null) {
            jdbcConnection.close();
        }
        DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
    }
}
Also used : Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet)

Example 4 with IDataSet

use of org.dbunit.dataset.IDataSet in project head by mifos.

the class AcceptanceDatabaseTestUtils method deleteDataFromTable.

public void deleteDataFromTable(String tableName, DriverManagerDataSource dataSource) throws IOException, DataSetException, SQLException, DatabaseUnitException {
    StringReader dataSetXmlStream = new StringReader("<dataset><" + tableName + "/></dataset>");
    IDataSet dataSet = new FlatXmlDataSet(dataSetXmlStream);
    IDatabaseConnection databaseConnection = new DatabaseDataSourceConnection(dataSource);
    databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
    DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) DatabaseDataSourceConnection(org.dbunit.database.DatabaseDataSourceConnection) StringReader(java.io.StringReader) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet)

Example 5 with IDataSet

use of org.dbunit.dataset.IDataSet in project head by mifos.

the class DatabaseTestUtils method verifyTable.

/**
     * Verify that a database table matches a dataSet table. dataSetXml must be formatted as a DBUnit
     * xml dataset. This method can be safely invoked inside a Spring-managed transaction.
     * @param dataSetXml
     * @param tableName
     * @param dataSource
     * @throws Exception
     */
// one of the dependent methods throws Exception
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void verifyTable(String dataSetXml, String tableName, DriverManagerDataSource dataSource) throws Exception {
    Connection jdbcConnection = null;
    StringReader dataSetXmlStream = new StringReader(dataSetXml);
    try {
        jdbcConnection = DataSourceUtils.getConnection(dataSource);
        IDatabaseTester databaseTester = new DataSourceDatabaseTester(dataSource);
        IDatabaseConnection databaseConnection = databaseTester.getConnection();
        databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
        IDataSet databaseDataSet = databaseConnection.createDataSet();
        ITable actualTable = databaseDataSet.getTable(tableName);
        IDataSet expectedDataSet = new FlatXmlDataSet(dataSetXmlStream);
        ITable expectedTable = expectedDataSet.getTable(tableName);
        Assertion.assertEqualsIgnoreCols(expectedTable, actualTable, new String[] { "id" });
    } finally {
        if (null != jdbcConnection) {
            jdbcConnection.close();
        }
        DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
    }
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) StringReader(java.io.StringReader) IDatabaseTester(org.dbunit.IDatabaseTester) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) DataSourceDatabaseTester(org.dbunit.DataSourceDatabaseTester)

Aggregations

IDataSet (org.dbunit.dataset.IDataSet)54 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)21 DatabaseConnection (org.dbunit.database.DatabaseConnection)16 Test (org.junit.Test)15 ITable (org.dbunit.dataset.ITable)13 Connection (java.sql.Connection)12 FileOutputStream (java.io.FileOutputStream)11 File (java.io.File)10 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)8 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)7 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)7 OutputStreamWriter (java.io.OutputStreamWriter)5 Writer (java.io.Writer)5 IDatabaseTester (org.dbunit.IDatabaseTester)5 FileInputStream (java.io.FileInputStream)4 FlatDtdWriter (org.dbunit.dataset.xml.FlatDtdWriter)4 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)3 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)3