Some more adjustments for commit f9937f6

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2021-01-25 23:25:56 +01:00
parent 24b79133f2
commit 5d768af983
16 changed files with 179 additions and 103 deletions

View File

@ -21,7 +21,6 @@
/**
* @author Steve Ebersole
*/
// TODO Convert to annotation based testing? Setting the CachingRegionFactory as below leads to a CNFE
@Jpa(
annotatedClasses = Order.class,
integrationSettings = {

View File

@ -8,6 +8,7 @@
import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
/**
@ -15,6 +16,18 @@
*/
public class AssociationTest extends EntityManagerFactoryBasedFunctionalTest {
@AfterEach
public void tearDown() {
inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Incident" ).executeUpdate();
entityManager.createQuery( "delete from IncidentStatus" ).executeUpdate();
entityManager.createQuery( "delete from Oven" ).executeUpdate();
entityManager.createQuery( "delete from Kitchen" ).executeUpdate();
}
);
}
@Test
public void testBidirOneToOne() {
final String id = "10";
@ -29,12 +42,6 @@ public void testBidirOneToOne() {
entityManager.persist( i );
}
} );
inTransaction(
entityManager -> {
entityManager.remove( entityManager.find( Incident.class, id ) );
} );
}
@Test
@ -55,12 +62,6 @@ public void testMergeAndBidirOneToOne() {
return entityManager.merge( persistedOven );
}
);
inTransaction(
entityManager -> {
entityManager.remove( entityManager.find( Oven.class, mergedOven.getId() ) );
} );
}
@Override

View File

@ -15,6 +15,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -26,17 +27,22 @@
@Jpa(
annotatedClasses = {
Cat.class,
Kitten.class,
Plant.class,
Television.class,
RemoteControl.class,
Translation.class,
Rythm.class
Kitten.class
},
properties = { @Setting(name = AvailableSettings.JPA_CALLBACKS_ENABLED, value = "false") }
)
public class CallbacksDisabledTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Kitten" ).executeUpdate();
entityManager.createQuery( "delete from Cat" ).executeUpdate();
}
);
}
@Test
public void testCallbacksAreDisabled(EntityManagerFactoryScope scope) {
scope.inTransaction(

View File

@ -24,6 +24,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -36,6 +37,16 @@
})
public class PreUpdateNewBidirectionalBagTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Tag" ).executeUpdate();
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Test
public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
Person person = new Person();
@ -68,13 +79,6 @@ public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
assertNotNull( p.getLastUpdatedAt() );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Tag" ).executeUpdate();
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Entity(name = "Person")

View File

@ -23,6 +23,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -35,6 +36,15 @@
})
public class PreUpdateNewUnidirectionalBagTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Test
public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
Person person = new Person();
@ -66,12 +76,6 @@ public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
assertNotNull( p.getLastUpdatedAt() );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Entity(name = "Person")

View File

@ -28,6 +28,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -40,6 +41,15 @@
})
public class PreUpdateNewUnidirectionalIdBagTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Test
public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
Person person = new Person();
@ -71,12 +81,6 @@ public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
assertNotNull( p.getLastUpdatedAt() );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Entity(name = "Person")

View File

@ -28,6 +28,7 @@
import org.hibernate.testing.util.ExceptionUtil;
import org.junit.Rule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.jboss.logging.Logger;
@ -49,6 +50,16 @@ public class PrivateConstructorTest {
.getName()
) );
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Child" ).executeUpdate();
entityManager.createQuery( "delete from Parent" ).executeUpdate();
}
);
}
@Test
public void test(EntityManagerFactoryScope scope) {
Child child = new Child();
@ -73,13 +84,6 @@ public void test(EntityManagerFactoryScope scope) {
assertTrue( triggerable.wasTriggered() );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Child" ).executeUpdate();
entityManager.createQuery( "delete from Parent" ).executeUpdate();
}
);
}
private static Class<? extends ProxyFactory> proxyFactoryClass() {

View File

@ -16,12 +16,10 @@
import javax.persistence.ManyToOne;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -33,6 +31,16 @@
})
public class ProtectedConstructorTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Child" ).executeUpdate();
entityManager.createQuery( "delete from Parent" ).executeUpdate();
}
);
}
@Test
public void test(EntityManagerFactoryScope scope) {
Child child = new Child();
@ -47,13 +55,6 @@ public void test(EntityManagerFactoryScope scope) {
assertEquals( child.getParent().getName(), childReference.getParent().getName() );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Child" ).executeUpdate();
entityManager.createQuery( "delete from Parent" ).executeUpdate();
}
);
}
@Entity(name = "Parent")

View File

@ -10,6 +10,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -22,6 +23,15 @@
)
public class EntityListenerViaXmlTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from MyEntity" ).executeUpdate();
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-9771")
public void testUsage(EntityManagerFactoryScope scope) {
@ -32,9 +42,5 @@ public void testUsage(EntityManagerFactoryScope scope) {
);
assertEquals( 1, JournalingListener.getPrePersistCount() );
scope.inTransaction(
entityManager -> entityManager.createQuery( "delete MyEntity" ).executeUpdate()
);
}
}

View File

@ -9,6 +9,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
/**
@ -21,6 +22,19 @@
Author.class
})
public class CascadeTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Student" ).executeUpdate();
entityManager.createQuery( "delete from Teacher" ).executeUpdate();
entityManager.createQuery( "delete from Song" ).executeUpdate();
entityManager.createQuery( "delete from Author" ).executeUpdate();
}
);
}
@Test
public void testCascade(EntityManagerFactoryScope scope) {
scope.inTransaction(
@ -51,13 +65,6 @@ public void testCascade(EntityManagerFactoryScope scope) {
}
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Student" ).executeUpdate();
entityManager.createQuery( "delete from Teacher" ).executeUpdate();
}
);
}
@Test
@ -80,12 +87,5 @@ public void testNoCascadeAndMerge(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> entityManager.merge( s2 )
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Song" ).executeUpdate();
entityManager.createQuery( "delete from Author" ).executeUpdate();
}
);
}
}

View File

@ -17,6 +17,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNull;
@ -29,6 +30,17 @@
Soldier.class
})
public class DeleteOrphanTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Soldier" ).executeUpdate();
entityManager.createQuery( "delete from Troop" ).executeUpdate();
}
);
}
@Test
public void testDeleteOrphan(EntityManagerFactoryScope scope) throws Exception {
Troop disney = new Troop();
@ -66,13 +78,6 @@ public void testDeleteOrphan(EntityManagerFactoryScope scope) throws Exception {
entityManager.remove( _troop );
}
);
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Soldier" ).executeUpdate();
entityManager.createQuery( "delete from Troop" ).executeUpdate();
}
);
}
private byte[] serialize(Object object) throws IOException {

View File

@ -18,6 +18,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static javax.persistence.CascadeType.DETACH;
@ -34,6 +35,17 @@
DetachAndContainsTest.Tooth.class
})
public class DetachAndContainsTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from DetachAndContainsTest$Tooth" ).executeUpdate();
entityManager.createQuery( "delete from DetachAndContainsTest$Mouth" ).executeUpdate();
}
);
}
@Test
public void testDetach(EntityManagerFactoryScope scope) {
Tooth tooth = new Tooth();
@ -58,10 +70,6 @@ public void testDetach(EntityManagerFactoryScope scope) {
assertFalse( entityManager.contains( _tooth ) );
}
);
scope.inTransaction(
entityManager -> entityManager.remove( entityManager.find( Mouth.class, mouth.id ) )
);
}
@Entity

View File

@ -14,6 +14,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
@ -33,6 +34,23 @@
Grandson.class
})
public class FetchTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Soldier" ).executeUpdate();
entityManager.createQuery( "delete from Troop" ).executeUpdate();
entityManager.createQuery( "delete from Grandson" ).executeUpdate();
entityManager.createQuery( "delete from Son" ).executeUpdate();
entityManager.createQuery( "delete from Parent" ).executeUpdate();
entityManager.createQuery( "delete from ExtractionDocument" ).executeUpdate();
entityManager.createQuery( "delete from ExtractionDocumentInfo" ).executeUpdate();
entityManager.createQuery( "delete from Conference" ).executeUpdate();
}
);
}
@Test
public void testCascadeAndFetchCollection(EntityManagerFactoryScope scope) {
Troop disney = new Troop();
@ -53,13 +71,6 @@ public void testCascadeAndFetchCollection(EntityManagerFactoryScope scope) {
}
);
assertFalse( Hibernate.isInitialized( troop2.getSoldiers() ) );
scope.inTransaction(
entityManager -> {
Troop troop = entityManager.find( Troop.class, disney.getId() );
entityManager.remove( troop );
}
);
}
@Test
@ -82,13 +93,6 @@ public void testCascadeAndFetchEntity(EntityManagerFactoryScope scope) {
}
);
assertFalse( Hibernate.isInitialized( soldier2.getTroop() ) );
scope.inTransaction(
entityManager -> {
Troop troop = entityManager.find( Troop.class, disney.getId() );
entityManager.remove( troop );
}
);
}
@Test
@ -119,7 +123,6 @@ public void testTwoLevelDeepPersist(EntityManagerFactoryScope scope) {
assertTrue( Hibernate.isInitialized( _jbwBarcelona ) );
assertTrue( Hibernate.isInitialized( _jbwBarcelona.getExtractionDocument() ) );
assertFalse( Hibernate.isInitialized( _jbwBarcelona.getExtractionDocument().getDocuments() ) );
entityManager.remove( _jbwBarcelona );
}
);
}
@ -140,7 +143,6 @@ public void testTwoLevelDeepPersistOnManyToOne(EntityManagerFactoryScope scope)
entityManager.flush();
assertTrue( Hibernate.isInitialized( _gs.getParent() ) );
assertFalse( Hibernate.isInitialized( _gs.getParent().getParent() ) );
entityManager.remove( _gs );
}
);
}

View File

@ -9,6 +9,7 @@
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.fail;
@ -18,6 +19,17 @@
Soldier2.class
})
public class FetchTest2 {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Soldier2" ).executeUpdate();
entityManager.createQuery( "delete from Troop2" ).executeUpdate();
}
);
}
@Test
public void testProxyTransientStuff(EntityManagerFactoryScope scope) {
Troop2 disney = new Troop2();

View File

@ -17,6 +17,7 @@
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -27,6 +28,16 @@
})
public class MergeTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from MergeTest$Item" ).executeUpdate();
entityManager.createQuery( "delete from MergeTest$Order" ).executeUpdate();
}
);
}
@Test
public void testMergeDetachedEntityWithNewOneToManyElements(EntityManagerFactoryScope scope) {
Order order = new Order();
@ -57,7 +68,6 @@ public void testMergeDetachedEntityWithNewOneToManyElements(EntityManagerFactory
entityManager -> {
Order _order = entityManager.find( Order.class, order.id );
assertEquals( 2, _order.items.size() );
entityManager.remove( _order );
}
);
}
@ -90,7 +100,6 @@ public void testMergeLoadedEntityWithNewOneToManyElements(EntityManagerFactorySc
entityManager -> {
Order _order = entityManager.find( Order.class, order.id );
assertEquals( 2, _order.items.size() );
entityManager.remove( _order );
}
);
}

View File

@ -10,6 +10,7 @@
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -23,6 +24,17 @@
})
public class MultiLevelCascadeTest {
@AfterEach
public void tearDown(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Middle" ).executeUpdate();
entityManager.createQuery( "delete from Bottom" ).executeUpdate();
entityManager.createQuery( "delete from Top" ).executeUpdate();
}
);
}
@TestForIssue(jiraKey = "HHH-5299")
@Test
public void test(EntityManagerFactoryScope scope) {
@ -61,7 +73,6 @@ public void test(EntityManagerFactoryScope scope) {
assertSame( found, loadedMiddle.getTop() );
assertNotNull( loadedMiddle.getBottom() );
}
entityManager.remove( found );
}
);
}