alf*_*zqu 7 java postgresql enums dbunit integration-testing
我正在使用DBUnit进行集成测试,在执行测试代码之前,我遇到了这个错误:
badges.track_types data type (2003, '_text') not recognized and will be ignored. See FAQ for more information.
org.dbunit.dataset.NoSuchColumnException: badges.TRACK_TYPES - (Non-uppercase input column: track_types) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
Run Code Online (Sandbox Code Playgroud)
被忽略的列是枚举列表.在数据集中,它是这样编写的:
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
// More info ...
<badges name="30'000" description="30k a day" image_name="30000.png" threshold_val="30000.00000000" has_many="true" id="45" track_types="{TRACK_GENERIC}" "/>
</dataset>
Run Code Online (Sandbox Code Playgroud)
我查看了DBUnit FAQ并看到了这个问题,说我必须覆盖isEnumType()方法来支持我的枚举是Postgresql,所以我这样做了:
/**
* Override method to set custom properties/features
*/
protected void setUpDatabaseConfig(DatabaseConfig config) {
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new PostgresqlDataTypeFactory(){
public boolean isEnumType(String sqlTypeName) {
if(sqlTypeName.equalsIgnoreCase("track_types")){
return true;
}
return false;
}
});
config.setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new DefaultMetadataHandler());
}
Run Code Online (Sandbox Code Playgroud)
但我仍然得到同样的错误,我不知道为什么.也许我没有超越这个方法?也许它甚至不是我的问题的原因?如果您需要任何其他代码,请询问,谢谢!
嗯...我无法准确解决这个问题,但设法通过解决方法解决了这个问题。
该错误是由于 @DatabaseSetup 注释引起的。如果我在不使用它的情况下执行此过程,它仍然会抛出“列无法识别”错误,因为它无法识别 postgres 数组(这是我的根本原因),但我可以通过创建一个扩展的新 DataTypeFactory 来解决它从默认的开始:
public class PsqlArrayDataTypeFactory extends DefaultDataTypeFactory {
public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException {
if (sqlType == Types.ARRAY)
{
return DataType.VARCHAR;
}
return super.createDataType(sqlType, sqlTypeName);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
819 次 |
| 最近记录: |