diff options
Diffstat (limited to 'src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util')
-rw-r--r-- | src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java new file mode 100644 index 0000000..5390841 --- /dev/null +++ b/src/test/java/at/ac/tuwien/sepm/assignment/groupphase/util/JdbcTestCase.java @@ -0,0 +1,50 @@ +package at.ac.tuwien.sepm.assignment.groupphase.util; + +import java.sql.Types; +import org.dbunit.DBTestCase; +import org.dbunit.PropertiesBasedJdbcDatabaseTester; +import org.dbunit.database.DatabaseConfig; +import org.dbunit.dataset.datatype.DataType; +import org.dbunit.dataset.datatype.DataTypeException; +import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; + +public abstract class JdbcTestCase extends DBTestCase { + + private static final String JDBC_DRIVER = "org.h2.Driver"; + private static final String JDBC_URL = + "jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:sql/database.sql'"; + + protected final JDBCConnectionManager jdbcConnectionManager; + + protected JdbcTestCase() { + System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, JDBC_DRIVER); + System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, JDBC_URL); + + jdbcConnectionManager = new JDBCConnectionManager(JDBC_URL); + } + + @Override + protected void setUpDatabaseConfig(DatabaseConfig config) { + PostgresqlDataTypeFactory factory = + new PostgresqlDataTypeFactory() { + @Override + public boolean isEnumType(String sqlTypeName) { + if (sqlTypeName.equalsIgnoreCase("enum")) return true; + + return super.isEnumType(sqlTypeName); + } + + @Override + public DataType createDataType(int sqlType, String sqlTypeName) + throws DataTypeException { + if (isEnumType(sqlTypeName)) { + sqlType = Types.VARCHAR; + } + + return super.createDataType(sqlType, sqlTypeName); + } + }; + + config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, factory); + } +} |