use of org.dbunit.dataset.IDataSet in project activityinfo by bedatadriven.
the class LoadDataSet method evaluate.
@Override
public void evaluate() throws Throwable {
System.out.println("ConnectionProvider class: " + connectionProvider);
JdbcScheduler.get().forceCleanup();
LOGGER.info("Removing all rows");
removeAllRows();
LOGGER.info("DBUnit: loading " + name + " into the database.");
IDataSet data = loadDataSet();
LOGGER.info("DBUnit: loaded " + name + ", table names: " + Arrays.toString(data.getTableNames()));
List<Throwable> errors = new ArrayList<Throwable>();
errors.clear();
try {
populate(data);
next.evaluate();
} catch (Throwable e) {
errors.add(e);
}
MultipleFailureException.assertEmpty(errors);
}
use of org.dbunit.dataset.IDataSet in project openmrs-core by openmrs.
the class BaseContextSensitiveTest method executeXmlDataSet.
/**
* Runs the xml data file at the classpath location specified by <code>datasetFilename</code>
* using XmlDataSet. It simply creates an {@link IDataSet} and calls
* {@link #executeDataSet(IDataSet)}. <br>
* <br>
* This method is different than {@link #executeDataSet(String)} in that this one does not
* expect a flat file xml but instead a true XmlDataSet. <br>
* <br>
* In addition, there is no replacing of [NULL] values in strings.
*
* @param datasetFilename String path/filename on the classpath of the xml data set to clean
* insert into the current database
* @see #getConnection()
* @see #executeDataSet(IDataSet)
*/
public void executeXmlDataSet(String datasetFilename) throws Exception {
// try to get the given filename from the cache
IDataSet xmlDataSetToRun = cachedDatasets.get(datasetFilename);
// if we didn't find it in the cache, load it
if (xmlDataSetToRun == null) {
File file = new File(datasetFilename);
InputStream fileInInputStreamFormat = null;
try {
// if its a classpath path to the file
if (file.exists())
fileInInputStreamFormat = new FileInputStream(datasetFilename);
else {
fileInInputStreamFormat = getClass().getClassLoader().getResourceAsStream(datasetFilename);
if (fileInInputStreamFormat == null)
throw new FileNotFoundException("Unable to find '" + datasetFilename + "' in the classpath");
}
XmlDataSet xmlDataSet = null;
xmlDataSet = new XmlDataSet(fileInInputStreamFormat);
xmlDataSetToRun = xmlDataSet;
fileInInputStreamFormat.close();
} finally {
IOUtils.closeQuietly(fileInInputStreamFormat);
}
// cache the xmldataset for future runs of this file
cachedDatasets.put(datasetFilename, xmlDataSetToRun);
}
executeDataSet(xmlDataSetToRun);
}
use of org.dbunit.dataset.IDataSet in project openmrs-core by openmrs.
the class CreateConceptDictionaryDataSet method createConceptDictionaryDataSet.
@Test
@SkipBaseSetup
public void createConceptDictionaryDataSet() throws Exception {
IDatabaseConnection connection = new DatabaseConnection(getConnection());
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_RESULTSET_TABLE_FACTORY, new ForwardOnlyResultSetTableFactory());
String[] tableNames = new String[] { "concept_class", "concept_datatype", "concept_map_type", "concept_reference_source", "concept", "concept_numeric", "concept_description", "concept_name", "concept_reference_term", "concept_reference_map", "concept_reference_term_map", "concept_set", "concept_complex", "concept_answer", "concept_stop_word" };
IDataSet dataSet = connection.createDataSet(tableNames);
FlatXmlDataSet.write(dataSet, new FileOutputStream("target/conceptDictionaryDataSet.xml"));
}
use of org.dbunit.dataset.IDataSet in project ovirt-engine by oVirt.
the class BaseGenericDaoTestCase method reinitializeDatabase.
protected void reinitializeDatabase() {
try {
final IDataSet dataset = initDataSet();
DatabaseOperation.CLEAN_INSERT.execute(getConnection(), dataset);
} catch (Exception ex) {
throw new RuntimeException("Database reinitialization failed", ex);
}
}
use of org.dbunit.dataset.IDataSet in project jbehave-core by jbehave.
the class DbUnitSteps method deleteAllData.
@BeforeStory
public void deleteAllData() throws SQLException, DatabaseUnitException {
DatabaseDataSourceConnection dbConn = new DatabaseDataSourceConnection(dataSource);
IDataSet dataSet = dbConn.createDataSet(new String[] { "ORGANIZATION", "APPLICATION_USER" });
DatabaseOperation.DELETE_ALL.execute(dbConn, dataSet);
}
Aggregations