3

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

Samuel
  • 61
  • 6
  • Inserts can only be performed on 'simple' views (views that are based only on one table). You cannot insert records into views that are the results of joins on multiple tables. The first thing you need to do is determine whether or not you can insert into the view. – Paul Croarkin Apr 29 '11 at 13:23
  • Probably you want to add data to the tables that actually are used for having the views... – Cris Apr 29 '11 at 13:59
  • Well, views are made to switch to different set of tables in db without modify java code... – Samuel Apr 29 '11 at 14:12
  • Perhaps this would be a good time for your organization to implement a proper DAO layer so that database changes don't impact your project so greatly in the future? – Mike Yockey Apr 29 '11 at 15:09

1 Answers1

2

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.

Samuel
  • 61
  • 6