2121import org .hibernate .query .Query ;
2222import org .hibernate .ScrollMode ;
2323import org .hibernate .Session ;
24- import org .hibernate .orm .test .jpa .BaseEntityManagerFunctionalTestCase ;
2524import org .hibernate .orm .test .jpa .callbacks .RemoteControl ;
2625import org .hibernate .orm .test .jpa .callbacks .Television ;
2726import org .hibernate .orm .test .jpa .callbacks .VideoSystem ;
4039import org .hibernate .orm .test .jpa .metamodel .ShelfLife ;
4140import org .hibernate .orm .test .jpa .metamodel .Spouse ;
4241
42+ import org .hibernate .testing .orm .junit .EntityManagerFactoryScope ;
4343import org .hibernate .testing .orm .junit .JiraKey ;
44- import org .hibernate .testing .transaction .TransactionUtil ;
45- import org .junit .Assert ;
46- import org .junit .Before ;
47- import org .junit .Test ;
44+ import org .hibernate .testing .orm .junit .Jpa ;
45+ import org .junit .jupiter .api .Assertions ;
46+ import org .junit .jupiter .api .Test ;
47+ import org .junit .jupiter .api .AfterEach ;
48+ import org .junit .jupiter .api .BeforeEach ;
4849
4950import static org .hamcrest .core .Is .is ;
50- import static org .junit .Assert .assertThat ;
51+ import static org .hamcrest .MatcherAssert .assertThat ;
52+ import static org .junit .jupiter .api .Assertions .assertEquals ;
5153
5254/**
5355 * @author Steve Ebersole
5456 */
55- public class CriteriaCompilingTest extends BaseEntityManagerFunctionalTestCase {
56- @ Override
57- public Class [] getAnnotatedClasses () {
58- return new Class [] {
59- Customer .class ,
60- Alias .class ,
61- Phone .class ,
62- Address .class ,
63- Country .class ,
64- CreditCard .class ,
65- Info .class ,
66- Spouse .class ,
67- LineItem .class ,
68- Order .class ,
69- Product .class ,
70- ShelfLife .class ,
71- // @Inheritance
72- Fruit .class ,
73- Strawberry .class ,
74- // @MappedSuperclass
75- VideoSystem .class ,
76- Television .class ,
77- RemoteControl .class
78- };
79- }
80-
81- @ Before
82- public void setUp (){
83- TransactionUtil .doInJPA ( this ::entityManagerFactory , entityManager -> {
57+ @ Jpa (annotatedClasses = {
58+ Customer .class ,
59+ Alias .class ,
60+ Phone .class ,
61+ Address .class ,
62+ Country .class ,
63+ CreditCard .class ,
64+ Info .class ,
65+ Spouse .class ,
66+ LineItem .class ,
67+ Order .class ,
68+ Product .class ,
69+ ShelfLife .class ,
70+ // @Inheritance
71+ Fruit .class ,
72+ Strawberry .class ,
73+ // @MappedSuperclass
74+ VideoSystem .class ,
75+ Television .class ,
76+ RemoteControl .class
77+ })
78+ public class CriteriaCompilingTest {
79+
80+ @ BeforeEach
81+ public void setUp (EntityManagerFactoryScope scope ){
82+ scope .inTransaction ( entityManager -> {
8483 Customer customer = new Customer ();
8584 customer .setId ( "id" );
8685 customer .setName ( " David R. Vincent " );
@@ -92,11 +91,16 @@ public void setUp(){
9291 } );
9392 }
9493
94+ @ AfterEach
95+ public void cleanupTestData (EntityManagerFactoryScope scope ) {
96+ scope .getEntityManagerFactory ().getSchemaManager ().truncate ();
97+ }
98+
9599 @ Test
96- public void testTrim () {
100+ public void testTrim (EntityManagerFactoryScope scope ) {
97101 final String expectedResult = "David R. Vincent" ;
98102
99- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
103+ scope . inTransaction ( entityManager -> {
100104
101105 CriteriaBuilder cb = entityManager .getCriteriaBuilder ();
102106
@@ -122,14 +126,14 @@ public void testTrim() {
122126 TypedQuery <String > tq = entityManager .createQuery ( cquery );
123127
124128 String result = tq .getSingleResult ();
125- Assert . assertEquals ( "Mismatch in received results" , expectedResult , result );
129+ assertEquals ( expectedResult , result , "Mismatch in received results" );
126130 } );
127131 }
128132
129133 @ Test
130134 @ JiraKey (value = "HHH-11393" )
131- public void testTrimAChar () {
132- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
135+ public void testTrimAChar (EntityManagerFactoryScope scope ) {
136+ scope . inTransaction ( entityManager -> {
133137 final CriteriaBuilder criteriaBuilder = entityManager .getCriteriaBuilder ();
134138 final CriteriaQuery <Customer > query = criteriaBuilder .createQuery ( Customer .class );
135139 final Root <Customer > from = query .from ( Customer .class );
@@ -146,8 +150,8 @@ public void testTrimAChar() {
146150 }
147151
148152 @ Test
149- public void testJustSimpleRootCriteria () {
150- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
153+ public void testJustSimpleRootCriteria (EntityManagerFactoryScope scope ) {
154+ scope . inTransaction ( entityManager -> {
151155 // First w/o explicit selection...
152156 CriteriaQuery <Customer > criteria = entityManager .getCriteriaBuilder ().createQuery ( Customer .class );
153157 criteria .from ( Customer .class );
@@ -162,8 +166,8 @@ public void testJustSimpleRootCriteria() {
162166 }
163167
164168 @ Test
165- public void testSimpleJoinCriteria () {
166- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
169+ public void testSimpleJoinCriteria (EntityManagerFactoryScope scope ) {
170+ scope . inTransaction ( entityManager -> {
167171
168172 // String based...
169173 CriteriaQuery <Order > criteria = entityManager .getCriteriaBuilder ().createQuery ( Order .class );
@@ -175,8 +179,8 @@ public void testSimpleJoinCriteria() {
175179 }
176180
177181 @ Test
178- public void testSimpleFetchCriteria () {
179- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
182+ public void testSimpleFetchCriteria (EntityManagerFactoryScope scope ) {
183+ scope . inTransaction ( entityManager -> {
180184
181185 // String based...
182186 CriteriaQuery <Order > criteria = entityManager .getCriteriaBuilder ().createQuery ( Order .class );
@@ -188,8 +192,8 @@ public void testSimpleFetchCriteria() {
188192 }
189193
190194 @ Test
191- public void testSerialization () {
192- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
195+ public void testSerialization (EntityManagerFactoryScope scope ) {
196+ scope . inTransaction ( entityManager -> {
193197
194198 CriteriaQuery <Order > criteria = entityManager .getCriteriaBuilder ().createQuery ( Order .class );
195199 Root <Order > root = criteria .from ( Order .class );
@@ -204,8 +208,8 @@ public void testSerialization() {
204208
205209 @ Test
206210 @ JiraKey (value = "HHH-10960" )
207- public void testDeprecation () {
208- TransactionUtil . doInJPA ( this :: entityManagerFactory , entityManager -> {
211+ public void testDeprecation (EntityManagerFactoryScope scope ) {
212+ scope . inTransaction ( entityManager -> {
209213
210214 Session session = entityManager .unwrap ( Session .class );
211215 CriteriaBuilder builder = session .getCriteriaBuilder ();
@@ -244,13 +248,8 @@ private <T> T serializeDeserialize(T object) {
244248 byteIn .close ();
245249 }
246250 catch (Exception e ) {
247- Assert .fail ( "Unable to serialize / deserialize the object: " + e .getMessage () );
251+ Assertions .fail ( "Unable to serialize / deserialize the object: " + e .getMessage () );
248252 }
249253 return serializedObject ;
250254 }
251-
252- @ Override
253- public void releaseResources () {
254- super .releaseResources ();
255- }
256255}
0 commit comments