HHH-17019 Move tests to bytecode folder

This commit is contained in:
Andrea Boriero 2023-08-02 11:46:36 +02:00 committed by Andrea Boriero
parent c971b16e14
commit 1b1ed23964
2 changed files with 26 additions and 11 deletions

View File

@ -4,9 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.orm.test.jpa.callbacks; package org.hibernate.orm.test.bytecode.enhancement.callbacks;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -26,6 +24,8 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.PostLoad; import jakarta.persistence.PostLoad;
import static org.assertj.core.api.Assertions.assertThat;
@JiraKey("HHH-17019") @JiraKey("HHH-17019")
@RunWith(BytecodeEnhancerRunner.class) @RunWith(BytecodeEnhancerRunner.class)
public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase { public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
@ -38,15 +38,16 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
@After @After
public void tearDown() { public void tearDown() {
inTransaction( session -> { inTransaction( session -> {
session.createQuery( "delete from Tag" ).executeUpdate(); session.createQuery( "delete from Tag" ).executeUpdate();
session.createQuery( "delete from Person" ).executeUpdate(); session.createQuery( "delete from Person" ).executeUpdate();
} }
); );
} }
@Test @Test
public void smoke() { public void smoke() {
inTransaction( session -> { inTransaction(
session -> {
Person person = new Person( 1, "name" ); Person person = new Person( 1, "name" );
Tag tag = new Tag( 100, person ); Tag tag = new Tag( 100, person );
person.tags.add( tag ); person.tags.add( tag );
@ -56,10 +57,14 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
} }
); );
inTransaction( session -> { inTransaction(
session -> {
Tag tag = session.find( Tag.class, 100 ); Tag tag = session.find( Tag.class, 100 );
assertThat( tag ) assertThat( tag )
.isNotNull(); .isNotNull();
assertThat( TagListener.WAS_CALLED ).isTrue();
assertThat( PersonListener.WAS_CALLED ).isFalse();
assertThat( tag.person.name ).isEqualTo( "name" ); assertThat( tag.person.name ).isEqualTo( "name" );
assertThat( PersonListener.WAS_CALLED ).isTrue(); assertThat( PersonListener.WAS_CALLED ).isTrue();
} }
@ -87,6 +92,7 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
} }
@Entity(name = "Tag") @Entity(name = "Tag")
@EntityListeners(TagListener.class)
public static class Tag { public static class Tag {
@Id @Id
@ -112,4 +118,13 @@ public class PostLoadLazyListenerTest extends BaseCoreFunctionalTestCase {
WAS_CALLED = true; WAS_CALLED = true;
} }
} }
public static class TagListener {
static boolean WAS_CALLED = false;
@PostLoad
void onPreUpdate(Object o) {
WAS_CALLED = true;
}
}
} }

View File

@ -4,7 +4,7 @@
* License: GNU Lesser General Public License (LGPL), version 2.1 or later. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/ */
package org.hibernate.orm.test.jpa.callbacks; package org.hibernate.orm.test.bytecode.enhancement.callbacks;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
@ -22,8 +22,8 @@ import jakarta.persistence.PreUpdate;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -31,7 +31,7 @@ import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
@TestForIssue(jiraKey = "HHH-12718") @JiraKey("HHH-12718")
@RunWith(BytecodeEnhancerRunner.class) @RunWith(BytecodeEnhancerRunner.class)
public class PreUpdateBytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase { public class PreUpdateBytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase {