Search code examples
javaoracleviewdbunitunitils

Unitils / DBunit / Oracle - how to insert dataset in oracle views?


It seems to be a simple question. I have some unitils tests in a spring application. The database contains some oracle views and i just want to insert dataset into these views. I know that it is possible to set options to DBunit (Table Type properties). But i find nothing for unitils.

Is there some unitils properties for inserting dataset to views ?

Thank you for help


Solution

  • Ok i think i find a way to configure unitils. But that needs some java code. I have tested this solution, it seems to work.

    First i find some properties in unitils (unitils.properties):

    unitils.module.dbunit.className=org.unitils.dbunit.DbUnitModule
    unitils.module.dbunit.runAfter=
    unitils.module.dbunit.enabled=true
    

    So it seems to be possible to override DBUnitModule like this


    public class DbUnitModule extends org.unitils.dbunit.DbUnitModule implements Module {
        /*
         * (non-Javadoc)
         * 
         * @see org.unitils.dbunit.DbUnitModule#getDbUnitDatabaseConnection(java.lang.String)
         */
        @Override
        public DbUnitDatabaseConnection getDbUnitDatabaseConnection(final String schemaName) {
            DbUnitDatabaseConnection dbConnection = super.getDbUnitDatabaseConnection(schemaName);
            dbConnection.getConfig().setProperty("http://www.dbunit.org/properties/tableType", new String[] { "VIEW", "TABLE" });
            return dbConnection;
        }
    }
    

    And then modify the configuration in unitils.properties.