Search in sources :

Example 1 with DatabaseConnection

use of org.dbunit.database.DatabaseConnection 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 DatabaseConnection

use of org.dbunit.database.DatabaseConnection in project head by mifos.

the class MifosIntegrationTestCase method dbVerificationSetUp.

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

Example 3 with DatabaseConnection

use of org.dbunit.database.DatabaseConnection 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 4 with DatabaseConnection

use of org.dbunit.database.DatabaseConnection 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 5 with DatabaseConnection

use of org.dbunit.database.DatabaseConnection in project head by mifos.

the class DatabaseTestUtils method saveTables.

/**
     * Return the current contents of the specified tables as a DBUnit dataset as XML string.
     * This method can be invoked safely inside a Spring-managed transaction.
     *
     * @param dataSource
     * @param tableNames variable parameter list of table names
     * @return XML string containing the current contents of the specified tables
     * @throws IOException
     * @throws DataSetException
     * @throws SQLException
     * @throws DatabaseUnitException
     */
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public //Rationale: You cannot define new local variables in the try block because the finally block must reference it.
String saveTables(DriverManagerDataSource dataSource, String... tableNames) throws IOException, DataSetException, SQLException, DatabaseUnitException {
    Connection jdbcConnection = null;
    try {
        jdbcConnection = DataSourceUtils.getConnection(dataSource);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        FlatXmlDataSet.write(new DatabaseConnection(jdbcConnection).createDataSet(tableNames), stream);
        return stream.toString();
    } finally {
        if (null != jdbcConnection) {
            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) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

DatabaseConnection (org.dbunit.database.DatabaseConnection)12 Connection (java.sql.Connection)11 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)10 IDataSet (org.dbunit.dataset.IDataSet)8 FileOutputStream (java.io.FileOutputStream)4 File (java.io.File)3 DataSourceDatabaseTester (org.dbunit.DataSourceDatabaseTester)2 IDatabaseTester (org.dbunit.IDatabaseTester)2 FilteredDataSet (org.dbunit.dataset.FilteredDataSet)2 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)2 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ITable (org.dbunit.dataset.ITable)1 ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)1 DatabaseUpgradeSupport (org.mifos.db.upgrade.DatabaseUpgradeSupport)1 ApplicationInitializer (org.mifos.framework.ApplicationInitializer)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1