Skip to content

Commit

Permalink
Some more adjustments for commit f9937f6
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
  • Loading branch information
jrenaat committed Jan 25, 2021
1 parent 24b7913 commit 5d768af
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 103 deletions.
Expand Up @@ -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 = {
Expand Down
Expand Up @@ -8,13 +8,26 @@


import org.hibernate.testing.junit5.EntityManagerFactoryBasedFunctionalTest;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

/**
* @author Emmanuel Bernard
*/
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";
Expand All @@ -29,12 +42,6 @@ public void testBidirOneToOne() {
entityManager.persist( i );
}
} );

inTransaction(
entityManager -> {
entityManager.remove( entityManager.find( Incident.class, id ) );

} );
}

@Test
Expand All @@ -55,12 +62,6 @@ public void testMergeAndBidirOneToOne() {
return entityManager.merge( persistedOven );
}
);

inTransaction(
entityManager -> {
entityManager.remove( entityManager.find( Oven.class, mergedOven.getId() ) );

} );
}

@Override
Expand Down
Expand Up @@ -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;
Expand All @@ -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(
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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")
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -66,12 +76,6 @@ public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
assertNotNull( p.getLastUpdatedAt() );
}
);

scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}

@Entity(name = "Person")
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -71,12 +81,6 @@ public void testPreUpdateModifications(EntityManagerFactoryScope scope) {
assertNotNull( p.getLastUpdatedAt() );
}
);

scope.inTransaction(
entityManager -> {
entityManager.createQuery( "delete from Person" ).executeUpdate();
}
);
}

@Entity(name = "Person")
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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() {
Expand Down
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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")
Expand Down
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -32,9 +42,5 @@ public void testUsage(EntityManagerFactoryScope scope) {
);

assertEquals( 1, JournalingListener.getPrePersistCount() );

scope.inTransaction(
entityManager -> entityManager.createQuery( "delete MyEntity" ).executeUpdate()
);
}
}
Expand Up @@ -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;

/**
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
);
}
}

0 comments on commit 5d768af

Please sign in to comment.