Unitils / DBunit tests and databases

I want to try to do a unit test with DBUnit, but I have a problem with my dataset.

Here is my persistence object:

@Entity @Table(name = "personnes") public class Personne implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer pk; @Column private String name; } 

And my dataset:

 <?xml version='1.0' encoding='UTF-8'?> <dataset> <personnes name="toto" pk="1" /> </dataset> 

My problem is with the name column, I get this error:

 org.dbunit.dataset.NoSuchColumnException: personnes.NAME - (Non-uppercase input column: name) in ColumnNameToIndexes cache map. Note that the map column names are NOT case sensitive. 

I do not understand why dbunit is looking for the column "NAME", while my column is "name".

Thank you for your help.

+4
source share
4 answers

I struggled with this for a while and keep coming back to this problem, which has no solution yet.

In Unitils 3.4.1, they added a new property org.dbunit.database.IMetadataHandler.implClassName

In my unitils.properties file, I added the following line

 org.dbunit.database.IMetadataHandler.implClassName=org.dbunit.ext.mysql.MySqlMetadataHandler 

Yes, I know, according to the Unitils website, there is no version 3.4.1, but you can get the latest version through Maven.

release report link

+4
source

Since you do not specify a column name in the mapping, I assume that the basic ORM structure generates a column name of "NAME" for it.

To fix this error / warning, you can add the column name to the display

 @Column( name = "name") 

which results in a lowercase column name or uses an uppercase entry in your dataset

 <personnes NAME="toto" pk="1" /> 

leaving the name of the uppercase column.

0
source

You need to set true

 DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES 

inside your DatabaseConfig object.

See org.dbunit.dataset.NoSuchTableException: could not find table "xxx" in schema "null"

0
source

Try setting the factory data type for your databases.

All available plants can be found at this link. http://dbunit.sourceforge.net/apidocs/org/dbunit/dataset/datatype/IDataTypeFactory.html

Choose the factory that belongs to your database.

Add the setUpDatabaseConfig method to your test class and set the factory.

 protected void setUpDatabaseConfig(DatabaseConfig config) { config.setProperty( DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new OracleDataTypeFactory() ); } 
0
source

All Articles