diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java index 8aa96b65b3..f80948f36a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/uniqueconstraint/MySQLDropConstraintThrowsExceptionTest.java @@ -16,6 +16,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; +import org.hibernate.SessionFactory; import org.hibernate.boot.Metadata; import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistry; @@ -29,6 +30,7 @@ import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.test.util.jdbc.PreparedStatementSpyConnectionProvider; import org.junit.After; +import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertTrue; @@ -40,14 +42,32 @@ import static org.junit.Assert.assertTrue; @RequiresDialect(MySQL5Dialect.class) public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase { - @After - public void releaseResources() { + @Before + public void setUp() { + final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .enableAutoClose() + .applySetting( AvailableSettings.HBM2DDL_AUTO, "drop" ) + .build(); + SessionFactoryImplementor sessionFactory = null; + + try { + final Metadata metadata = new MetadataSources( serviceRegistry ) + .addAnnotatedClass( Customer.class ) + .buildMetadata(); + sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory(); + } + finally { + if ( sessionFactory != null ) { + sessionFactory.close(); + } + StandardServiceRegistryBuilder.destroy( serviceRegistry ); + } } - @Test - public void testEnumTypeInterpretation() { - StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + @After + public void tearDown() { + final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .enableAutoClose() .applySetting( AvailableSettings.HBM2DDL_AUTO, "drop" ) .build(); @@ -67,9 +87,13 @@ public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase { StandardServiceRegistryBuilder.destroy( serviceRegistry ); } - PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); + } - serviceRegistry = new StandardServiceRegistryBuilder() + @Test + public void testEnumTypeInterpretation() { + final PreparedStatementSpyConnectionProvider connectionProvider = new PreparedStatementSpyConnectionProvider(); + + final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .enableAutoClose() .applySetting( AvailableSettings.HBM2DDL_AUTO, "update" ) .applySetting( @@ -78,17 +102,19 @@ public class MySQLDropConstraintThrowsExceptionTest extends BaseUnitTestCase { ) .build(); + SessionFactory sessionFactory = null; try { final Metadata metadata = new MetadataSources( serviceRegistry ) .addAnnotatedClass( Customer.class ) .buildMetadata(); - sessionFactory = (SessionFactoryImplementor) metadata.buildSessionFactory(); + sessionFactory = metadata.buildSessionFactory(); List alterStatements = connectionProvider.getExecuteStatements().stream() - .filter( - sql -> sql.toLowerCase().contains( "alter " ) - ).map( String::trim ).collect( Collectors.toList() ); - assertTrue(alterStatements.get(0).matches( "alter table CUSTOMER\\s+drop index .*?" )); - assertTrue(alterStatements.get(1).matches( "alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)" )); + .filter( + sql -> sql.toLowerCase().contains( "alter " ) + ).map( String::trim ).collect( Collectors.toList() ); + assertTrue( alterStatements.get( 0 ).matches( "alter table CUSTOMER\\s+drop index .*?" ) ); + assertTrue( alterStatements.get( 1 ) + .matches( "alter table CUSTOMER\\s+add constraint .*? unique \\(CUSTOMER_ID\\)" ) ); } finally { if ( sessionFactory != null ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java index a978cddd0e..9242a30a02 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BasicConnectionTest.java @@ -93,6 +93,17 @@ public class BasicConnectionTest extends BaseCoreFunctionalTestCase { assertFalse( getResourceRegistry( jdbcCoord ).hasRegisteredResources() ); } + @Override + protected void cleanupTest() throws Exception { + try (Session session = openSession()) { + session.doWork( connection -> { + final Statement stmnt = connection.createStatement(); + + stmnt.execute( getDialect().getDropTableString( "SANDBOX_JDBC_TST" ) ); + } ); + } + } + private ResourceRegistry getResourceRegistry(JdbcCoordinator jdbcCoord) { return jdbcCoord.getResourceRegistry(); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BatchingTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BatchingTest.java index 4b0990eedf..b64c79778d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/internal/BatchingTest.java @@ -260,4 +260,15 @@ public class BatchingTest extends BaseCoreFunctionalTestCase implements BatchKey session.close(); } + @Override + protected void cleanupTest() throws Exception { + try (Session session = openSession()) { + session.doWork( connection -> { + final Statement stmnt = connection.createStatement(); + + stmnt.execute( getDialect().getDropTableString( "SANDBOX_JDBC_TST" ) ); + } ); + } + } + } diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SequenceReadingTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SequenceReadingTest.java index dabaef5895..e616d3a0f5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SequenceReadingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/SequenceReadingTest.java @@ -23,7 +23,9 @@ import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; +import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; /** @@ -34,7 +36,8 @@ import org.junit.Test; * @see */ @TestForIssue( jiraKey = "HHH-9745" ) -public class SequenceReadingTest { +@RequiresDialect( H2Dialect.class ) +public class SequenceReadingTest extends BaseCoreFunctionalTestCase { @Test public void testSequenceReading() {