Source Code Cross Referenced for TestCascadeDeleteSimpleRef.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » runtime » ref » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Speedo_1.4.5 » org.objectweb.speedo.runtime.ref 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2001-2004 France Telecom R&D
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */package org.objectweb.speedo.runtime.ref;
018:
019:        import javax.jdo.JDOUserException;
020:        import javax.jdo.PersistenceManager;
021:
022:        import junit.framework.Assert;
023:
024:        import org.objectweb.speedo.SpeedoTestHelper;
025:        import org.objectweb.speedo.pobjects.ref.Group;
026:        import org.objectweb.speedo.pobjects.ref.Meeting;
027:        import org.objectweb.speedo.pobjects.ref.Member;
028:        import org.objectweb.speedo.pobjects.ref.President;
029:
030:        /**
031:         *
032:         * @author S.Col
033:         */
034:        public class TestCascadeDeleteSimpleRef extends SpeedoTestHelper {
035:
036:            public TestCascadeDeleteSimpleRef(String s) {
037:                super (s);
038:            }
039:
040:            protected String getLoggerName() {
041:                return LOG_NAME + "rt.ref.CascadeDeleteSimpleRef";
042:            }
043:
044:            /**
045:             * This method is responsible for the test of the delete of an object that has one-one and one-to-many
046:             * relationships with other classes, but these relationships are empty.
047:             */
048:            public void testCascadeDeleteOneToNone() {
049:                PersistenceManager pm = pmf.getPersistenceManager();
050:
051:                // We create a group. A group can have a president and many members, but not this one.
052:                String gName = "SpeedoCascade";
053:                Group grp = new Group(gName);
054:
055:                // We make the group persistant
056:                pm.makePersistent(grp);
057:
058:                // Get the id
059:                Object gId = pm.getObjectId(grp);
060:
061:                pm.close();
062:
063:                grp = null;
064:
065:                // Check the creation of the group
066:                pm = pmf.getPersistenceManager();
067:                grp = (Group) pm.getObjectById(gId, true);
068:                Assert.assertNotNull("null instance returned for group", grp);
069:                Assert.assertEquals("Bad group name", gName, grp.getName());
070:
071:                /* Delete the group.
072:                 */
073:                pm.currentTransaction().begin();
074:                pm.deletePersistent(grp);
075:                pm.currentTransaction().commit();
076:                pm.close();
077:
078:                // Check that the group has been deleted
079:                pm = pmf.getPersistenceManager();
080:                try {
081:                    grp = (Group) pm.getObjectById(gId, true);
082:                    Assert
083:                            .fail("Should have thrown a JDOUserException : the group has not been deleted");
084:                } catch (JDOUserException jdoEx) {
085:                    // The test has passed
086:                    Assert.assertTrue(true);
087:                }
088:
089:                pm.close();
090:            }
091:
092:            /**
093:             * This method is responsible for the test of the cascade delete of a simple reference. A group has a president and if we delete the group,
094:             * the president should be deleted too.
095:             */
096:            public void testCascadeDeleteOneToOne() {
097:                PersistenceManager pm = pmf.getPersistenceManager();
098:
099:                // A president
100:                String pName = "Boss";
101:                President pres = new President(pName);
102:
103:                // A group
104:                String gName = "SpeedoCascade";
105:                Group grp = new Group(gName, pres);
106:                pres.setGroup(grp);
107:
108:                // We make the group persistant
109:                pm.makePersistent(grp);
110:
111:                // Get the ids
112:                Object gId = pm.getObjectId(grp);
113:                Object pId = pm.getObjectId(grp.getPresident());
114:
115:                pm.close();
116:
117:                grp = null;
118:                pres = null;
119:
120:                // Check the creation of the group and its president
121:                pm = pmf.getPersistenceManager();
122:                grp = (Group) pm.getObjectById(gId, true);
123:                pres = (President) pm.getObjectById(pId, true);
124:                Assert.assertNotNull("null instance returned for group", grp);
125:                Assert.assertEquals("Bad group name", gName, grp.getName());
126:                Assert.assertNotNull("null instance returned for president",
127:                        pres);
128:                Assert
129:                        .assertEquals("Bad president name", pName, pres
130:                                .getName());
131:
132:                /* Delete the group :
133:                 * this should delete the president.
134:                 */
135:                pm.currentTransaction().begin();
136:                pm.deletePersistent(grp);
137:                pm.currentTransaction().commit();
138:                pm.close();
139:
140:                // Check that the president has been deleted
141:                pm = pmf.getPersistenceManager();
142:                try {
143:                    pres = (President) pm.getObjectById(pId, true);
144:                    Assert
145:                            .fail("Should have thrown a JDOUserException : the president has not been deleted");
146:                } catch (JDOUserException jdoEx) {
147:                    // The test has passed
148:                    Assert.assertTrue(true);
149:                }
150:
151:                pm.close();
152:            }
153:
154:            /**
155:             * This method is responsible for the test of the cascade delete of a simple reference. The group has 2 members.
156:             */
157:            public void testCascadeDeleteOneToTwo() {
158:                PersistenceManager pm = pmf.getPersistenceManager();
159:
160:                // A group
161:                String gName = "SpeedoCascade";
162:                Group grp = new Group(gName);
163:
164:                // Two members
165:                String m1Name = "Jean";
166:                String m2Name = "Sophie";
167:                Member mem1 = new Member(m1Name, grp);
168:                Member mem2 = new Member(m2Name, grp);
169:
170:                // We make the members persistant
171:                pm.makePersistent(mem1);
172:                pm.makePersistent(mem2);
173:
174:                // Get the ids
175:                Object m1Id = pm.getObjectId(mem1);
176:                Object m2Id = pm.getObjectId(mem2);
177:                Object gId = pm.getObjectId(grp);
178:
179:                pm.close();
180:
181:                mem1 = null;
182:                mem2 = null;
183:                grp = null;
184:
185:                // Check the creation of the group and its members
186:                pm = pmf.getPersistenceManager();
187:                mem1 = (Member) pm.getObjectById(m1Id, true);
188:                mem2 = (Member) pm.getObjectById(m2Id, true);
189:                grp = (Group) pm.getObjectById(gId, true);
190:                Assert.assertNotNull("null instance for the member 1", mem1);
191:                Assert
192:                        .assertEquals("Bad member 1 name", m1Name, mem1
193:                                .getName());
194:                Assert.assertNotNull("null instance for the member 2", mem2);
195:                Assert
196:                        .assertEquals("Bad member 2 name", m2Name, mem2
197:                                .getName());
198:                Assert.assertNotNull("null instance returned for group", grp);
199:                Assert.assertEquals("Bad group name", gName, grp.getName());
200:
201:                /* Delete the group :
202:                 * this should delete both members.
203:                 */
204:                pm.currentTransaction().begin();
205:                pm.deletePersistent(grp);
206:                pm.currentTransaction().commit();
207:                pm.close();
208:
209:                // Check that the members have been deleted
210:                pm = pmf.getPersistenceManager();
211:                try {
212:                    mem1 = (Member) pm.getObjectById(m1Id, true);
213:
214:                    // Delete both members
215:                    pm.currentTransaction().begin();
216:                    pm.deletePersistent(mem1);
217:                    pm.deletePersistent(mem2);
218:                    pm.currentTransaction().commit();
219:                    Assert
220:                            .fail("Should have thrown a JDOUserException : member 1 has not been deleted");
221:                } catch (JDOUserException jdoEx) {
222:                    // The test has passed
223:                    Assert.assertTrue(true);
224:                }
225:                try {
226:                    mem2 = (Member) pm.getObjectById(m2Id, true);
227:                    Assert
228:                            .fail("Should have thrown a JDOUserException : member 2 has not been deleted");
229:                } catch (JDOUserException jdoEx) {
230:                    // The test has passed
231:                    Assert.assertTrue(true);
232:                }
233:
234:                pm.close();
235:            }
236:
237:            /**
238:             * This method is responsible for the test of the cascade delete of a simple reference. A group with 10 members.
239:             */
240:            public void testCascadeDeleteOneToMany() {
241:                PersistenceManager pm = pmf.getPersistenceManager();
242:
243:                // A group
244:                String gName = "SpeedoCascade";
245:                Group grp = new Group(gName);
246:
247:                // Two members
248:                String m1Name = "Jean";
249:                String m2Name = "Sophie";
250:                String m3Name = "Alain";
251:                String m4Name = "Sylvie";
252:                String m5Name = "Jeanne";
253:                String m6Name = "Rose";
254:                String m7Name = "Baptiste";
255:                String m8Name = "Alexandre";
256:                String m9Name = "Noemie";
257:                String m10Name = "Eve";
258:                Member mem1 = new Member(m1Name, grp);
259:                Member mem2 = new Member(m2Name, grp);
260:                Member mem3 = new Member(m3Name, grp);
261:                Member mem4 = new Member(m4Name, grp);
262:                Member mem5 = new Member(m5Name, grp);
263:                Member mem6 = new Member(m6Name, grp);
264:                Member mem7 = new Member(m7Name, grp);
265:                Member mem8 = new Member(m8Name, grp);
266:                Member mem9 = new Member(m9Name, grp);
267:                Member mem10 = new Member(m10Name, grp);
268:
269:                // We make the members persistant
270:                pm.makePersistent(mem1);
271:                pm.makePersistent(mem2);
272:                pm.makePersistent(mem3);
273:                pm.makePersistent(mem4);
274:                pm.makePersistent(mem5);
275:                pm.makePersistent(mem6);
276:                pm.makePersistent(mem7);
277:                pm.makePersistent(mem8);
278:                pm.makePersistent(mem9);
279:                pm.makePersistent(mem10);
280:
281:                // Get the ids
282:                Object m1Id = pm.getObjectId(mem1);
283:                Object m2Id = pm.getObjectId(mem2);
284:                Object m3Id = pm.getObjectId(mem3);
285:                Object m4Id = pm.getObjectId(mem4);
286:                Object m5Id = pm.getObjectId(mem5);
287:                Object m6Id = pm.getObjectId(mem6);
288:                Object m7Id = pm.getObjectId(mem7);
289:                Object m8Id = pm.getObjectId(mem8);
290:                Object m9Id = pm.getObjectId(mem9);
291:                Object m10Id = pm.getObjectId(mem10);
292:                Object gId = pm.getObjectId(grp);
293:
294:                pm.close();
295:
296:                mem1 = null;
297:                mem2 = null;
298:                mem3 = null;
299:                mem4 = null;
300:                mem5 = null;
301:                mem6 = null;
302:                mem7 = null;
303:                mem8 = null;
304:                mem9 = null;
305:                mem10 = null;
306:                grp = null;
307:
308:                // Check the creation of the employee and the department
309:                pm = pmf.getPersistenceManager();
310:                mem1 = (Member) pm.getObjectById(m1Id, true);
311:                mem2 = (Member) pm.getObjectById(m2Id, true);
312:                mem3 = (Member) pm.getObjectById(m3Id, true);
313:                mem4 = (Member) pm.getObjectById(m4Id, true);
314:                mem5 = (Member) pm.getObjectById(m5Id, true);
315:                mem6 = (Member) pm.getObjectById(m6Id, true);
316:                mem7 = (Member) pm.getObjectById(m7Id, true);
317:                mem8 = (Member) pm.getObjectById(m8Id, true);
318:                mem9 = (Member) pm.getObjectById(m9Id, true);
319:                mem10 = (Member) pm.getObjectById(m10Id, true);
320:                grp = (Group) pm.getObjectById(gId, true);
321:                Assert.assertNotNull("null instance for the member 1", mem1);
322:                Assert
323:                        .assertEquals("Bad member 1 name", m1Name, mem1
324:                                .getName());
325:                Assert.assertNotNull("null instance for the member 2", mem2);
326:                Assert
327:                        .assertEquals("Bad member 2 name", m2Name, mem2
328:                                .getName());
329:                Assert.assertNotNull("null instance for the member 3", mem3);
330:                Assert
331:                        .assertEquals("Bad member 3 name", m3Name, mem3
332:                                .getName());
333:                Assert.assertNotNull("null instance for the member 4", mem4);
334:                Assert
335:                        .assertEquals("Bad member 4 name", m4Name, mem4
336:                                .getName());
337:                Assert.assertNotNull("null instance for the member 5", mem5);
338:                Assert
339:                        .assertEquals("Bad member 5 name", m5Name, mem5
340:                                .getName());
341:                Assert.assertNotNull("null instance for the member 6", mem6);
342:                Assert
343:                        .assertEquals("Bad member 6 name", m6Name, mem6
344:                                .getName());
345:                Assert.assertNotNull("null instance for the member 7", mem7);
346:                Assert
347:                        .assertEquals("Bad member 7 name", m7Name, mem7
348:                                .getName());
349:                Assert.assertNotNull("null instance for the member 8", mem8);
350:                Assert
351:                        .assertEquals("Bad member 8 name", m8Name, mem8
352:                                .getName());
353:                Assert.assertNotNull("null instance for the member 9", mem9);
354:                Assert
355:                        .assertEquals("Bad member 9 name", m9Name, mem9
356:                                .getName());
357:                Assert.assertNotNull("null instance for the member 10", mem10);
358:                Assert.assertEquals("Bad member 10 name", m10Name, mem10
359:                        .getName());
360:                Assert.assertNotNull("null instance returned for group", grp);
361:                Assert.assertEquals("Bad group name", gName, grp.getName());
362:
363:                /* Delete the group :
364:                 * this should delete its members too.
365:                 */
366:                pm.currentTransaction().begin();
367:                pm.deletePersistent(grp);
368:                pm.currentTransaction().commit();
369:                pm.close();
370:
371:                // Check that the members have been deleted too
372:                pm = pmf.getPersistenceManager();
373:                try {
374:                    mem1 = (Member) pm.getObjectById(m1Id, true);
375:
376:                    // Delete all members
377:                    pm.currentTransaction().begin();
378:                    pm.deletePersistent(mem1);
379:                    pm.deletePersistent(mem2);
380:                    pm.deletePersistent(mem3);
381:                    pm.deletePersistent(mem4);
382:                    pm.deletePersistent(mem5);
383:                    pm.deletePersistent(mem6);
384:                    pm.deletePersistent(mem7);
385:                    pm.deletePersistent(mem8);
386:                    pm.deletePersistent(mem9);
387:                    pm.deletePersistent(mem10);
388:                    pm.currentTransaction().commit();
389:                    Assert
390:                            .fail("Should have thrown a JDOUserException : member 1 has not been deleted");
391:                } catch (JDOUserException jdoEx) {
392:                    // The test has passed
393:                }
394:
395:                // Check that the members have been deleted too
396:                try {
397:                    mem2 = (Member) pm.getObjectById(m2Id, true);
398:
399:                    // Delete all members
400:                    pm.currentTransaction().begin();
401:                    pm.deletePersistent(mem2);
402:                    pm.deletePersistent(mem3);
403:                    pm.deletePersistent(mem4);
404:                    pm.deletePersistent(mem5);
405:                    pm.deletePersistent(mem6);
406:                    pm.deletePersistent(mem7);
407:                    pm.deletePersistent(mem8);
408:                    pm.deletePersistent(mem9);
409:                    pm.deletePersistent(mem10);
410:                    pm.currentTransaction().commit();
411:                    Assert
412:                            .fail("Should have thrown a JDOUserException : member 2 has not been deleted");
413:                } catch (JDOUserException jdoEx) {
414:                    // The test has passed
415:                }
416:
417:                // Check that the members have been deleted too
418:                try {
419:                    mem3 = (Member) pm.getObjectById(m3Id, true);
420:
421:                    // Delete all members
422:                    pm.currentTransaction().begin();
423:                    pm.deletePersistent(mem3);
424:                    pm.deletePersistent(mem4);
425:                    pm.deletePersistent(mem5);
426:                    pm.deletePersistent(mem6);
427:                    pm.deletePersistent(mem7);
428:                    pm.deletePersistent(mem8);
429:                    pm.deletePersistent(mem9);
430:                    pm.deletePersistent(mem10);
431:                    pm.currentTransaction().commit();
432:                    Assert
433:                            .fail("Should have thrown a JDOUserException : member 3 has not been deleted");
434:                } catch (JDOUserException jdoEx) {
435:                    // The test has passed
436:                }
437:
438:                // Check that the members have been deleted too
439:                try {
440:                    mem4 = (Member) pm.getObjectById(m4Id, true);
441:
442:                    // Delete all members
443:                    pm.currentTransaction().begin();
444:                    pm.deletePersistent(mem4);
445:                    pm.deletePersistent(mem5);
446:                    pm.deletePersistent(mem6);
447:                    pm.deletePersistent(mem7);
448:                    pm.deletePersistent(mem8);
449:                    pm.deletePersistent(mem9);
450:                    pm.deletePersistent(mem10);
451:                    pm.currentTransaction().commit();
452:                    Assert
453:                            .fail("Should have thrown a JDOUserException : member 4 has not been deleted");
454:                } catch (JDOUserException jdoEx) {
455:                    // The test has passed
456:                }
457:
458:                // Check that the members have been deleted too
459:                try {
460:                    mem5 = (Member) pm.getObjectById(m5Id, true);
461:
462:                    // Delete all members
463:                    pm.currentTransaction().begin();
464:                    pm.deletePersistent(mem5);
465:                    pm.deletePersistent(mem6);
466:                    pm.deletePersistent(mem7);
467:                    pm.deletePersistent(mem8);
468:                    pm.deletePersistent(mem9);
469:                    pm.deletePersistent(mem10);
470:                    pm.currentTransaction().commit();
471:                    Assert
472:                            .fail("Should have thrown a JDOUserException : member 5 has not been deleted");
473:                } catch (JDOUserException jdoEx) {
474:                    // The test has passed
475:                }
476:
477:                // Check that the members have been deleted too
478:                try {
479:                    mem6 = (Member) pm.getObjectById(m6Id, true);
480:
481:                    // Delete all members
482:                    pm.currentTransaction().begin();
483:                    pm.deletePersistent(mem6);
484:                    pm.deletePersistent(mem7);
485:                    pm.deletePersistent(mem8);
486:                    pm.deletePersistent(mem9);
487:                    pm.deletePersistent(mem10);
488:                    pm.currentTransaction().commit();
489:                    Assert
490:                            .fail("Should have thrown a JDOUserException : member 6 has not been deleted");
491:                } catch (JDOUserException jdoEx) {
492:                    // The test has passed
493:                }
494:
495:                // Check that the members have been deleted too
496:                try {
497:                    mem7 = (Member) pm.getObjectById(m7Id, true);
498:
499:                    // Delete all members
500:                    pm.currentTransaction().begin();
501:                    pm.deletePersistent(mem7);
502:                    pm.deletePersistent(mem8);
503:                    pm.deletePersistent(mem9);
504:                    pm.deletePersistent(mem10);
505:                    pm.currentTransaction().commit();
506:                    Assert
507:                            .fail("Should have thrown a JDOUserException : member 7 has not been deleted");
508:                } catch (JDOUserException jdoEx) {
509:                    // The test has passed
510:                }
511:
512:                // Check that the members have been deleted too
513:                try {
514:                    mem8 = (Member) pm.getObjectById(m8Id, true);
515:
516:                    // Delete all members
517:                    pm.currentTransaction().begin();
518:                    pm.deletePersistent(mem8);
519:                    pm.deletePersistent(mem9);
520:                    pm.deletePersistent(mem10);
521:                    pm.currentTransaction().commit();
522:                    Assert
523:                            .fail("Should have thrown a JDOUserException : member 8 has not been deleted");
524:                } catch (JDOUserException jdoEx) {
525:                    // The test has passed
526:                }
527:
528:                // Check that the members have been deleted too
529:                try {
530:                    mem9 = (Member) pm.getObjectById(m9Id, true);
531:
532:                    // Delete all members
533:                    pm.currentTransaction().begin();
534:                    pm.deletePersistent(mem9);
535:                    pm.deletePersistent(mem10);
536:                    pm.currentTransaction().commit();
537:                    Assert
538:                            .fail("Should have thrown a JDOUserException : member 9 has not been deleted");
539:                } catch (JDOUserException jdoEx) {
540:                    // The test has passed
541:                }
542:
543:                // Check that the members have been deleted too
544:                try {
545:                    mem10 = (Member) pm.getObjectById(m10Id, true);
546:
547:                    // Delete all members
548:                    pm.currentTransaction().begin();
549:                    pm.deletePersistent(mem10);
550:                    pm.currentTransaction().commit();
551:                    Assert
552:                            .fail("Should have thrown a JDOUserException : member 10 has not been deleted");
553:                } catch (JDOUserException jdoEx) {
554:                    // The test has passed
555:                    Assert.assertTrue(true);
556:                }
557:
558:                pm.close();
559:            }
560:
561:            /**
562:             * This method is responsible for the test of the cascade delete of a simple reference: a map. A group with 5 meetings.
563:             */
564:            public void testCascadeDeleteMap() {
565:                PersistenceManager pm = pmf.getPersistenceManager();
566:
567:                // A group
568:                String gName = "SpeedoCascade";
569:                Group grp = new Group(gName);
570:
571:                // Five members
572:                Meeting m1 = new Meeting("Meeting1", "Topic1");
573:                Meeting m2 = new Meeting("Meeting2", "Topic2");
574:                Meeting m3 = new Meeting("Meeting3", "Topic3");
575:                Meeting m4 = new Meeting("Meeting4", "Topic4");
576:                Meeting m5 = new Meeting("Meeting5", "Topic5");
577:
578:                // Add four meetings to the group 
579:                grp.addMeeting(m1);
580:                grp.addMeeting(m2);
581:                grp.addMeeting(m3);
582:                grp.addMeeting(m4);
583:
584:                //make the group persistent
585:                pm.makePersistent(grp);
586:                pm.makePersistent(m5);
587:                Object m1Id = pm.getObjectId(m1);
588:                Object m2Id = pm.getObjectId(m2);
589:                Object m3Id = pm.getObjectId(m3);
590:                Object m4Id = pm.getObjectId(m4);
591:                Object m5Id = pm.getObjectId(m5);
592:                Object gId = pm.getObjectId(grp);
593:                pm.close();
594:
595:                m1 = null;
596:                m2 = null;
597:                m3 = null;
598:                m4 = null;
599:                m5 = null;
600:                grp = null;
601:
602:                pm = pmf.getPersistenceManager();
603:
604:                // Check the creation of the meetings
605:                m1 = (Meeting) pm.getObjectById(m1Id, true);
606:                m2 = (Meeting) pm.getObjectById(m2Id, true);
607:                m3 = (Meeting) pm.getObjectById(m3Id, true);
608:                m4 = (Meeting) pm.getObjectById(m4Id, true);
609:                m5 = (Meeting) pm.getObjectById(m5Id, true);
610:                grp = (Group) pm.getObjectById(gId, true);
611:
612:                Assert.assertNotNull("null instance for the meeting 1", m1);
613:                Assert.assertNotNull("null instance for the meeting 2", m2);
614:                Assert.assertNotNull("null instance for the meeting 3", m3);
615:                Assert.assertNotNull("null instance for the meeting 4", m4);
616:                Assert.assertNotNull("null instance for the meeting 5", m5);
617:                Assert.assertNotNull("null instance returned for group", grp);
618:                Assert.assertEquals("Bad group name", gName, grp.getName());
619:
620:                /* Delete the group :
621:                 * this should delete its meetings too.
622:                 */
623:                pm.currentTransaction().begin();
624:                pm.deletePersistent(grp);
625:                pm.currentTransaction().commit();
626:                pm.close();
627:
628:                // Check that the meetings have been deleted too
629:                //excepting the fifth one, that was not part of the group
630:                pm = pmf.getPersistenceManager();
631:                try {
632:                    m1 = (Meeting) pm.getObjectById(m1Id, true);
633:
634:                    // Delete all meetings => throw an exception
635:                    pm.currentTransaction().begin();
636:                    pm.deletePersistent(m1);
637:                    pm.deletePersistent(m2);
638:                    pm.deletePersistent(m3);
639:                    pm.deletePersistent(m4);
640:                    pm.deletePersistent(m5);
641:                    pm.currentTransaction().commit();
642:                    Assert
643:                            .fail("Should have thrown a JDOUserException : member 1 has not been deleted");
644:                } catch (JDOUserException jdoEx) {
645:                    // The test has passed
646:                }
647:
648:                try {
649:                    m2 = (Meeting) pm.getObjectById(m2Id, true);
650:
651:                    // Delete all meetings => throw an exception
652:                    pm.currentTransaction().begin();
653:                    pm.deletePersistent(m2);
654:                    pm.deletePersistent(m3);
655:                    pm.deletePersistent(m4);
656:                    pm.deletePersistent(m5);
657:                    pm.currentTransaction().commit();
658:                    Assert
659:                            .fail("Should have thrown a JDOUserException : member 2 has not been deleted");
660:                } catch (JDOUserException jdoEx) {
661:                    // The test has passed
662:                }
663:
664:                try {
665:                    m3 = (Meeting) pm.getObjectById(m3Id, true);
666:
667:                    // Delete all meetings => throw an exception
668:                    pm.currentTransaction().begin();
669:                    pm.deletePersistent(m3);
670:                    pm.deletePersistent(m4);
671:                    pm.deletePersistent(m5);
672:                    pm.currentTransaction().commit();
673:                    Assert
674:                            .fail("Should have thrown a JDOUserException : member 3 has not been deleted");
675:                } catch (JDOUserException jdoEx) {
676:                    // The test has passed
677:                }
678:
679:                try {
680:                    m4 = (Meeting) pm.getObjectById(m4Id, true);
681:
682:                    // Delete all meetings => throw an exception
683:                    pm.currentTransaction().begin();
684:                    pm.deletePersistent(m4);
685:                    pm.deletePersistent(m5);
686:                    pm.currentTransaction().commit();
687:                    Assert
688:                            .fail("Should have thrown a JDOUserException : member 4 has not been deleted");
689:                } catch (JDOUserException jdoEx) {
690:                    // The test has passed
691:                }
692:
693:                try {
694:                    m5 = (Meeting) pm.getObjectById(m5Id, true);
695:                    Assert.assertNotNull("null instance for the meeting 5", m5);
696:                    // Delete all meetings => throw an exception
697:                    pm.currentTransaction().begin();
698:                    pm.deletePersistent(m5);
699:                    pm.currentTransaction().commit();
700:
701:                } catch (JDOUserException jdoEx) {
702:                    Assert
703:                            .fail("Deletion of meeting 5 should not be a problem.");
704:                }
705:
706:                pm.close();
707:            }
708:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.