HHH-14503 - Migration of tests from jpa/test to orm/test/jpa
This commit is contained in:
parent
a7f242af03
commit
6bd7a4d972
|
@ -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<Object, Object> 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<Object, Object> 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<Object, Object> 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<Object, Object> 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<Object, Object> 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<Object, Object> 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<Object, Object> 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();
|
||||
|
|
|
@ -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" );
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue