|  | 
| 10 | 10 | import org.hibernate.annotations.Type; | 
| 11 | 11 | import org.hibernate.engine.spi.SessionFactoryImplementor; | 
| 12 | 12 | import org.hibernate.engine.spi.SessionImplementor; | 
|  | 13 | +import org.hibernate.envers.AuditReaderFactory; | 
| 13 | 14 | import org.hibernate.envers.Audited; | 
| 14 | 15 | import org.hibernate.envers.boot.internal.EnversService; | 
| 15 |  | -import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase; | 
| 16 |  | -import org.hibernate.orm.test.envers.Priority; | 
| 17 | 16 | import org.hibernate.persister.entity.EntityPersister; | 
| 18 | 17 | import org.hibernate.type.CustomType; | 
| 19 | 18 | import org.hibernate.usertype.UserType; | 
| 20 | 19 | 
 | 
|  | 20 | +import org.hibernate.testing.envers.junit.EnversTest; | 
|  | 21 | +import org.hibernate.testing.orm.junit.BeforeClassTemplate; | 
|  | 22 | +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; | 
| 21 | 23 | import org.hibernate.testing.orm.junit.JiraKey; | 
| 22 |  | -import org.junit.Test; | 
|  | 24 | +import org.hibernate.testing.orm.junit.Jpa; | 
|  | 25 | +import org.junit.jupiter.api.Test; | 
| 23 | 26 | 
 | 
| 24 | 27 | import jakarta.persistence.Entity; | 
| 25 | 28 | import jakarta.persistence.EnumType; | 
|  | 
| 28 | 31 | import jakarta.persistence.Id; | 
| 29 | 32 | 
 | 
| 30 | 33 | import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; | 
| 31 |  | -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; | 
| 32 |  | -import static org.junit.Assert.assertEquals; | 
| 33 |  | -import static org.junit.Assert.assertNull; | 
|  | 34 | +import static org.junit.jupiter.api.Assertions.assertEquals; | 
|  | 35 | +import static org.junit.jupiter.api.Assertions.assertNull; | 
| 34 | 36 | 
 | 
| 35 | 37 | /** | 
| 36 | 38 |  * Tests that a custom type which extends {@link org.hibernate.orm.test.envers.integration.customtype.EnumType} | 
|  | 
| 42 | 44 |  * @author Chris Cranford | 
| 43 | 45 |  */ | 
| 44 | 46 | @JiraKey(value = "HHH-12304") | 
| 45 |  | -public class ExtendedEnumTypeTest extends BaseEnversJPAFunctionalTestCase { | 
|  | 47 | +@EnversTest | 
|  | 48 | +@Jpa(annotatedClasses = ExtendedEnumTypeTest.Widget.class) | 
|  | 49 | +public class ExtendedEnumTypeTest { | 
| 46 | 50 | 
 | 
| 47 | 51 | 	// An extended type to trigger the need for Envers to supply type information in the HBM mappings. | 
| 48 | 52 | 	// This should be treated the same as any other property annotated as Enumerated or uses an Enum. | 
| @@ -103,63 +107,60 @@ public void setStatus2(Status status2) { | 
| 103 | 107 | 		} | 
| 104 | 108 | 	} | 
| 105 | 109 | 
 | 
| 106 |  | -	@Override | 
| 107 |  | -	protected Class<?>[] getAnnotatedClasses() { | 
| 108 |  | -		return new Class<?>[] { Widget.class }; | 
| 109 |  | -	} | 
| 110 |  | - | 
| 111 | 110 | 	private Integer widgetId; | 
| 112 | 111 | 
 | 
| 113 |  | -	@Test | 
| 114 |  | -	@Priority(10) | 
| 115 |  | -	public void initData() { | 
|  | 112 | +	@BeforeClassTemplate | 
|  | 113 | +	public void initData(EntityManagerFactoryScope scope) { | 
| 116 | 114 | 		// Revision 1 - insert | 
| 117 |  | -		this.widgetId = doInJPA( this::entityManagerFactory, entityManager -> { | 
|  | 115 | +		this.widgetId = scope.fromTransaction( entityManager -> { | 
| 118 | 116 | 			final Widget widget = new Widget( Widget.Status.DRAFT ); | 
| 119 | 117 | 			entityManager.persist( widget ); | 
| 120 | 118 | 			return widget.getId(); | 
| 121 | 119 | 		} ); | 
| 122 | 120 | 
 | 
| 123 | 121 | 		// Revision 2 - update | 
| 124 |  | -		doInJPA( this::entityManagerFactory, entityManager -> { | 
|  | 122 | +		scope.inTransaction( entityManager -> { | 
| 125 | 123 | 			final Widget widget = entityManager.find( Widget.class, this.widgetId ); | 
| 126 | 124 | 			widget.setStatus( Widget.Status.ARCHIVED ); | 
| 127 | 125 | 			entityManager.merge( widget ); | 
| 128 | 126 | 		} ); | 
| 129 | 127 | 
 | 
| 130 | 128 | 		// Revision 3 - delete | 
| 131 |  | -		doInJPA( this::entityManagerFactory, entityManager -> { | 
|  | 129 | +		scope.inTransaction( entityManager -> { | 
| 132 | 130 | 			final Widget widget = entityManager.find( Widget.class, this.widgetId ); | 
| 133 | 131 | 			entityManager.remove( widget ); | 
| 134 | 132 | 		} ); | 
| 135 | 133 | 	} | 
| 136 | 134 | 
 | 
| 137 | 135 | 	@Test | 
| 138 |  | -	public void testRevisionHistory() { | 
| 139 |  | -		List revisions = getAuditReader().getRevisions( Widget.class, this.widgetId ); | 
| 140 |  | -		assertEquals( Arrays.asList( 1, 2, 3 ), revisions ); | 
|  | 136 | +	public void testRevisionHistory(EntityManagerFactoryScope scope) { | 
|  | 137 | +		scope.inEntityManager( em -> { | 
|  | 138 | +			final var auditReader = AuditReaderFactory.get( em ); | 
|  | 139 | +			List revisions = auditReader.getRevisions( Widget.class, this.widgetId ); | 
|  | 140 | +			assertEquals( Arrays.asList( 1, 2, 3 ), revisions ); | 
| 141 | 141 | 
 | 
| 142 |  | -		final Widget rev1 = getAuditReader().find( Widget.class, this.widgetId, 1 ); | 
| 143 |  | -		assertEquals( Widget.Status.DRAFT, rev1.getStatus() ); | 
|  | 142 | +			final Widget rev1 = auditReader.find( Widget.class, this.widgetId, 1 ); | 
|  | 143 | +			assertEquals( Widget.Status.DRAFT, rev1.getStatus() ); | 
| 144 | 144 | 
 | 
| 145 |  | -		final Widget rev2 = getAuditReader().find( Widget.class, this.widgetId, 2 ); | 
| 146 |  | -		assertEquals( Widget.Status.ARCHIVED, rev2.getStatus() ); | 
|  | 145 | +			final Widget rev2 = auditReader.find( Widget.class, this.widgetId, 2 ); | 
|  | 146 | +			assertEquals( Widget.Status.ARCHIVED, rev2.getStatus() ); | 
| 147 | 147 | 
 | 
| 148 |  | -		final Widget rev3 = getAuditReader().find( Widget.class, this.widgetId, 3 ); | 
| 149 |  | -		assertNull( rev3 ); | 
|  | 148 | +			final Widget rev3 = auditReader.find( Widget.class, this.widgetId, 3 ); | 
|  | 149 | +			assertNull( rev3 ); | 
|  | 150 | +		} ); | 
| 150 | 151 | 	} | 
| 151 | 152 | 
 | 
| 152 | 153 | 	@Test | 
| 153 |  | -	public void testEnumPropertyStorageType() { | 
|  | 154 | +	public void testEnumPropertyStorageType(EntityManagerFactoryScope scope) { | 
| 154 | 155 | 		// test that property 'status' translates to an enum type that is stored by name (e.g. STRING) | 
| 155 |  | -		assertEnumProperty( Widget.class, ExtendedEnumType.class, "status", EnumType.STRING ); | 
|  | 156 | +		assertEnumProperty( scope, Widget.class, ExtendedEnumType.class, "status", EnumType.STRING ); | 
| 156 | 157 | 
 | 
| 157 | 158 | 		// test that property 'status2' translates to an enum type that is stored by position (e.g. ORDINAL) | 
| 158 |  | -		assertEnumProperty( Widget.class, ExtendedEnumType.class, "status2", EnumType.ORDINAL ); | 
|  | 159 | +		assertEnumProperty( scope, Widget.class, ExtendedEnumType.class, "status2", EnumType.ORDINAL ); | 
| 159 | 160 | 	} | 
| 160 | 161 | 
 | 
| 161 |  | -	private void assertEnumProperty(Class<?> entityClass, Class<?> typeClass, String propertyName, EnumType expectedType) { | 
| 162 |  | -		doInJPA( this::entityManagerFactory, entityManager -> { | 
|  | 162 | +	private void assertEnumProperty(EntityManagerFactoryScope scope, Class<?> entityClass, Class<?> typeClass, String propertyName, EnumType expectedType) { | 
|  | 163 | +		scope.inEntityManager( entityManager -> { | 
| 163 | 164 | 			final SessionFactoryImplementor sessionFactory = entityManager.unwrap( SessionImplementor.class ).getSessionFactory(); | 
| 164 | 165 | 
 | 
| 165 | 166 | 			final EntityPersister entityPersister = sessionFactory.getMappingMetamodel().getEntityDescriptor( entityClass ); | 
|  | 
0 commit comments