Search in sources :

Example 6 with XmlDataSet

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IDataSet(org.dbunit.dataset.IDataSet) File(java.io.File) FileInputStream(java.io.FileInputStream) FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet)

Example 7 with XmlDataSet

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);
}
Also used : MetaStore(org.smartdata.metastore.MetaStore) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet)

Example 8 with XmlDataSet

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));
}
Also used : MetaStore(org.smartdata.metastore.MetaStore) FileAccessInfo(org.smartdata.model.FileAccessInfo) IDataSet(org.dbunit.dataset.IDataSet) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) DBTest(org.smartdata.metastore.DBTest) Test(org.junit.Test)

Aggregations

IDataSet (org.dbunit.dataset.IDataSet)8 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)8 Test (org.junit.Test)6 ITable (org.dbunit.dataset.ITable)4 MetaStore (org.smartdata.metastore.MetaStore)3 DBAdapter (org.smartdata.server.metastore.DBAdapter)3 Statement (java.sql.Statement)2 SortedTable (org.dbunit.dataset.SortedTable)2 DBTest (org.smartdata.metastore.DBTest)2 DBTest (org.smartdata.server.metastore.DBTest)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)1 FileAccessEvent (org.smartdata.metrics.FileAccessEvent)1 FileAccessInfo (org.smartdata.model.FileAccessInfo)1 AccessCountTable (org.smartdata.server.metastore.tables.AccessCountTable)1