43
43
*
44
44
* @author Costin Leau
45
45
* @author Juergen Hoeller
46
+ * @author Nicholas Williams
46
47
*/
47
48
public class PersistenceXmlParsingTests {
48
49
@@ -60,6 +61,8 @@ public void testMetaInfCase() throws Exception {
60
61
assertEquals (2 , info [0 ].getJarFileUrls ().size ());
61
62
assertEquals (new ClassPathResource ("order.jar" ).getURL (), info [0 ].getJarFileUrls ().get (0 ));
62
63
assertEquals (new ClassPathResource ("order-supplemental.jar" ).getURL (), info [0 ].getJarFileUrls ().get (1 ));
64
+
65
+ assertFalse ("Exclude unlisted should default false in 1.0." , info [0 ].excludeUnlistedClasses ());
63
66
}
64
67
65
68
@ Test
@@ -72,6 +75,8 @@ public void testExample1() throws Exception {
72
75
assertNotNull (info );
73
76
assertEquals (1 , info .length );
74
77
assertEquals ("OrderManagement" , info [0 ].getPersistenceUnitName ());
78
+
79
+ assertFalse ("Exclude unlisted should default false in 1.0." , info [0 ].excludeUnlistedClasses ());
75
80
}
76
81
77
82
@ Test
@@ -89,6 +94,8 @@ public void testExample2() throws Exception {
89
94
assertEquals (1 , info [0 ].getMappingFileNames ().size ());
90
95
assertEquals ("mappings.xml" , info [0 ].getMappingFileNames ().get (0 ));
91
96
assertEquals (0 , info [0 ].getProperties ().keySet ().size ());
97
+
98
+ assertFalse ("Exclude unlisted should default false in 1.0." , info [0 ].excludeUnlistedClasses ());
92
99
}
93
100
94
101
@ Test
@@ -109,6 +116,8 @@ public void testExample3() throws Exception {
109
116
assertEquals (0 , info [0 ].getProperties ().keySet ().size ());
110
117
assertNull (info [0 ].getJtaDataSource ());
111
118
assertNull (info [0 ].getNonJtaDataSource ());
119
+
120
+ assertFalse ("Exclude unlisted should default false in 1.0." , info [0 ].excludeUnlistedClasses ());
112
121
}
113
122
114
123
@ Test
@@ -134,7 +143,7 @@ public void testExample4() throws Exception {
134
143
assertEquals ("com.acme.Customer" , info [0 ].getManagedClassNames ().get (1 ));
135
144
assertEquals ("com.acme.Item" , info [0 ].getManagedClassNames ().get (2 ));
136
145
137
- assertTrue (info [0 ].excludeUnlistedClasses ());
146
+ assertTrue ("Exclude unlisted should be true when no value." , info [0 ].excludeUnlistedClasses ());
138
147
139
148
assertSame (PersistenceUnitTransactionType .RESOURCE_LOCAL , info [0 ].getTransactionType ());
140
149
assertEquals (0 , info [0 ].getProperties ().keySet ().size ());
@@ -163,6 +172,8 @@ public void testExample5() throws Exception {
163
172
164
173
assertEquals ("com.acme.AcmePersistence" , info [0 ].getPersistenceProviderClassName ());
165
174
assertEquals (0 , info [0 ].getProperties ().keySet ().size ());
175
+
176
+ assertFalse ("Exclude unlisted should default false in 1.0." , info [0 ].excludeUnlistedClasses ());
166
177
}
167
178
168
179
@ Test
@@ -206,6 +217,8 @@ public void testExampleComplex() throws Exception {
206
217
207
218
assertSame (ds , pu1 .getJtaDataSource ());
208
219
220
+ assertFalse ("Exclude unlisted should default false in 1.0." , pu1 .excludeUnlistedClasses ());
221
+
209
222
PersistenceUnitInfo pu2 = info [1 ];
210
223
211
224
assertSame (PersistenceUnitTransactionType .JTA , pu2 .getTransactionType ());
@@ -222,6 +235,8 @@ public void testExampleComplex() throws Exception {
222
235
223
236
assertNull (pu2 .getJtaDataSource ());
224
237
assertEquals (ds , pu2 .getNonJtaDataSource ());
238
+
239
+ assertTrue ("Exclude unlisted should be true when no value." , pu2 .excludeUnlistedClasses ());
225
240
}
226
241
227
242
@ Test
@@ -233,6 +248,8 @@ public void testExample6() throws Exception {
233
248
assertEquals (1 , info .length );
234
249
assertEquals ("pu" , info [0 ].getPersistenceUnitName ());
235
250
assertEquals (0 , info [0 ].getProperties ().keySet ().size ());
251
+
252
+ assertFalse ("Exclude unlisted should default false in 1.0." , info [0 ].excludeUnlistedClasses ());
236
253
}
237
254
238
255
@ Ignore // not doing schema parsing anymore for JPA 2.0 compatibility
@@ -290,4 +307,66 @@ public void testPersistenceUnitRootUrlWithJar() throws Exception {
290
307
assertTrue ("the archive location should have been returned" , archive .getURL ().sameFile (url ));
291
308
}
292
309
310
+ @ Test
311
+ public void testJpa1ExcludeUnlisted () throws Exception {
312
+ PersistenceUnitReader reader = new PersistenceUnitReader (
313
+ new PathMatchingResourcePatternResolver (), new JndiDataSourceLookup ());
314
+ String resource = "/org/springframework/orm/jpa/persistence-exclude-1.0.xml" ;
315
+ PersistenceUnitInfo [] info = reader .readPersistenceUnitInfos (resource );
316
+
317
+ assertNotNull (info );
318
+ assertEquals ("The number of persistence units is incorrect." , 4 , info .length );
319
+
320
+ PersistenceUnitInfo noExclude = info [0 ];
321
+ assertNotNull ("noExclude should not be null." , noExclude );
322
+ assertEquals ("noExclude name is not correct." , "NoExcludeElement" , noExclude .getPersistenceUnitName ());
323
+ assertFalse ("Exclude unlisted should default false in 1.0." , noExclude .excludeUnlistedClasses ());
324
+
325
+ PersistenceUnitInfo emptyExclude = info [1 ];
326
+ assertNotNull ("emptyExclude should not be null." , emptyExclude );
327
+ assertEquals ("emptyExclude name is not correct." , "EmptyExcludeElement" , emptyExclude .getPersistenceUnitName ());
328
+ assertTrue ("emptyExclude should be true." , emptyExclude .excludeUnlistedClasses ());
329
+
330
+ PersistenceUnitInfo trueExclude = info [2 ];
331
+ assertNotNull ("trueExclude should not be null." , trueExclude );
332
+ assertEquals ("trueExclude name is not correct." , "TrueExcludeElement" , trueExclude .getPersistenceUnitName ());
333
+ assertTrue ("trueExclude should be true." , trueExclude .excludeUnlistedClasses ());
334
+
335
+ PersistenceUnitInfo falseExclude = info [3 ];
336
+ assertNotNull ("falseExclude should not be null." , falseExclude );
337
+ assertEquals ("falseExclude name is not correct." , "FalseExcludeElement" , falseExclude .getPersistenceUnitName ());
338
+ assertFalse ("falseExclude should be false." , falseExclude .excludeUnlistedClasses ());
339
+ }
340
+
341
+ @ Test
342
+ public void testJpa2ExcludeUnlisted () throws Exception {
343
+ PersistenceUnitReader reader = new PersistenceUnitReader (
344
+ new PathMatchingResourcePatternResolver (), new JndiDataSourceLookup ());
345
+ String resource = "/org/springframework/orm/jpa/persistence-exclude-2.0.xml" ;
346
+ PersistenceUnitInfo [] info = reader .readPersistenceUnitInfos (resource );
347
+
348
+ assertNotNull (info );
349
+ assertEquals ("The number of persistence units is incorrect." , 4 , info .length );
350
+
351
+ PersistenceUnitInfo noExclude = info [0 ];
352
+ assertNotNull ("noExclude should not be null." , noExclude );
353
+ assertEquals ("noExclude name is not correct." , "NoExcludeElement" , noExclude .getPersistenceUnitName ());
354
+ assertTrue ("Exclude unlisted should default true in 2.0." , noExclude .excludeUnlistedClasses ());
355
+
356
+ PersistenceUnitInfo emptyExclude = info [1 ];
357
+ assertNotNull ("emptyExclude should not be null." , emptyExclude );
358
+ assertEquals ("emptyExclude name is not correct." , "EmptyExcludeElement" , emptyExclude .getPersistenceUnitName ());
359
+ assertTrue ("emptyExclude should be true." , emptyExclude .excludeUnlistedClasses ());
360
+
361
+ PersistenceUnitInfo trueExclude = info [2 ];
362
+ assertNotNull ("trueExclude should not be null." , trueExclude );
363
+ assertEquals ("trueExclude name is not correct." , "TrueExcludeElement" , trueExclude .getPersistenceUnitName ());
364
+ assertTrue ("trueExclude should be true." , trueExclude .excludeUnlistedClasses ());
365
+
366
+ PersistenceUnitInfo falseExclude = info [3 ];
367
+ assertNotNull ("falseExclude should not be null." , falseExclude );
368
+ assertEquals ("falseExclude name is not correct." , "FalseExcludeElement" , falseExclude .getPersistenceUnitName ());
369
+ assertFalse ("falseExclude should be false." , falseExclude .excludeUnlistedClasses ());
370
+ }
371
+
293
372
}
0 commit comments