Unitils Integrated Dbunit problem-solutions

Source: Internet
Author: User

Unitils when integrating Dbunit, if the database is MySQL, some of the following will appear:

Org.unitils.core.UnitilsException:Error inserting test data from DbUnit DataSet for method ...

Org.dbunit.dataset.NoSuchColumnException ...

The reasons for the above two errors are: Unitils default is to use the "Defaultmetadatahandler.java" class to load the database information, so that the database schema value is not available, The implementation code in Defaultmetadatahandler.java is as follows:

Boolean areEqual =                 areequalignorenull (catalog, CatalogName, casesensitive) &&                areequalignorenull ( Schema, SchemaName, casesensitive) &&                areequalignorenull (table, TableName, casesensitive) &&                areequalignorenull (column, ColumnName, casesensitive);

This time the schemaname is empty, but the schema is passed in to have value, thus error!

Solutions Two types:

1, change the source code, remove the catalog and schema comparison

2, write an extension class, to inherit Dbunitmodule, the code is as follows:

 Import Org.dbunit.database.databaseconfig;import Org.dbunit.ext.mysql.mysqldatatypefactory;import Org.dbunit.ext.mysql.mysqlmetadatahandler;import Org.unitils.dbunit.dbunitmodule;import Org.unitils.dbunit.util.dbunitdatabaseconnection;public class Mysqldbunitmodule extends Dbunitmodule {@Override Pub Lic dbunitdatabaseconnection getdbunitdatabaseconnection (final String schemaName) {Dbunitdatabaseconne        ction result = Dbunitdatabaseconnections. Get (SchemaName);        if (null! = result) {return result;        } result = Super.getdbunitdatabaseconnection (schemaName); Result.getconfig (). SetProperty (Databaseconfig.property_datatype_factory, New MYSQLDATATYPEF        Actory ()); Result.getconfig (). SetProperty (Databaseconfig.property_metadata_handler, New Mysqlmetadatah        Andler ());    return result; }}

Then modify the Unitils-default.properties file under the Unitils-core jar package,

Unitils.module.dbunit.classname=org.unitils.dbunit.dbunitmodule changed to the following:

Unitils.module.dbunit.classname=org.unitils.dbunit.mysqldbunitmodule

If you use your own defined profile unitils.properties, you only need to modify the custom profile so that you do not need to modify the unitils-default.properties in the jar

Of course, the premise of these problems is that the database being used is the case of MySQL, and the solution ~

Reprint: http://www.cnblogs.com/candle806/p/3807590.html

Unitils Integrated Dbunit problem-solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.