Search in sources :

Example 1 with DataSourceDatabaseTester

use of org.dbunit.DataSourceDatabaseTester 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)

Example 2 with DataSourceDatabaseTester

use of org.dbunit.DataSourceDatabaseTester in project gocd by gocd.

the class DatabaseAccessHelper method initialize.

private void initialize(DataSource dataSource) throws AmbiguousTableNameException {
    databaseTester = new DataSourceDatabaseTester(dataSource);
    databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
    databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
    DefaultDataSet dataSet = new DefaultDataSet();
    dataSet.addTable(new DefaultTable("agents"));
    dataSet.addTable(new DefaultTable("pipelines"));
    dataSet.addTable(new DefaultTable("pipelinestates"));
    dataSet.addTable(new DefaultTable("materials"));
    dataSet.addTable(new DefaultTable("modifications"));
    dataSet.addTable(new DefaultTable("pipelineMaterialRevisions"));
    dataSet.addTable(new DefaultTable("modifiedFiles"));
    dataSet.addTable(new DefaultTable("notificationfilters"));
    dataSet.addTable(new DefaultTable("users"));
    dataSet.addTable(new DefaultTable("stages"));
    dataSet.addTable(new DefaultTable("pipelineLabelCounts"));
    dataSet.addTable(new DefaultTable("environmentVariables"));
    dataSet.addTable(new DefaultTable("artifactPlans"));
    dataSet.addTable(new DefaultTable("buildStateTransitions"));
    dataSet.addTable(new DefaultTable("resources"));
    dataSet.addTable(new DefaultTable("builds"));
    dataSet.addTable(new DefaultTable("stageArtifactCleanupProhibited"));
    dataSet.addTable(new DefaultTable("serverBackups"));
    dataSet.addTable(new DefaultTable("jobAgentMetadata"));
    dataSet.addTable(new DefaultTable("AccessToken"));
    databaseTester.setDataSet(dataSet);
}
Also used : DefaultDataSet(org.dbunit.dataset.DefaultDataSet) DefaultTable(org.dbunit.dataset.DefaultTable) DataSourceDatabaseTester(org.dbunit.DataSourceDatabaseTester)

Example 3 with DataSourceDatabaseTester

use of org.dbunit.DataSourceDatabaseTester 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)

Aggregations

DataSourceDatabaseTester (org.dbunit.DataSourceDatabaseTester)3 Connection (java.sql.Connection)2 IDatabaseTester (org.dbunit.IDatabaseTester)2 DatabaseConnection (org.dbunit.database.DatabaseConnection)2 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)2 IDataSet (org.dbunit.dataset.IDataSet)2 StringReader (java.io.StringReader)1 DefaultDataSet (org.dbunit.dataset.DefaultDataSet)1 DefaultTable (org.dbunit.dataset.DefaultTable)1 ITable (org.dbunit.dataset.ITable)1 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)1