Search in sources :

Example 1 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project head by mifos.

the class DatabaseTestUtils method getDataSetWithNullsReplaced.

/**
     * Given a data set, return a data set with [null] replaced by actual null objects
     * @param dataSet
     * @return replacementDataSet
     */
public ReplacementDataSet getDataSetWithNullsReplaced(IDataSet dataSet) {
    ReplacementDataSet replacementDataSet = new ReplacementDataSet(dataSet);
    replacementDataSet.addReplacementObject("[null]", null);
    return replacementDataSet;
}
Also used : ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet)

Example 2 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet 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);
}
Also used : FlatXmlDataSet(org.dbunit.dataset.xml.FlatXmlDataSet) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DatabaseUnitRuntimeException(org.dbunit.DatabaseUnitRuntimeException) DataSetException(org.dbunit.dataset.DataSetException) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) IDataSet(org.dbunit.dataset.IDataSet) File(java.io.File)

Example 3 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project cals-api by ca-cwds.

the class RFA1aCoreSubmitApplicationTest method testIfSubstituteCareProviderUCWasCreatedProperly.

private void testIfSubstituteCareProviderUCWasCreatedProperly(String substituteCareProviderId1, String substituteCareProviderId2) throws Exception {
    DBUnitAssertHelper helper = DBUnitAssertHelper.builder(dbUnitSupport).setExpectedResultTemplatePath("/dbunit/SubstituteCareProviderUC.xml").setTestedTableName("SBPVD_UC").build();
    ReplacementDataSet expectedDataSet = helper.getExpectedDataSet();
    expectedDataSet.addReplacementObject("$substituteCareProviderId1", substituteCareProviderId1);
    expectedDataSet.addReplacementObject("$substituteCareProviderId2", substituteCareProviderId2);
    helper.assertEquals(new String[] { "PKSB_PVDRT", "LST_UPD_TS" }, new String[] { "FIRST_NM" });
}
Also used : DBUnitAssertHelper(gov.ca.cwds.cals.persistence.DBUnitAssertHelper) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet)

Example 4 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project cals-api by ca-cwds.

the class RFA1aCoreSubmitApplicationTest method testIfSubstituteCareProviderWasCreatedProperly.

private void testIfSubstituteCareProviderWasCreatedProperly(String substituteCareProviderId1, String substituteCareProviderId2) throws Exception {
    DBUnitAssertHelper helper = DBUnitAssertHelper.builder(dbUnitSupport).setExpectedResultTemplatePath("/dbunit/SubstituteCareProvider.xml").setTestedTableName("SB_PVDRT").build();
    ReplacementDataSet expectedDataSet = helper.getExpectedDataSet();
    expectedDataSet.addReplacementObject("$substituteCareProviderId1", substituteCareProviderId1);
    expectedDataSet.addReplacementObject("$substituteCareProviderId2", substituteCareProviderId2);
    helper.assertEquals(new String[] { "IDENTIFIER", "LST_UPD_TS", "LIS_PER_ID", "ETH_UD_CD", "HISP_UD_CD", "PASSBC_CD" }, new String[] { "FIRST_NM" });
}
Also used : DBUnitAssertHelper(gov.ca.cwds.cals.persistence.DBUnitAssertHelper) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet)

Example 5 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project cals-api by ca-cwds.

the class RFA1aCoreSubmitApplicationTest method testIfCountyOwnershipWasCreatedProperly.

private void testIfCountyOwnershipWasCreatedProperly(String placementHomeId, String[] substituteCareProviderIds) throws Exception {
    DBUnitAssertHelper helper = DBUnitAssertHelper.builder(dbUnitSupport).setExpectedResultTemplatePath("/dbunit/CountyOwnership.xml").setTestedTableName("CNTYOWNT").build();
    ReplacementDataSet expectedDataSet = helper.getExpectedDataSet();
    expectedDataSet.addReplacementObject("$placementHomeId", placementHomeId);
    expectedDataSet.addReplacementObject("$substituteCareProviderId1", substituteCareProviderIds[0]);
    expectedDataSet.addReplacementObject("$substituteCareProviderId2", substituteCareProviderIds[1]);
    helper.assertEquals(new String[] { "IDENTIFIER", "BKGRCHK_DT", "LST_UPD_TS" }, new String[] { "ENTITY_ID" });
}
Also used : DBUnitAssertHelper(gov.ca.cwds.cals.persistence.DBUnitAssertHelper) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet)

Aggregations

ReplacementDataSet (org.dbunit.dataset.ReplacementDataSet)17 DBUnitAssertHelper (gov.ca.cwds.cals.persistence.DBUnitAssertHelper)6 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 Connection (java.sql.Connection)3 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)3 FlatXmlDataSet (org.dbunit.dataset.xml.FlatXmlDataSet)3 FlatXmlDataSetBuilder (org.dbunit.dataset.xml.FlatXmlDataSetBuilder)3 DatabaseEnvironment (io.shardingjdbc.core.common.env.DatabaseEnvironment)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 DatabaseUnitException (org.dbunit.DatabaseUnitException)2 DataSetException (org.dbunit.dataset.DataSetException)2 IDataSet (org.dbunit.dataset.IDataSet)2 ITable (org.dbunit.dataset.ITable)2 Reader (java.io.Reader)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1