From 6bd7a4d97272cd1853b82a2e9991f132393e0ca1 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 26 Mar 2021 15:17:19 +0100 Subject: [PATCH] HHH-14503 - Migration of tests from jpa/test to orm/test/jpa --- .../jpa/schemagen/JpaSchemaGeneratorTest.java | 43 ++++++++----------- .../EntityManagerDeserializationTest.java | 14 +++--- .../BasicEntityManagerFactoryScopeTests.java | 4 ++ 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java index f4d07114ce..f6554173e6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/schemagen/JpaSchemaGeneratorTest.java @@ -17,8 +17,8 @@ import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.orm.junit.RequiresDialect; import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest; +import org.hibernate.testing.orm.junit.RequiresDialect; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -43,43 +43,39 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT return new Class[] { Item.class }; } - @SuppressWarnings("unchecked") @Test @TestForIssue(jiraKey = "HHH-8271") - public void testSqlLoadScriptSourceClasspath() throws Exception { - Map settings = buildSettings(); + public void testSqlLoadScriptSourceClasspath() { + Map settings = buildSettings(); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getLoadSqlScript() ); doTest( settings ); } - @SuppressWarnings("unchecked") @Test @TestForIssue(jiraKey = "HHH-8271") - public void testSqlLoadScriptSourceUrl() throws Exception { - Map settings = buildSettings(); + public void testSqlLoadScriptSourceUrl() { + Map settings = buildSettings(); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getResourceUrlString( getLoadSqlScript() ) ); doTest( settings ); } - @SuppressWarnings("unchecked") @Test @TestForIssue(jiraKey = "HHH-8271") - public void testSqlCreateScriptSourceClasspath() throws Exception { - Map settings = buildSettings(); + public void testSqlCreateScriptSourceClasspath() { + Map settings = buildSettings(); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getCreateSqlScript() ); doTest( settings ); } - @SuppressWarnings("unchecked") @Test @TestForIssue(jiraKey = "HHH-8271") - public void testSqlCreateScriptSourceUrl() throws Exception { - Map settings = buildSettings(); + public void testSqlCreateScriptSourceUrl() { + Map settings = buildSettings(); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getResourceUrlString( getCreateSqlScript() ) ); @@ -87,22 +83,20 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT } - @SuppressWarnings("unchecked") @Test @TestForIssue(jiraKey = "HHH-8271") - public void testSqlDropScriptSourceClasspath() throws Exception { - Map settings = buildSettings(); + public void testSqlDropScriptSourceClasspath() { + Map settings = buildSettings(); settings.put( AvailableSettings.HBM2DDL_DROP_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop" ); settings.put( AvailableSettings.HBM2DDL_DROP_SCRIPT_SOURCE, getDropSqlScript() ); doTest( settings ); } - @SuppressWarnings("unchecked") @Test @TestForIssue(jiraKey = "HHH-8271") - public void testSqlDropScriptSourceUrl() throws Exception { - Map settings = buildSettings(); + public void testSqlDropScriptSourceUrl() { + Map settings = buildSettings(); settings.put( AvailableSettings.HBM2DDL_DROP_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop" ); settings.put( AvailableSettings.HBM2DDL_DROP_SCRIPT_SOURCE, getResourceUrlString( getDropSqlScript() ) ); @@ -122,7 +116,7 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT } protected String encodedName() { - return "sch" + (char) 233 +"magen-test"; + return "sch" + (char) 233 + "magen-test"; } protected String getResourceUrlString(String resource) { @@ -133,14 +127,15 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT return url.toString(); } - @SuppressWarnings("unchecked") - private void doTest(Map settings) { + private void doTest(Map settings) { // We want a fresh db after emf close // Unfortunately we have to use this dirty hack because the db seems not to be closed otherwise settings.put( "hibernate.connection.url", "jdbc:h2:mem:db-schemagen" + schemagenNumber++ + ";MVCC=TRUE;LOCK_TIMEOUT=10000" ); - EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder( buildPersistenceUnitDescriptor(), - settings ); + EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder( + buildPersistenceUnitDescriptor(), + settings + ); EntityManagerFactory emf = emfb.build(); try { EntityManager em = emf.createEntityManager(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/serialization/EntityManagerDeserializationTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/serialization/EntityManagerDeserializationTest.java index 09e4af6dbc..bb66987b6d 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/serialization/EntityManagerDeserializationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/serialization/EntityManagerDeserializationTest.java @@ -72,21 +72,19 @@ public class EntityManagerDeserializationTest { } private EntityManager spoofSerialization(EntityManager entityManager) throws IOException { - try { + try(ByteArrayOutputStream serBaOut = new ByteArrayOutputStream()) { // Serialize the incoming out to memory - ByteArrayOutputStream serBaOut = new ByteArrayOutputStream(); + ObjectOutputStream serOut = new ObjectOutputStream( serBaOut ); serOut.writeObject( entityManager ); // Now, re-constitute the model from memory - ByteArrayInputStream serBaIn = - new ByteArrayInputStream( serBaOut.toByteArray() ); - ObjectInputStream serIn = new ObjectInputStream( serBaIn ); + try (ByteArrayInputStream serBaIn = new ByteArrayInputStream( serBaOut.toByteArray() ); ObjectInputStream serIn = new ObjectInputStream( serBaIn )) { + EntityManager outgoing = (EntityManager) serIn.readObject(); - EntityManager outgoing = (EntityManager) serIn.readObject(); - - return outgoing; + return outgoing; + } } catch (ClassNotFoundException cnfe) { throw new IOException( "Unable to locate class on reconstruction" ); diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/annotations/BasicEntityManagerFactoryScopeTests.java b/hibernate-testing/src/test/java/org/hibernate/testing/annotations/BasicEntityManagerFactoryScopeTests.java index bf9d6f750c..a5b5ea5d7a 100644 --- a/hibernate-testing/src/test/java/org/hibernate/testing/annotations/BasicEntityManagerFactoryScopeTests.java +++ b/hibernate-testing/src/test/java/org/hibernate/testing/annotations/BasicEntityManagerFactoryScopeTests.java @@ -6,13 +6,17 @@ */ package org.hibernate.testing.annotations; +import org.hibernate.dialect.H2Dialect; + import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.RequiresDialect; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.notNullValue; +@RequiresDialect(H2Dialect.class) @Jpa( annotatedClasses = { AnEntity.class