0

I'm looking forward to integrate dbUnit to a project. The project has Spring and has no ORM. While loading the XML dataSet to the db i'm getting org.dbunit.dataset.NoSuchTableException: XXX_VW "XXX_VW" is a db view. However, I'm able to load the dataset to any table. I've confirmed in db the required view exits and the metadata is similiar.

Below is the code I execute during setup method of my test.

DataSource dc = (MCDataSource) context.getBean("dataSource");
            databaseTester = new DataSourceDatabaseTester(dc, dc.getUsername());
            DatabaseConfig config = databaseTester.getConnection().getConfig();
            config.setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, new String[]{"TABLE", "VIEW"});
            databaseTester.setDataSet(this.getDataSet());
            databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
            databaseTester.onSetup();

Any idea what could be the issue ?

  • As per the debug logs org.dbunit.dataset.OrderedTableNameMap have all schema tables except views. – user2103799 Apr 28 '15 at 11:54
  • I tried to debug further in DatabaseDataSet, even though I've set the table type property to TABLE and VIEW its not getting updated into the config. String[] tableType = (String[])config.getProperty(DatabaseConfig.PROPERTY_TABLE_TYPE); IMetadataHandler metadataHandler = (IMetadataHandler) config.getProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER); – user2103799 Apr 28 '15 at 12:10

1 Answers1

0

Instead implement and setOperationListener and do setProperty during lifecycle methods of OperationListener.

    databaseTester.setOperationListener(new IOperationListener() {

        @Override
        public void operationTearDownFinished(IDatabaseConnection connection) {
            // TODO Auto-generated method stub

        }

        @Override
        public void operationSetUpFinished(IDatabaseConnection connection) {
            // TODO Auto-generated method stub

        }

        @Override
        public void connectionRetrieved(IDatabaseConnection connection) {
            DatabaseConfig config = connection.getConfig();
            config.setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, new String[]{"TABLE", "VIEW"});
    databaseTester.setDataSet(this.getDataSet());
    databaseTester.setTearDownOperation(DatabaseOperation.DELETE_ALL);
    databaseTester.onSetup();