Search in sources :

Example 11 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project api-core by ca-cwds.

the class BasePersistenceTest method readXmlDataSet.

protected IDataSet readXmlDataSet(String dataSetFilePath) throws Exception {
    DataFileLoader loader = new FlatXmlDataFileLoader();
    IDataSet dataSet = loader.load(dataSetFilePath);
    ReplacementDataSet replacementDataSet = new ReplacementDataSet(dataSet);
    replacementDataSet.addReplacementObject("[NULL]", null);
    return replacementDataSet;
}
Also used : FlatXmlDataFileLoader(org.dbunit.util.fileloader.FlatXmlDataFileLoader) DataFileLoader(org.dbunit.util.fileloader.DataFileLoader) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) FlatXmlDataFileLoader(org.dbunit.util.fileloader.FlatXmlDataFileLoader) IDataSet(org.dbunit.dataset.IDataSet)

Example 12 with ReplacementDataSet

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

the class DatabaseTestUtils method cleanAndInsertDataSet.

private void cleanAndInsertDataSet(DriverManagerDataSource dataSource, IDataSet dataSet) throws DatabaseUnitException, SQLException {
    Connection jdbcConnection = null;
    ReplacementDataSet replacementDataSet = getDataSetWithNullsReplaced(dataSet);
    try {
        jdbcConnection = DataSourceUtils.getConnection(dataSource);
        IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
        databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
        DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, replacementDataSet);
    } finally {
        if (null != jdbcConnection) {
            jdbcConnection.close();
        }
        DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
    }
}
Also used : ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) 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)

Example 13 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project sonarqube by SonarSource.

the class AbstractDbTester method dbUnitDataSet.

private IDataSet dbUnitDataSet(InputStream stream) {
    try {
        ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
        dataSet.addReplacementObject("[null]", null);
        dataSet.addReplacementObject("[false]", Boolean.FALSE);
        dataSet.addReplacementObject("[true]", Boolean.TRUE);
        return dataSet;
    } catch (Exception e) {
        throw translateException("Could not read the dataset stream", e);
    }
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) SQLException(java.sql.SQLException) DatabaseUnitException(org.dbunit.DatabaseUnitException)

Example 14 with ReplacementDataSet

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

the class DatabaseUpgradeTestUtil method executeDataset.

public void executeDataset(String path) throws IOException, SQLException {
    InputStream inputStream = getClass().getResourceAsStream(path);
    ReplacementDataSet replacementDataSet;
    try {
        replacementDataSet = new ReplacementDataSet(new FlatXmlDataSet(new InputStreamReader(inputStream), false, true, false));
        inputStream.close();
    } catch (DataSetException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
    replacementDataSet.addReplacementObject("[NULL]", null);
    try {
        DatabaseOperation.REFRESH.execute(dbUnitConnection, replacementDataSet);
        connection.commit();
    } catch (DatabaseUnitException e) {
        throw new IOException(e);
    }
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) InputStreamReader(java.io.InputStreamReader) DataSetException(org.dbunit.dataset.DataSetException) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) InputStream(java.io.InputStream) DatabaseUnitException(org.dbunit.DatabaseUnitException) IOException(java.io.IOException)

Example 15 with ReplacementDataSet

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

the class BaseContextSensitiveTest method executeLargeDataSet.

/**
 * Runs the large flat xml dataset. It does not cache the file as opposed to
 * {@link #executeDataSet(String)}.
 *
 * @param datasetFilename
 * @throws Exception
 * @since 1.10
 */
public void executeLargeDataSet(String datasetFilename) throws Exception {
    InputStream inputStream = null;
    try {
        final File file = new File(datasetFilename);
        if (file.exists()) {
            inputStream = new FileInputStream(datasetFilename);
        } else {
            inputStream = getClass().getClassLoader().getResourceAsStream(datasetFilename);
            if (inputStream == null)
                throw new FileNotFoundException("Unable to find '" + datasetFilename + "' in the classpath");
        }
        final FlatXmlProducer flatXmlProducer = new FlatXmlProducer(new InputSource(inputStream));
        final StreamingDataSet streamingDataSet = new StreamingDataSet(flatXmlProducer);
        final ReplacementDataSet replacementDataSet = new ReplacementDataSet(streamingDataSet);
        replacementDataSet.addReplacementObject("[NULL]", null);
        executeDataSet(replacementDataSet);
        inputStream.close();
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FlatXmlProducer(org.dbunit.dataset.xml.FlatXmlProducer) StreamingDataSet(org.dbunit.dataset.stream.StreamingDataSet) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)17 DBUnitAssertHelper (gov.ca.cwds.cals.persistence.DBUnitAssertHelper)6 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 Connection (java.sql.Connection)3 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)3 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)3 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)3 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 DatabaseUnitException (org.dbunit.DatabaseUnitException)2 DataSetException (org.dbunit.dataset.DataSetException)2 IDataSet (org.dbunit.dataset.IDataSet)2 ITable (org.dbunit.dataset.ITable)2 Reader (java.io.Reader)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1