Skip to content

Commit ba01e81

Browse files
committed
[#929] adapted tests for H2 dialect
1 parent 8f33ea0 commit ba01e81

15 files changed

+198
-28
lines changed

.github/workflows/tracking-orm-5.build.yml

-19
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,3 @@ jobs:
100100
run: ./gradlew :hibernate-reactive-core:dependencyInsight --dependency org.hibernate:hibernate-core -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep
101101
- name: Build and Test with ${{ matrix.db }}
102102
run: ./gradlew build -Pdb=${{ matrix.db }} -Pdocker -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep -PshowStandardOutput
103-
104-
# test_h2:
105-
# name: Test with ${{ matrix.db }} and ORM ${{ matrix.orm-version }}
106-
# runs-on: ubuntu-latest
107-
# strategy:
108-
# matrix:
109-
# orm-version: [ '[5.6,5.7)' ]
110-
# db: [ 'H2' ]
111-
# steps:
112-
# - uses: actions/checkout@v2
113-
# - name: Set up JDK 11
114-
# uses: actions/setup-java@v1
115-
# with:
116-
# java-version: 11
117-
# - name: Print the effective ORM version used
118-
# run: ./gradlew :hibernate-reactive-core:dependencyInsight --dependency org.hibernate:hibernate-core -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep
119-
# - name: Build and Test with ${{ matrix.db }}
120-
# run: ./gradlew build -Pdb=${{ matrix.db }} -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep -PshowStandardOutput
121-

hibernate-reactive-core/src/test/java/org/hibernate/reactive/DefaultPortTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414
import org.hibernate.reactive.containers.DatabaseConfiguration;
1515
import org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration;
1616
import org.hibernate.reactive.provider.Settings;
17+
import org.hibernate.reactive.testing.DatabaseSelectionRule;
1718

1819
import org.junit.Assert;
20+
import org.junit.Rule;
1921
import org.junit.Test;
2022

2123
import io.vertx.sqlclient.SqlConnectOptions;
2224
import org.assertj.core.api.Assertions;
2325

26+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2427
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
2528

2629
/**
2730
* Test the default port is set correctly when using {@link DefaultSqlClientPoolConfiguration}
2831
*/
2932
public class DefaultPortTest {
3033

34+
@Rule
35+
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );
36+
3137
@Test
3238
public void testDefaultPortIsSet() throws URISyntaxException {
3339
DefaultSqlClientPoolConfiguration configuration = new DefaultSqlClientPoolConfiguration();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/FormulaTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
import java.util.Collection;
2323
import java.util.List;
2424

25+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2526
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
2627
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
2728

2829
public class FormulaTest extends BaseReactiveTest {
2930

3031
@Rule
31-
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( MARIA, MYSQL );
32+
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( MARIA, MYSQL, H2 );
3233

3334
@Override
3435
protected Collection<Class<?>> annotatedEntities() {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MutinyExceptionsTest.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
import org.hibernate.HibernateException;
1616
import org.hibernate.cfg.AvailableSettings;
1717
import org.hibernate.cfg.Configuration;
18+
import org.hibernate.reactive.containers.DatabaseConfiguration;
19+
import org.hibernate.reactive.exception.ConstraintViolationException;
1820
import org.hibernate.reactive.mutiny.Mutiny;
1921

2022
import org.junit.Test;
2123

2224
import io.vertx.ext.unit.TestContext;
2325

26+
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
27+
2428
public class MutinyExceptionsTest extends BaseReactiveTest {
2529

2630
@Override
@@ -48,7 +52,12 @@ public void testDuplicateKeyException(TestContext context) {
4852
.onItem().call( Mutiny.Session::flush )
4953
.onItem().invoke( ignore -> context.fail( "Expected exception not thrown" ) )
5054
.onFailure().recoverWithItem( err -> {
51-
context.assertEquals( getExpectedException(), err.getClass() );
55+
if( dbType() == DatabaseConfiguration.DBType.H2 ) {
56+
context.assertTrue( ConstraintViolationException.class == err.getClass() ||
57+
getExpectedException() == err.getClass() );
58+
} else {
59+
context.assertEquals( getExpectedException(), err.getClass() );
60+
}
5261
return null;
5362
} )
5463
);

hibernate-reactive-core/src/test/java/org/hibernate/reactive/UUIDAsBinaryType.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.vertx.ext.unit.TestContext;
2323

2424
import static java.util.Arrays.asList;
25+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2526
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
2627
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
2728
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
@@ -105,7 +106,7 @@ public String toString() {
105106
public static class ForOtherDbsTest extends UUIDAsBinaryType {
106107

107108
@Rule // Select a UUID field doesn't work with Oracle
108-
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA, ORACLE );
109+
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA, ORACLE, H2 );
109110

110111
@Override
111112
protected Collection<Class<?>> annotatedEntities() {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/UriConfigTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@
1717
import org.hibernate.dialect.SQLServer2012Dialect;
1818
import org.hibernate.reactive.containers.DatabaseConfiguration;
1919
import org.hibernate.reactive.provider.Settings;
20+
import org.hibernate.reactive.testing.DatabaseSelectionRule;
2021

22+
import org.junit.Rule;
2123
import org.junit.Test;
2224

2325
import io.vertx.ext.unit.TestContext;
2426

27+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2528
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
2629

2730
public class UriConfigTest extends BaseReactiveTest {
2831

32+
@Rule
33+
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );
34+
2935
@Override
3036
protected Configuration constructConfiguration() {
3137
Class<? extends Dialect> dialect;

hibernate-reactive-core/src/test/java/org/hibernate/reactive/WrongCredentialsTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
import org.hibernate.cfg.Configuration;
1212
import org.hibernate.reactive.containers.DatabaseConfiguration;
1313
import org.hibernate.reactive.provider.Settings;
14+
import org.hibernate.reactive.testing.DatabaseSelectionRule;
1415

16+
import org.junit.Rule;
1517
import org.junit.Test;
1618

1719
import io.vertx.ext.unit.TestContext;
1820

1921
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2023

2124
/**
2225
* Check that the right exception is thrown when there is an error with the credentials.
@@ -28,6 +31,9 @@
2831
*/
2932
public class WrongCredentialsTest extends BaseReactiveTest {
3033

34+
@Rule
35+
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );
36+
3137
@Override
3238
protected Configuration constructConfiguration() {
3339
Configuration configuration = super.constructConfiguration();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/configuration/JdbcUrlParserTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
import org.hibernate.HibernateError;
1313
import org.hibernate.reactive.pool.impl.DefaultSqlClientPool;
1414
import org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration;
15+
import org.hibernate.reactive.testing.DatabaseSelectionRule;
1516

17+
import org.junit.Rule;
1618
import org.junit.Test;
1719

1820
import io.vertx.sqlclient.SqlConnectOptions;
1921

2022
import static org.assertj.core.api.Assertions.assertThat;
2123
import static org.assertj.core.api.Assertions.fail;
24+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2225
import static org.hibernate.reactive.containers.DatabaseConfiguration.createJdbcUrl;
2326
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
2427
import static org.junit.Assert.assertThrows;
@@ -33,6 +36,9 @@ public class JdbcUrlParserTest {
3336

3437
private static final String DEFAULT_DB = "hreactDB";
3538

39+
@Rule
40+
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( H2 );
41+
3642
@Test
3743
public void exceptionWhenNull() {
3844
final HibernateError error = assertThrows( HibernateError.class, () -> {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/DatabaseConfiguration.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public enum DBType {
2525
POSTGRESQL( PostgreSQLDatabase.INSTANCE, 5432, "POSTGRES", "PG" ),
2626
COCKROACHDB( CockroachDBDatabase.INSTANCE, 26257, "COCKROACH" ),
2727
SQLSERVER( MSSQLServerDatabase.INSTANCE, 1433, "MSSQL", "MSSQLSERVER" ),
28-
ORACLE( OracleDatabase.INSTANCE, 1521 );
28+
ORACLE( OracleDatabase.INSTANCE, 1521 ),
29+
H2( H2Database.INSTANCE, -1 );
2930

3031
private final TestableDatabase configuration;
3132
private final int defaultPort;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/* Hibernate, Relational Persistence for Idiomatic Java
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Copyright: Red Hat Inc. and Hibernate Authors
5+
*/
6+
package org.hibernate.reactive.containers;
7+
8+
import java.io.Serializable;
9+
import java.math.BigDecimal;
10+
import java.math.BigInteger;
11+
import java.net.URL;
12+
import java.sql.Time;
13+
import java.sql.Timestamp;
14+
import java.time.Duration;
15+
import java.time.Instant;
16+
import java.time.LocalDate;
17+
import java.time.LocalDateTime;
18+
import java.time.LocalTime;
19+
import java.util.Date;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import java.util.TimeZone;
23+
import java.util.UUID;
24+
25+
import org.hibernate.type.NumericBooleanType;
26+
import org.hibernate.type.TextType;
27+
import org.hibernate.type.TrueFalseType;
28+
import org.hibernate.type.YesNoType;
29+
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
30+
31+
public class H2Database implements TestableDatabase {
32+
public static H2Database INSTANCE = new H2Database();
33+
34+
private static Map<Class<?>, String> expectedDBTypeForClass = new HashMap<>();
35+
36+
static {
37+
{
38+
expectedDBTypeForClass.put( boolean.class, "BOOLEAN" );
39+
expectedDBTypeForClass.put( Boolean.class, "BOOLEAN" );
40+
expectedDBTypeForClass.put( NumericBooleanType.class, "INTEGER" );
41+
expectedDBTypeForClass.put( TrueFalseType.class, "CHARACTER" );
42+
expectedDBTypeForClass.put( YesNoType.class, "CHARACTER" );
43+
expectedDBTypeForClass.put( int.class, "INTEGER" );
44+
expectedDBTypeForClass.put( Integer.class, "INTEGER" );
45+
expectedDBTypeForClass.put( long.class, "BIGINT" );
46+
expectedDBTypeForClass.put( Long.class, "BIGINT" );
47+
expectedDBTypeForClass.put( float.class, "DOUBLE PRECISION" );
48+
expectedDBTypeForClass.put( Float.class, "DOUBLE PRECISION" );
49+
expectedDBTypeForClass.put( double.class, "DOUBLE PRECISION" );
50+
expectedDBTypeForClass.put( Double.class, "DOUBLE PRECISION" );
51+
expectedDBTypeForClass.put( byte.class, "TINYINT" );
52+
expectedDBTypeForClass.put( Byte.class, "TINYINT" );
53+
expectedDBTypeForClass.put( PrimitiveByteArrayTypeDescriptor.class, "BINARY VARYING" );
54+
expectedDBTypeForClass.put( URL.class, "VARCHAR_IGNORECASE" );
55+
expectedDBTypeForClass.put( TimeZone.class, "VARCHAR_IGNORECASE" );
56+
expectedDBTypeForClass.put( Date.class, "DATE" );
57+
expectedDBTypeForClass.put( Timestamp.class, "TIMESTAMP" );
58+
expectedDBTypeForClass.put( Time.class, "TIME" );
59+
expectedDBTypeForClass.put( LocalDate.class, "DATE" );
60+
expectedDBTypeForClass.put( LocalTime.class, "time" );
61+
expectedDBTypeForClass.put( LocalDateTime.class, "TIMESTAMP" );
62+
expectedDBTypeForClass.put( BigInteger.class, "NUMERIC" );
63+
expectedDBTypeForClass.put( BigDecimal.class, "NUMERIC" );
64+
expectedDBTypeForClass.put( Serializable.class, "BINARY VARYING" );
65+
expectedDBTypeForClass.put( UUID.class, "binary" );
66+
expectedDBTypeForClass.put( Instant.class, "datetime" );
67+
expectedDBTypeForClass.put( Duration.class, "bigint" );
68+
expectedDBTypeForClass.put( Character.class, "VARCHAR_IGNORECASE" );
69+
expectedDBTypeForClass.put( char.class, "VARCHAR_IGNORECASE" );
70+
expectedDBTypeForClass.put( TextType.class, "text" );
71+
expectedDBTypeForClass.put( String.class, "VARCHAR_IGNORECASE" );
72+
}
73+
}
74+
75+
private String getRegularJdbcUrl() {
76+
return "jdbc:h2:~/test;DATABASE_TO_UPPER=FALSE";
77+
}
78+
79+
@Override
80+
public String getJdbcUrl() {
81+
return "jdbc:h2:~/test;DATABASE_TO_UPPER=FALSE";
82+
}
83+
84+
@Override
85+
public String getUri() {
86+
return "h2:~/test;DATABASE_TO_UPPER=FALSE";
87+
}
88+
89+
90+
@Override
91+
public String getScheme() {
92+
return "h2:";
93+
}
94+
95+
@Override
96+
public String getNativeDatatypeQuery(String tableName, String columnName) {
97+
return "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS COLS " +
98+
"WHERE COLS.TABLE_NAME = '" + tableName + "'" +
99+
"AND COLS.COLUMN_NAME= '" + columnName + "'";
100+
}
101+
102+
@Override
103+
public String getExpectedNativeDatatype(Class<?> dataType) {
104+
return expectedDBTypeForClass.get( dataType );
105+
}
106+
107+
@Override
108+
public String createJdbcUrl(String host, int port, String database, Map<String, String> params) {
109+
// Primary mode for H2 is embedded which uses the URL format: "jdbc:h2:~/test"
110+
// H2 can also be configured as a remote server.
111+
// EXAMPLE 1: jdbc:h2:tcp://localhost/D:/myproject/data/project-name
112+
// EXAMPLE 2: jdbc:h2:tcp://localhost/~/test
113+
// EXAMpLE 3: jdbc:h2:tcp://localhost:9081/~/test
114+
final StringBuilder paramsBuilder = new StringBuilder();
115+
if ( params != null && !params.isEmpty() ) {
116+
params.forEach( (key, value) -> {
117+
paramsBuilder.append( jdbcParamDelimiter() );
118+
paramsBuilder.append( key );
119+
paramsBuilder.append( "=" );
120+
paramsBuilder.append( value );
121+
} );
122+
}
123+
String url = "jdbc:" + getScheme() + "//" + host;
124+
if ( port > -1 ) {
125+
url += ":" + port;
126+
}
127+
if ( paramsBuilder.length() > 0 ) {
128+
url += jdbcStartQuery() + paramsBuilder.substring( 1 );
129+
}
130+
if ( database != null ) {
131+
return url + ";database=" + database;
132+
}
133+
return url;
134+
}
135+
136+
@Override
137+
public String jdbcStartQuery() {
138+
return ";";
139+
}
140+
141+
@Override
142+
public String jdbcParamDelimiter() {
143+
return ";";
144+
}
145+
146+
private H2Database() {
147+
}
148+
}

hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaUpdateTestBase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.vertx.ext.unit.TestContext;
2222

2323
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
24+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2425
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
2526
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
2627
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
@@ -53,7 +54,7 @@ protected Configuration constructConfiguration(String hbm2DdlOption) {
5354
}
5455

5556
@Rule
56-
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2 );
57+
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2, H2 );
5758

5859
protected Configuration constructConfiguration(String action) {
5960
Configuration configuration = super.constructConfiguration();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/schema/SchemaValidationTestBase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import javax.persistence.Table;
1313

1414
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
15+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
1516
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
1617
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;
1718

@@ -59,7 +60,7 @@ protected Configuration constructConfiguration(String hbm2DdlOption) {
5960
}
6061

6162
@Rule
62-
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2 );
63+
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2, H2 );
6364

6465
protected Configuration constructConfiguration(String action) {
6566
Configuration configuration = super.constructConfiguration();

hibernate-reactive-core/src/test/java/org/hibernate/reactive/types/JsonTypeTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.vertx.ext.unit.TestContext;
2626

2727
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
28+
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
2829
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
2930
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
3031

@@ -34,7 +35,7 @@
3435
public class JsonTypeTest extends BaseReactiveTest {
3536

3637
@Rule
37-
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE);
38+
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE, H2);
3839

3940
@Override
4041
protected Collection<Class<?>> annotatedEntities() {

0 commit comments

Comments
 (0)