Search in sources :

Example 1 with DefaultDataSet

use of org.dbunit.dataset.DefaultDataSet 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 2 with DefaultDataSet

use of org.dbunit.dataset.DefaultDataSet in project openmrs-core by openmrs.

the class BaseContextSensitiveTest method deleteAllData.

/**
 * This is a convenience method to clear out all rows in all tables in the current connection.
 * <p>
 * This operation always results in a commit.
 *
 * @throws Exception
 */
public void deleteAllData() {
    try {
        Context.clearSession();
        Connection connection = getConnection();
        turnOffDBConstraints(connection);
        IDatabaseConnection dbUnitConn = setupDatabaseConnection(connection);
        // find all the tables for this connection
        ResultSet resultSet = connection.getMetaData().getTables(null, "PUBLIC", "%", null);
        DefaultDataSet dataset = new DefaultDataSet();
        while (resultSet.next()) {
            String tableName = resultSet.getString(3);
            dataset.addTable(new DefaultTable(tableName));
        }
        // do the actual deleting/truncating
        DatabaseOperation.DELETE_ALL.execute(dbUnitConn, dataset);
        turnOnDBConstraints(connection);
        connection.commit();
        updateSearchIndex();
        isBaseSetup = false;
    } catch (SQLException | DatabaseUnitException e) {
        throw new DatabaseUnitRuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) DefaultDataSet(org.dbunit.dataset.DefaultDataSet) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) ResultSet(java.sql.ResultSet) DefaultTable(org.dbunit.dataset.DefaultTable) DatabaseUnitException(org.dbunit.DatabaseUnitException) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseUnitRuntimeException(org.dbunit.DatabaseUnitRuntimeException)

Aggregations

DefaultDataSet (org.dbunit.dataset.DefaultDataSet)2 DefaultTable (org.dbunit.dataset.DefaultTable)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DataSourceDatabaseTester (org.dbunit.DataSourceDatabaseTester)1 DatabaseUnitException (org.dbunit.DatabaseUnitException)1 DatabaseUnitRuntimeException (org.dbunit.DatabaseUnitRuntimeException)1 DatabaseConnection (org.dbunit.database.DatabaseConnection)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1