Search in sources :

Example 31 with IDataSet

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

the class SavingsDepositTest method makeDepositToClientSavingsAccount.

// one of the dependent methods throws Exception
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void makeDepositToClientSavingsAccount() throws Exception {
    initData();
    DepositWithdrawalSavingsParameters params = new DepositWithdrawalSavingsParameters();
    params.setTrxnDateMM("09");
    params.setTrxnDateDD("09");
    params.setTrxnDateYYYY("2009");
    params.setAmount("543.2");
    params.setPaymentType(DepositWithdrawalSavingsParameters.CASH);
    params.setTrxnType(DepositWithdrawalSavingsParameters.DEPOSIT);
    params.setReceiptDateDD("09");
    params.setReceiptDateMM("09");
    params.setReceiptDateYYYY("2009");
    SavingsAccountDetailPage accountDetailPage = savingsAccountHelper.makeDepositOrWithdrawalOnSavingsAccount("000100000000036", params);
    String[] tablesToRetrieve = { "SAVINGS_ACTIVITY_DETAILS", "SAVINGS_ACCOUNT", "SAVINGS_PERFORMANCE", "SAVINGS_TRXN_DETAIL" };
    String[] tablesToValidate = { "SAVINGS_ACTIVITY_DETAILS", "SAVINGS_ACCOUNT", "SAVINGS_PERFORMANCE" };
    IDataSet expectedDataSet = dbUnitUtilities.getDataSetFromDataSetDirectoryFile("SavingsDeposit_001_result_dbunit.xml");
    IDataSet databaseDataSet = dbUnitUtilities.getDataSetForTables(dataSource, tablesToRetrieve);
    dbUnitUtilities.verifyTables(tablesToValidate, databaseDataSet, expectedDataSet);
    // verify savings transaction table with sorting
    String[] orderSavingsTrxnByColumns = new String[] { "deposit_amount" };
    dbUnitUtilities.verifyTableWithSort(orderSavingsTrxnByColumns, SavingsDepositTest.SAVINGS_TRXN_DETAIL, expectedDataSet, databaseDataSet);
    // verify transaction history table
    TransactionHistoryPage historyPage = accountDetailPage.navigateToTransactionHistoryPage();
    historyPage.verifyTableTypeAfterDeposit(2);
}
Also used : TransactionHistoryPage(org.mifos.test.acceptance.framework.savings.TransactionHistoryPage) SavingsAccountDetailPage(org.mifos.test.acceptance.framework.savings.SavingsAccountDetailPage) IDataSet(org.dbunit.dataset.IDataSet) DepositWithdrawalSavingsParameters(org.mifos.test.acceptance.framework.savings.DepositWithdrawalSavingsParameters)

Example 32 with IDataSet

use of org.dbunit.dataset.IDataSet 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 33 with IDataSet

use of org.dbunit.dataset.IDataSet 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 34 with IDataSet

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

the class DbUnitUtilities method getDataSetForTables.

/**
     * Returns a DbUnit DataSet for several tables.
     * @param driverManagerDataSource TODO
     * @param tableNames
     * @return IDataSet
     * @throws Exception
     */
// one of the dependent methods throws Exception
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public IDataSet getDataSetForTables(DriverManagerDataSource driverManagerDataSource, String[] tableNames) throws Exception {
    Connection jdbcConnection = null;
    IDataSet databaseDataSet = null;
    try {
        jdbcConnection = DataSourceUtils.getConnection(driverManagerDataSource);
        IDatabaseTester databaseTester = new DataSourceDatabaseTester(driverManagerDataSource);
        IDatabaseConnection databaseConnection = databaseTester.getConnection();
        databaseDataSet = databaseConnection.createDataSet(tableNames);
    } finally {
        jdbcConnection.close();
        DataSourceUtils.releaseConnection(jdbcConnection, driverManagerDataSource);
    }
    return databaseDataSet;
}
Also used : Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) IDatabaseTester(org.dbunit.IDatabaseTester) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) DataSourceDatabaseTester(org.dbunit.DataSourceDatabaseTester)

Example 35 with IDataSet

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

the class DatabaseTestUtils method cleanAndInsertDataSetWithColumnSensing.

@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public //Rationale: You cannot define new local variables in the try block because the finally block must reference it.
void cleanAndInsertDataSetWithColumnSensing(String xmlString, DriverManagerDataSource dataSource) throws IOException, DataSetException, SQLException, DatabaseUnitException {
    IDataSet dataSet = getXmlDataSet(xmlString);
    cleanAndInsertDataSet(dataSource, dataSet);
}
Also used : IDataSet(org.dbunit.dataset.IDataSet)

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