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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations