Search in sources :

Example 6 with ReplacementDataSet

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

the class RFA1aCoreSubmitApplicationTest method testIfPlacementHomeInformationWasCreatedProperly.

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

Example 7 with ReplacementDataSet

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

the class RFA1aCoreSubmitApplicationTest method testIfPlacementHomeProfileWasCreatedProperly.

private void testIfPlacementHomeProfileWasCreatedProperly(String placementHomeId) throws Exception {
    DBUnitAssertHelper helper = DBUnitAssertHelper.builder(dbUnitSupport).setExpectedResultTemplatePath("/dbunit/PlacementHomeProfile.xml").setTestedTableName("HM_PRFT").appendTableFilter("FKPLC_HM_T", placementHomeId).build();
    ReplacementDataSet expectedDataSet = helper.getExpectedDataSet();
    expectedDataSet.addReplacementObject("$placementHomeId", placementHomeId);
    helper.assertEquals(new String[] { "THIRD_ID", "LST_UPD_TS" });
}
Also used : DBUnitAssertHelper(gov.ca.cwds.cals.persistence.DBUnitAssertHelper) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet)

Example 8 with ReplacementDataSet

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

the class DBUnitAssertHelper method getReplacementDataSet.

private ReplacementDataSet getReplacementDataSet(IDataSet dataSet) throws Exception {
    ReplacementDataSet replacementDataSet = new ReplacementDataSet(dataSet);
    replacementDataSet.addReplacementObject("[NULL]", null);
    replacementDataSet.addReplacementObject("[CURRENT_DATE]", LocalDate.now().toString());
    return replacementDataSet;
}
Also used : ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet)

Example 9 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project sharding-jdbc by shardingjdbc.

the class SQLAssertHelper method executeQueryWithPreparedStatement.

/**
 * Execute query with prepared statement.
 *
 * @param isExecute is execute method
 * @param abstractDataSourceAdapter data source adapter
 * @param parameters parameters
 * @param file file
 *
 * @throws MalformedURLException malformed URL exception
 * @throws SQLException SQL exception
 * @throws DatabaseUnitException database unit exception
 */
public void executeQueryWithPreparedStatement(final boolean isExecute, final AbstractDataSourceAdapter abstractDataSourceAdapter, final List<String> parameters, final File file) throws MalformedURLException, SQLException, DatabaseUnitException {
    try (Connection conn = abstractDataSourceAdapter.getConnection();
        PreparedStatement preparedStatement = conn.prepareStatement(SQLPlaceholderUtil.replacePreparedStatement(sql))) {
        setParameters(preparedStatement, parameters);
        ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file));
        expectedDataSet.addReplacementObject("[null]", null);
        for (ITable each : expectedDataSet.getTables()) {
            String tableName = each.getTableMetaData().getTableName();
            IDatabaseConnection connection = DBUnitUtil.getConnection(new DatabaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn);
            ITable actualTable;
            if (isExecute) {
                actualTable = createTable(tableName, preparedStatement, connection);
            } else {
                actualTable = connection.createTable(tableName, preparedStatement);
            }
            Assertion.assertEquals(expectedDataSet.getTable(tableName), actualTable);
        }
    }
}
Also used : DatabaseEnvironment(io.shardingjdbc.core.common.env.DatabaseEnvironment) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) PreparedStatement(java.sql.PreparedStatement) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

Example 10 with ReplacementDataSet

use of org.dbunit.dataset.ReplacementDataSet in project sharding-jdbc by shardingjdbc.

the class SQLAssertHelper method executeQueryWithStatement.

/**
 * Execute query with statement.
 *
 * @param abstractDataSourceAdapter data source adapter
 * @param parameters parameters
 * @param file file
 *
 * @throws MalformedURLException malformed URL exception
 * @throws SQLException SQL exception
 * @throws DatabaseUnitException database unit exception
 */
public void executeQueryWithStatement(final AbstractDataSourceAdapter abstractDataSourceAdapter, final List<String> parameters, final File file) throws MalformedURLException, SQLException, DatabaseUnitException {
    try (Connection conn = abstractDataSourceAdapter.getConnection()) {
        String querySql = SQLPlaceholderUtil.replaceStatement(sql, parameters.toArray());
        ReplacementDataSet expectedDataSet = new ReplacementDataSet(new FlatXmlDataSetBuilder().build(file));
        expectedDataSet.addReplacementObject("[null]", null);
        for (ITable each : expectedDataSet.getTables()) {
            String tableName = each.getTableMetaData().getTableName();
            IDatabaseConnection connection = DBUnitUtil.getConnection(new DatabaseEnvironment(DatabaseType.valueFrom(conn.getMetaData().getDatabaseProductName())), conn);
            ITable actualTable = connection.createQueryTable(tableName, querySql);
            // TODO customized CachedResultSetTable with statement
            Assertion.assertEquals(expectedDataSet.getTable(tableName), actualTable);
        }
    }
}
Also used : DatabaseEnvironment(io.shardingjdbc.core.common.env.DatabaseEnvironment) ReplacementDataSet(org.dbunit.dataset.ReplacementDataSet) Connection(java.sql.Connection) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) FlatXmlDataSetBuilder(org.dbunit.dataset.xml.FlatXmlDataSetBuilder)

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