Search in sources :

Example 46 with IDataSet

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);
}
Also used : ArrayList(java.util.ArrayList) IDataSet(org.dbunit.dataset.IDataSet)

Example 47 with IDataSet

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);
}
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 48 with IDataSet

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"));
}
Also used : FileOutputStream(java.io.FileOutputStream) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatabaseConnection(org.dbunit.database.DatabaseConnection) ForwardOnlyResultSetTableFactory(org.dbunit.database.ForwardOnlyResultSetTableFactory) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IDataSet(org.dbunit.dataset.IDataSet) DatabaseConfig(org.dbunit.database.DatabaseConfig) Test(org.junit.Test)

Example 49 with IDataSet

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

Example 50 with IDataSet

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);
}
Also used : DatabaseDataSourceConnection(org.dbunit.database.DatabaseDataSourceConnection) IDataSet(org.dbunit.dataset.IDataSet) BeforeStory(org.jbehave.core.annotations.BeforeStory)

Aggregations

IDataSet (org.dbunit.dataset.IDataSet)54 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)21 DatabaseConnection (org.dbunit.database.DatabaseConnection)16 Test (org.junit.Test)15 ITable (org.dbunit.dataset.ITable)13 Connection (java.sql.Connection)12 FileOutputStream (java.io.FileOutputStream)11 File (java.io.File)10 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)8 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)7 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)7 OutputStreamWriter (java.io.OutputStreamWriter)5 Writer (java.io.Writer)5 IDatabaseTester (org.dbunit.IDatabaseTester)5 FileInputStream (java.io.FileInputStream)4 FlatDtdWriter (org.dbunit.dataset.xml.FlatDtdWriter)4 BaseCwsCmsInMemoryPersistenceTest (gov.ca.cwds.data.legacy.cms.persistence.BaseCwsCmsInMemoryPersistenceTest)3 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)3