use of org.dbunit.dataset.xml.XmlDataSet 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.xml.XmlDataSet in project SSM by Intel-bigdata.
the class TestAccessCountTableManager method initTestEnvironment.
private AccessCountTableManager initTestEnvironment() throws Exception {
MetaStore metaStore = new MetaStore(druidPool);
createTables(databaseTester.getConnection().getConnection());
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("files.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
prepareFiles(metaStore);
return new AccessCountTableManager(metaStore);
}
use of org.dbunit.dataset.xml.XmlDataSet in project SSM by Intel-bigdata.
the class TestTableAggregator method testGetTopN.
@Test
public void testGetTopN() throws Exception {
createTables(databaseTester.getConnection());
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("accessCountTable.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
MetaStore metaStore = new MetaStore(druidPool);
prepareFiles(metaStore);
AccessCountTable table1 = new AccessCountTable("table1", 0L, 0L, false);
AccessCountTable table2 = new AccessCountTable("table2", 0L, 0L, false);
AccessCountTable table3 = new AccessCountTable("table3", 0L, 0L, false);
List<FileAccessInfo> accessInfos = metaStore.getHotFiles(Arrays.asList(table1, table2, table3), 1);
Assert.assertTrue(accessInfos.size() == 1);
FileAccessInfo expected1 = new FileAccessInfo(103L, "/file3", 7);
Assert.assertTrue(accessInfos.get(0).equals(expected1));
List<FileAccessInfo> accessInfos2 = metaStore.getHotFiles(Arrays.asList(table1, table2, table3), 2);
List<FileAccessInfo> expected2 = Arrays.asList(expected1, new FileAccessInfo(102L, "/file2", 6));
Assert.assertTrue(accessInfos2.size() == expected2.size());
Assert.assertTrue(accessInfos2.containsAll(expected2));
}
Aggregations