HHH-14503 - Migration of tests from jpa/test to orm/test/jpa

This commit is contained in:
Andrea Boriero 2021-03-26 15:17:19 +01:00
parent a7f242af03
commit 6bd7a4d972
3 changed files with 29 additions and 32 deletions

View File

@ -17,8 +17,8 @@ import org.hibernate.jpa.boot.spi.Bootstrap;
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder; import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest; import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -43,43 +43,39 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT
return new Class[] { Item.class }; return new Class[] { Item.class };
} }
@SuppressWarnings("unchecked")
@Test @Test
@TestForIssue(jiraKey = "HHH-8271") @TestForIssue(jiraKey = "HHH-8271")
public void testSqlLoadScriptSourceClasspath() throws Exception { public void testSqlLoadScriptSourceClasspath() {
Map settings = buildSettings(); Map<Object, Object> settings = buildSettings();
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" );
settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getLoadSqlScript() ); settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getLoadSqlScript() );
doTest( settings ); doTest( settings );
} }
@SuppressWarnings("unchecked")
@Test @Test
@TestForIssue(jiraKey = "HHH-8271") @TestForIssue(jiraKey = "HHH-8271")
public void testSqlLoadScriptSourceUrl() throws Exception { public void testSqlLoadScriptSourceUrl() {
Map settings = buildSettings(); Map<Object, Object> settings = buildSettings();
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" );
settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getResourceUrlString( getLoadSqlScript() ) ); settings.put( AvailableSettings.HBM2DDL_LOAD_SCRIPT_SOURCE, getResourceUrlString( getLoadSqlScript() ) );
doTest( settings ); doTest( settings );
} }
@SuppressWarnings("unchecked")
@Test @Test
@TestForIssue(jiraKey = "HHH-8271") @TestForIssue(jiraKey = "HHH-8271")
public void testSqlCreateScriptSourceClasspath() throws Exception { public void testSqlCreateScriptSourceClasspath() {
Map settings = buildSettings(); Map<Object, Object> settings = buildSettings();
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" );
settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" );
settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getCreateSqlScript() ); settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getCreateSqlScript() );
doTest( settings ); doTest( settings );
} }
@SuppressWarnings("unchecked")
@Test @Test
@TestForIssue(jiraKey = "HHH-8271") @TestForIssue(jiraKey = "HHH-8271")
public void testSqlCreateScriptSourceUrl() throws Exception { public void testSqlCreateScriptSourceUrl() {
Map settings = buildSettings(); Map<Object, Object> settings = buildSettings();
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "create-drop" );
settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_CREATE_SOURCE, "metadata-then-script" );
settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getResourceUrlString( getCreateSqlScript() ) ); settings.put( AvailableSettings.HBM2DDL_CREATE_SCRIPT_SOURCE, getResourceUrlString( getCreateSqlScript() ) );
@ -87,22 +83,20 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT
} }
@SuppressWarnings("unchecked")
@Test @Test
@TestForIssue(jiraKey = "HHH-8271") @TestForIssue(jiraKey = "HHH-8271")
public void testSqlDropScriptSourceClasspath() throws Exception { public void testSqlDropScriptSourceClasspath() {
Map settings = buildSettings(); Map<Object, Object> settings = buildSettings();
settings.put( AvailableSettings.HBM2DDL_DROP_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_DROP_SOURCE, "metadata-then-script" );
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop" );
settings.put( AvailableSettings.HBM2DDL_DROP_SCRIPT_SOURCE, getDropSqlScript() ); settings.put( AvailableSettings.HBM2DDL_DROP_SCRIPT_SOURCE, getDropSqlScript() );
doTest( settings ); doTest( settings );
} }
@SuppressWarnings("unchecked")
@Test @Test
@TestForIssue(jiraKey = "HHH-8271") @TestForIssue(jiraKey = "HHH-8271")
public void testSqlDropScriptSourceUrl() throws Exception { public void testSqlDropScriptSourceUrl() {
Map settings = buildSettings(); Map<Object, Object> settings = buildSettings();
settings.put( AvailableSettings.HBM2DDL_DROP_SOURCE, "metadata-then-script" ); settings.put( AvailableSettings.HBM2DDL_DROP_SOURCE, "metadata-then-script" );
settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop" ); settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, "drop" );
settings.put( AvailableSettings.HBM2DDL_DROP_SCRIPT_SOURCE, getResourceUrlString( getDropSqlScript() ) ); settings.put( AvailableSettings.HBM2DDL_DROP_SCRIPT_SOURCE, getResourceUrlString( getDropSqlScript() ) );
@ -122,7 +116,7 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT
} }
protected String encodedName() { protected String encodedName() {
return "sch" + (char) 233 +"magen-test"; return "sch" + (char) 233 + "magen-test";
} }
protected String getResourceUrlString(String resource) { protected String getResourceUrlString(String resource) {
@ -133,14 +127,15 @@ public class JpaSchemaGeneratorTest extends EntityManagerFactoryBasedFunctionalT
return url.toString(); return url.toString();
} }
@SuppressWarnings("unchecked") private void doTest(Map<Object, Object> settings) {
private void doTest(Map settings) {
// We want a fresh db after emf close // 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 // 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++ settings.put( "hibernate.connection.url", "jdbc:h2:mem:db-schemagen" + schemagenNumber++
+ ";MVCC=TRUE;LOCK_TIMEOUT=10000" ); + ";MVCC=TRUE;LOCK_TIMEOUT=10000" );
EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder( buildPersistenceUnitDescriptor(), EntityManagerFactoryBuilder emfb = Bootstrap.getEntityManagerFactoryBuilder(
settings ); buildPersistenceUnitDescriptor(),
settings
);
EntityManagerFactory emf = emfb.build(); EntityManagerFactory emf = emfb.build();
try { try {
EntityManager em = emf.createEntityManager(); EntityManager em = emf.createEntityManager();

View File

@ -72,21 +72,19 @@ public class EntityManagerDeserializationTest {
} }
private EntityManager spoofSerialization(EntityManager entityManager) throws IOException { private EntityManager spoofSerialization(EntityManager entityManager) throws IOException {
try { try(ByteArrayOutputStream serBaOut = new ByteArrayOutputStream()) {
// Serialize the incoming out to memory // Serialize the incoming out to memory
ByteArrayOutputStream serBaOut = new ByteArrayOutputStream();
ObjectOutputStream serOut = new ObjectOutputStream( serBaOut ); ObjectOutputStream serOut = new ObjectOutputStream( serBaOut );
serOut.writeObject( entityManager ); serOut.writeObject( entityManager );
// Now, re-constitute the model from memory // Now, re-constitute the model from memory
ByteArrayInputStream serBaIn = try (ByteArrayInputStream serBaIn = new ByteArrayInputStream( serBaOut.toByteArray() ); ObjectInputStream serIn = new ObjectInputStream( serBaIn )) {
new ByteArrayInputStream( serBaOut.toByteArray() ); EntityManager outgoing = (EntityManager) serIn.readObject();
ObjectInputStream serIn = new ObjectInputStream( serBaIn );
EntityManager outgoing = (EntityManager) serIn.readObject(); return outgoing;
}
return outgoing;
} }
catch (ClassNotFoundException cnfe) { catch (ClassNotFoundException cnfe) {
throw new IOException( "Unable to locate class on reconstruction" ); throw new IOException( "Unable to locate class on reconstruction" );

View File

@ -6,13 +6,17 @@
*/ */
package org.hibernate.testing.annotations; package org.hibernate.testing.annotations;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@RequiresDialect(H2Dialect.class)
@Jpa( @Jpa(
annotatedClasses = { annotatedClasses = {
AnEntity.class AnEntity.class