Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Consolidate config for DbUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Nov 3, 2015
1 parent 08cf5a9 commit 8157fe9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
4 changes: 0 additions & 4 deletions zanata-war/src/test/java/org/zanata/ArquillianTest.java
Expand Up @@ -99,10 +99,6 @@ private static IDatabaseConnection getConnection() {
"java:jboss/datasources/zanataDatasource");
DatabaseConnection dbConn =
new DatabaseConnection(dataSource.getConnection());
// NB: Specific to H2
dbConn.getConfig().setProperty(
DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new H2DataTypeFactory());
return dbConn;
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
4 changes: 0 additions & 4 deletions zanata-war/src/test/java/org/zanata/RestTest.java
Expand Up @@ -184,10 +184,6 @@ private static IDatabaseConnection getConnection() {
"java:jboss/datasources/zanataDatasource");
DatabaseConnection dbConn =
new DatabaseConnection(dataSource.getConnection());
// NB: Specific to H2
dbConn.getConfig().setProperty(
DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new H2DataTypeFactory());
return dbConn;
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
19 changes: 5 additions & 14 deletions zanata-war/src/test/java/org/zanata/ZanataDbunitJpaTest.java
Expand Up @@ -20,6 +20,7 @@
import org.dbunit.dataset.datatype.DataTypeException;
import org.dbunit.dataset.datatype.DefaultDataTypeFactory;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.ext.h2.H2DataTypeFactory;
import org.dbunit.operation.DatabaseOperation;
import org.hibernate.internal.SessionImpl;
import org.junit.After;
Expand Down Expand Up @@ -232,8 +233,10 @@ public String toString() {
// TODO This is hibernate specific
protected IDatabaseConnection getConnection() {
try {
return new DatabaseConnection(
DatabaseConnection dbConn = new DatabaseConnection(
((SessionImpl) getSession()).connection());
editConfig(dbConn.getConfig());
return dbConn;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -291,19 +294,7 @@ protected void enableReferentialIntegrity(IDatabaseConnection con) {
* and features
*/
protected void editConfig(DatabaseConfig config) {
// DBUnit/HSQL bugfix
// http://www.carbonfive.com/community/archives/2005/07/dbunit_hsql_and.html
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new DefaultDataTypeFactory() {
@Override
public DataType createDataType(int sqlType,
String sqlTypeName) throws DataTypeException {
if (sqlType == Types.BOOLEAN) {
return DataType.BOOLEAN;
}
return super.createDataType(sqlType, sqlTypeName);
}
});
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
}

/**
Expand Down
16 changes: 3 additions & 13 deletions zanata-war/src/test/java/org/zanata/provider/DBUnitProvider.java
Expand Up @@ -37,6 +37,7 @@
import org.dbunit.dataset.datatype.DataTypeException;
import org.dbunit.dataset.datatype.DefaultDataTypeFactory;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.dbunit.ext.h2.H2DataTypeFactory;
import org.dbunit.operation.DatabaseOperation;

/**
Expand Down Expand Up @@ -113,6 +114,7 @@ protected void executeOperations(List<DataSetOperation> list) {
IDatabaseConnection con = null;
try {
con = getConnection();
editConfig(con.getConfig());
disableReferentialIntegrity(con);
for (DataSetOperation op : list) {
prepareExecution(con, op);
Expand Down Expand Up @@ -312,19 +314,7 @@ protected void enableReferentialIntegrity(IDatabaseConnection con) {
* and features
*/
protected void editConfig(DatabaseConfig config) {
// DBUnit/HSQL bugfix
// http://www.carbonfive.com/community/archives/2005/07/dbunit_hsql_and.html
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new DefaultDataTypeFactory() {
@Override
public DataType createDataType(int sqlType,
String sqlTypeName) throws DataTypeException {
if (sqlType == Types.BOOLEAN) {
return DataType.BOOLEAN;
}
return super.createDataType(sqlType, sqlTypeName);
}
});
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());
}

/**
Expand Down

0 comments on commit 8157fe9

Please sign in to comment.