28
28
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
29
29
import org .springframework .orm .jpa .domain .DriversLicense ;
30
30
import org .springframework .orm .jpa .domain .Person ;
31
- import org .springframework .test .annotation .ExpectedException ;
32
- import org .springframework .test .annotation .NotTransactional ;
33
- import org .springframework .test .annotation .Repeat ;
34
- import org .springframework .test .annotation .Timed ;
31
+ import org .springframework .transaction .annotation .Propagation ;
32
+ import org .springframework .transaction .annotation .Transactional ;
35
33
import org .springframework .util .SerializationTestUtils ;
36
34
37
35
/**
42
40
* @author Juergen Hoeller
43
41
*/
44
42
@ SuppressWarnings ("deprecation" )
45
- public abstract class AbstractContainerEntityManagerFactoryIntegrationTests
46
- extends AbstractEntityManagerFactoryIntegrationTests {
43
+ public abstract class AbstractContainerEntityManagerFactoryIntegrationTests extends
44
+ AbstractEntityManagerFactoryIntegrationTests {
47
45
48
- @ NotTransactional
46
+ @ Transactional ( propagation = Propagation . NOT_SUPPORTED )
49
47
public void testEntityManagerFactoryImplementsEntityManagerFactoryInfo () {
50
48
assertTrue (Proxy .isProxyClass (entityManagerFactory .getClass ()));
51
- assertTrue ("Must have introduced config interface" ,
52
- entityManagerFactory instanceof EntityManagerFactoryInfo );
49
+ assertTrue ("Must have introduced config interface" , entityManagerFactory instanceof EntityManagerFactoryInfo );
53
50
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo ) entityManagerFactory ;
54
- //assertEquals("Person", emfi.getPersistenceUnitName());
51
+ // assertEquals("Person", emfi.getPersistenceUnitName());
55
52
assertNotNull ("PersistenceUnitInfo must be available" , emfi .getPersistenceUnitInfo ());
56
53
assertNotNull ("Raw EntityManagerFactory must be available" , emfi .getNativeEntityManagerFactory ());
57
54
}
58
55
59
56
public void testStateClean () {
60
- assertEquals ("Should be no people from previous transactions" ,
61
- 0 , countRowsInTable ("person" ));
57
+ assertEquals ("Should be no people from previous transactions" , 0 , countRowsInTable ("person" ));
58
+ }
59
+
60
+ public void testJdbcTx1_1 () {
61
+ testJdbcTx2 ();
62
+ }
63
+
64
+ public void testJdbcTx1_2 () {
65
+ testJdbcTx2 ();
62
66
}
63
67
64
- @ Repeat (5 )
65
- public void testJdbcTx1 () throws Exception {
68
+ public void testJdbcTx1_3 () {
66
69
testJdbcTx2 ();
67
70
}
68
71
69
- @ Timed (millis =273 )
70
- public void testJdbcTx2 () throws InterruptedException {
71
- //Thread.sleep(2000);
72
+ public void testJdbcTx2 () {
72
73
assertEquals ("Any previous tx must have been rolled back" , 0 , countRowsInTable ("person" ));
73
- //insertPerson("foo");
74
74
executeSqlScript ("/org/springframework/orm/jpa/insertPerson.sql" , false );
75
75
}
76
76
77
- //@NotTransactional
78
77
@ SuppressWarnings ({ "unused" , "unchecked" })
79
78
public void testEntityManagerProxyIsProxy () {
80
79
assertTrue (Proxy .isProxyClass (sharedEntityManager .getClass ()));
@@ -86,21 +85,31 @@ public void testEntityManagerProxyIsProxy() {
86
85
assertTrue ("Close should have been silently ignored" , sharedEntityManager .isOpen ());
87
86
}
88
87
89
- @ ExpectedException (RuntimeException .class )
90
88
public void testBogusQuery () {
91
- Query query = sharedEntityManager .createQuery ("It's raining toads" );
92
- // required in OpenJPA case
93
- query .executeUpdate ();
89
+ try {
90
+ Query query = sharedEntityManager .createQuery ("It's raining toads" );
91
+ // required in OpenJPA case
92
+ query .executeUpdate ();
93
+ fail ("Should have thrown a RuntimeException" );
94
+ }
95
+ catch (RuntimeException e ) {
96
+ /* expected */
97
+ }
94
98
}
95
99
96
- @ ExpectedException (EntityNotFoundException .class )
97
100
public void testGetReferenceWhenNoRow () {
98
- Person notThere = sharedEntityManager .getReference (Person .class , 666 );
101
+ try {
102
+ Person notThere = sharedEntityManager .getReference (Person .class , 666 );
99
103
100
- // We may get here (as with Hibernate).
101
- // Either behaviour is valid: throw exception on first access
102
- // or on getReference itself.
103
- notThere .getFirstName ();
104
+ // We may get here (as with Hibernate).
105
+ // Either behaviour is valid: throw exception on first access
106
+ // or on getReference itself.
107
+ notThere .getFirstName ();
108
+ fail ("Should have thrown an EntityNotFoundException" );
109
+ }
110
+ catch (EntityNotFoundException e ) {
111
+ /* expected */
112
+ }
104
113
}
105
114
106
115
public void testLazyLoading () {
@@ -125,7 +134,6 @@ public void testLazyLoading() {
125
134
}
126
135
finally {
127
136
deleteFromTables (new String [] { "person" , "drivers_license" });
128
- //setComplete();
129
137
}
130
138
}
131
139
@@ -157,12 +165,12 @@ public void testEntityManagerProxyRejectsProgrammaticTxManagement() {
157
165
}
158
166
}
159
167
160
- // public void testAspectJInjectionOfConfigurableEntity() {
161
- // Person p = new Person();
162
- // System.err.println(p);
163
- // assertNotNull("Was injected", p.getTestBean());
164
- // assertEquals("Ramnivas", p.getTestBean().getName());
165
- // }
168
+ // public void testAspectJInjectionOfConfigurableEntity() {
169
+ // Person p = new Person();
170
+ // System.err.println(p);
171
+ // assertNotNull("Was injected", p.getTestBean());
172
+ // assertEquals("Ramnivas", p.getTestBean().getName());
173
+ // }
166
174
167
175
public void testInstantiateAndSaveWithSharedEmProxy () {
168
176
testInstantiateAndSave (sharedEntityManager );
@@ -194,7 +202,7 @@ public void testQueryNoPersons() {
194
202
}
195
203
}
196
204
197
- @ NotTransactional
205
+ @ Transactional ( propagation = Propagation . NOT_SUPPORTED )
198
206
@ SuppressWarnings ("unchecked" )
199
207
public void testQueryNoPersonsNotTransactional () {
200
208
EntityManager em = entityManagerFactory .createEntityManager ();
@@ -225,7 +233,7 @@ public void testQueryNoPersonsShared() {
225
233
}
226
234
}
227
235
228
- @ NotTransactional
236
+ @ Transactional ( propagation = Propagation . NOT_SUPPORTED )
229
237
@ SuppressWarnings ("unchecked" )
230
238
public void testQueryNoPersonsSharedNotTransactional () {
231
239
EntityManager em = SharedEntityManagerCreator .createSharedEntityManager (entityManagerFactory );
@@ -238,7 +246,9 @@ public void testQueryNoPersonsSharedNotTransactional() {
238
246
fail ("Should have thrown IllegalStateException" );
239
247
}
240
248
catch (Exception ex ) {
241
- // IllegalStateException expected, but PersistenceException thrown by Hibernate
249
+ // IllegalStateException expected, but PersistenceException thrown by
250
+ // Hibernate
251
+ System .err .println (ex );
242
252
assertTrue (ex .getMessage ().indexOf ("closed" ) != -1 );
243
253
}
244
254
q = em .createQuery ("select p from Person as p" );
0 commit comments