HHH-6073 : test fix up

This commit is contained in:
Steve Ebersole 2011-04-05 16:08:59 -05:00
parent 5e8e49d3ae
commit bd5c483b67
2 changed files with 24 additions and 4 deletions

View File

@ -35,8 +35,12 @@ import java.sql.SQLException;
@SuppressWarnings( {"UnnecessaryBoxing"})
public class Mocks {
public static Connection createConnection(String dbName, int version) {
DatabaseMetaDataHandler metadataHandler = new DatabaseMetaDataHandler( dbName, version );
public static Connection createConnection(String databaseName, int majorVersion) {
return createConnection( databaseName, majorVersion, -9999 );
}
public static Connection createConnection(String databaseName, int majorVersion, int minorVersion) {
DatabaseMetaDataHandler metadataHandler = new DatabaseMetaDataHandler( databaseName, majorVersion, minorVersion );
ConnectionHandler connectionHandler = new ConnectionHandler();
DatabaseMetaData metadataProxy = ( DatabaseMetaData ) Proxy.newProxyInstance(
@ -90,6 +94,7 @@ public class Mocks {
private static class DatabaseMetaDataHandler implements InvocationHandler {
private final String databaseName;
private final int majorVersion;
private final int minorVersion;
private Connection connectionProxy;
@ -98,8 +103,13 @@ public class Mocks {
}
private DatabaseMetaDataHandler(String databaseName, int majorVersion) {
this( databaseName, majorVersion, -9999 );
}
private DatabaseMetaDataHandler(String databaseName, int majorVersion, int minorVersion) {
this.databaseName = databaseName;
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
}
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

View File

@ -33,6 +33,8 @@ import org.hibernate.HibernateException;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.DB2Dialect;
import org.hibernate.dialect.DerbyDialect;
import org.hibernate.dialect.DerbyTenFiveDialect;
import org.hibernate.dialect.DerbyTenSixDialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.InformixDialect;
@ -123,7 +125,10 @@ public class DialectFactoryTest extends BaseUnitTestCase {
testDetermination( "H2", H2Dialect.class, resolver );
testDetermination( "MySQL", MySQLDialect.class, resolver );
testDetermination( "PostgreSQL", PostgreSQLDialect.class, resolver );
testDetermination( "Apache Derby", DerbyDialect.class, resolver );
testDetermination( "Apache Derby", 10, 4, DerbyDialect.class, resolver );
testDetermination( "Apache Derby", 10, 5, DerbyTenFiveDialect.class, resolver );
testDetermination( "Apache Derby", 10, 6, DerbyTenSixDialect.class, resolver );
testDetermination( "Apache Derby", 11, 5, DerbyTenSixDialect.class, resolver );
testDetermination( "Ingres", IngresDialect.class, resolver );
testDetermination( "ingres", IngresDialect.class, resolver );
testDetermination( "INGRES", IngresDialect.class, resolver );
@ -197,9 +202,14 @@ public class DialectFactoryTest extends BaseUnitTestCase {
}
private void testDetermination(String databaseName, int databaseMajorVersion, Class clazz, DialectResolver resolver) {
testDetermination( databaseName, databaseMajorVersion, -9999, clazz, resolver );
}
private void testDetermination(String databaseName, int majorVersion, int minorVersion, Class clazz, DialectResolver resolver) {
dialectFactory.setDialectResolver( resolver );
Properties properties = new Properties();
Connection conn = Mocks.createConnection( databaseName, databaseMajorVersion );
Connection conn = Mocks.createConnection( databaseName, majorVersion, minorVersion );
assertEquals( clazz, dialectFactory.buildDialect( properties, conn ).getClass() );
}
}