Skip to content

Commit

Permalink
[hibernate#929] Adapt or disable existing tests for H2
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jun 14, 2022
1 parent de4a47d commit eed8d7e
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

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

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

/**
* Test the default port is set correctly when using {@link DefaultSqlClientPoolConfiguration}
*/
public class DefaultPortTest {

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Test
public void testDefaultPortIsSet() throws URISyntaxException {
DefaultSqlClientPoolConfiguration configuration = new DefaultSqlClientPoolConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
import java.util.Collection;
import java.util.List;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;

public class FormulaTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( MARIA, MYSQL );
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( MARIA, MYSQL, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
import org.hibernate.HibernateException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.exception.ConstraintViolationException;
import org.hibernate.reactive.mutiny.Mutiny;

import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

public class MutinyExceptionsTest extends BaseReactiveTest {

@Override
Expand Down Expand Up @@ -48,7 +52,12 @@ public void testDuplicateKeyException(TestContext context) {
.onItem().call( Mutiny.Session::flush )
.onItem().invoke( ignore -> context.fail( "Expected exception not thrown" ) )
.onFailure().recoverWithItem( err -> {
context.assertEquals( getExpectedException(), err.getClass() );
if( dbType() == DatabaseConfiguration.DBType.H2 ) {
context.assertTrue( ConstraintViolationException.class == err.getClass() ||
getExpectedException() == err.getClass() );
} else {
context.assertEquals( getExpectedException(), err.getClass() );
}
return null;
} )
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.vertx.ext.unit.TestContext;

import static java.util.Arrays.asList;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MYSQL;
import static org.hibernate.reactive.testing.DatabaseSelectionRule.runOnlyFor;
Expand Down Expand Up @@ -103,8 +104,8 @@ public String toString() {

public static class ForOtherDbsTest extends UUIDAsBinaryType {

@Rule
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA );
@Rule // Select a UUID field doesn't work with Oracle
public DatabaseSelectionRule rule = skipTestsFor( MYSQL, MARIA, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
import org.hibernate.dialect.SQLServer2012Dialect;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;

public class UriConfigTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Override
protected Configuration constructConfiguration() {
Class<? extends Dialect> dialect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.reactive.containers.DatabaseConfiguration;
import org.hibernate.reactive.provider.Settings;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.ext.unit.TestContext;

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

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

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( H2 );

@Override
protected Configuration constructConfiguration() {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import org.hibernate.HibernateError;
import org.hibernate.reactive.pool.impl.DefaultSqlClientPool;
import org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration;
import org.hibernate.reactive.testing.DatabaseSelectionRule;

import org.junit.Rule;
import org.junit.Test;

import io.vertx.sqlclient.SqlConnectOptions;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.createJdbcUrl;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
import static org.junit.Assert.assertThrows;
Expand All @@ -33,6 +36,9 @@ public class JdbcUrlParserTest {

private static final String DEFAULT_DB = "hreactDB";

@Rule
public DatabaseSelectionRule rule = DatabaseSelectionRule.skipTestsFor( H2 );

@Test
public void exceptionWhenNull() {
final HibernateError error = assertThrows( HibernateError.class, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public enum DBType {
POSTGRESQL( PostgreSQLDatabase.INSTANCE, 5432, "POSTGRES", "PG" ),
COCKROACHDB( CockroachDBDatabase.INSTANCE, 26257, "COCKROACH" ),
SQLSERVER( MSSQLServerDatabase.INSTANCE, 1433, "MSSQL", "MSSQLSERVER" ),
ORACLE( OracleDatabase.INSTANCE, 1521 );
ORACLE( OracleDatabase.INSTANCE, 1521 ),
H2( H2Database.INSTANCE, -1 );

private final TestableDatabase configuration;
private final int defaultPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
import static org.hibernate.reactive.containers.DatabaseConfiguration.dbType;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected Configuration constructConfiguration(String hbm2DdlOption) {
}

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2 );
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2, H2 );

protected Configuration constructConfiguration(String action) {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.persistence.Table;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.GROUPED;
import static org.hibernate.tool.schema.JdbcMetadaAccessStrategy.INDIVIDUALLY;

Expand Down Expand Up @@ -59,7 +60,7 @@ protected Configuration constructConfiguration(String hbm2DdlOption) {
}

@Rule
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2 );
public DatabaseSelectionRule dbRule = DatabaseSelectionRule.skipTestsFor( DB2, H2 );

protected Configuration constructConfiguration(String action) {
Configuration configuration = super.constructConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;

Expand All @@ -34,7 +35,7 @@
public class JsonTypeTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE);
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE, H2);

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.function.Consumer;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.MARIA;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;
Expand All @@ -35,7 +36,7 @@
public class StringToJsonTypeTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, MARIA, ORACLE );
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, MARIA, ORACLE, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.vertx.ext.unit.TestContext;

import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.DB2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.H2;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.ORACLE;
import static org.hibernate.reactive.containers.DatabaseConfiguration.DBType.SQLSERVER;

Expand All @@ -36,7 +37,7 @@
public class UserJsonTypeTest extends BaseReactiveTest {

@Rule
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE );
public DatabaseSelectionRule selectionRule = DatabaseSelectionRule.skipTestsFor( DB2, SQLSERVER, ORACLE, H2 );

@Override
protected Collection<Class<?>> annotatedEntities() {
Expand Down

0 comments on commit eed8d7e

Please sign in to comment.