use of org.dbunit.dataset.DataSetException in project nextprot-api by calipho-sib.
the class FlatXmlDataSetExtractor method toString.
public String toString() {
StringBuilder sb = new StringBuilder();
try {
for (String tableName : ds.getTableNames()) {
sb.append("Table:").append(tableName).append("\n");
ITable table = ds.getTable(tableName);
for (int i = 0; i < table.getRowCount(); i++) {
ITableMetaData md = table.getTableMetaData();
sb.append(" ");
for (Column col : md.getColumns()) {
sb.append(col.getColumnName()).append(": ").append(table.getValue(i, col.getColumnName()));
sb.append(", ");
}
sb.delete(sb.length() - 2, sb.length());
sb.append("\n");
}
}
} catch (DataSetException e) {
sb.append("Error: ").append(e.getMessage());
}
return sb.toString();
}
use of org.dbunit.dataset.DataSetException in project openmrs-core by openmrs.
the class BaseContextSensitiveTest method executeDataSet.
/**
* Runs the flat xml data file at the classpath location specified by
* <code>datasetFilename</code> This is a convenience method. It simply creates an
* {@link IDataSet} and calls {@link #executeDataSet(IDataSet)}
*
* @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 executeDataSet(String datasetFilename) {
// 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;
Reader reader = null;
try {
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");
}
reader = new InputStreamReader(fileInInputStreamFormat);
ReplacementDataSet replacementDataSet = new ReplacementDataSet(new FlatXmlDataSet(reader, false, true, false));
replacementDataSet.addReplacementObject("[NULL]", null);
xmlDataSetToRun = replacementDataSet;
reader.close();
} catch (DataSetException | IOException e) {
throw new DatabaseUnitRuntimeException(e);
}
} finally {
IOUtils.closeQuietly(fileInInputStreamFormat);
IOUtils.closeQuietly(reader);
}
// cache the xmldataset for future runs of this file
cachedDatasets.put(datasetFilename, xmlDataSetToRun);
}
executeDataSet(xmlDataSetToRun);
}
use of org.dbunit.dataset.DataSetException 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);
}
}
Aggregations