Source Code Cross Referenced for ListContainerTests.java in  » Database-ORM » beankeeper » hu » netmind » persistence » 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 » beankeeper » hu.netmind.persistence 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright (C) 2007 NetMind Consulting Bt.
0003:         *
0004:         * This library is free software; you can redistribute it and/or
0005:         * modify it under the terms of the GNU Lesser General Public
0006:         * License as published by the Free Software Foundation; either
0007:         * version 3 of the License, or (at your option) any later version.
0008:         *
0009:         * This library is distributed in the hope that it will be useful,
0010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012:         * Lesser General Public License for more details.
0013:         *
0014:         * You should have received a copy of the GNU Lesser General Public
0015:         * License along with this library; if not, write to the Free Software
0016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
0017:         */package hu.netmind.persistence;
0018:
0019:        import java.util.*;
0020:        import org.apache.log4j.Logger;
0021:
0022:        /**
0023:         * Test the container framework.
0024:         * @author Brautigam Robert
0025:         * @version Revision: $Revision$
0026:         */
0027:        public class ListContainerTests extends AbstractPersistenceTest {
0028:            private static Logger logger = Logger
0029:                    .getLogger(ListContainerTests.class);
0030:
0031:            public ListContainerTests(String name) throws Exception {
0032:                super (name);
0033:            }
0034:
0035:            public void testListInitializeWithNonexisting() throws Exception {
0036:                // Drop table
0037:                dropTables("listholder");
0038:                // Insert mixed stuff
0039:                ListHolder holder = new ListHolder();
0040:                holder.setList(new Vector());
0041:                holder.getList().add(new Referrer(1));
0042:                holder.getList().add(new Referrer(2));
0043:                holder.getList().add(new Book("Refer collection", "1"));
0044:                store.save(holder);
0045:                // Check
0046:                ListHolder dbHolder = (ListHolder) store
0047:                        .findSingle("find listholder");
0048:                assertEquals(3, dbHolder.getList().size());
0049:            }
0050:
0051:            public void testListInitializeWithExisting() throws Exception {
0052:                // Drop table
0053:                dropTables("listholder");
0054:                // Insert mixed stuff
0055:                Referrer ref1 = new Referrer(1);
0056:                store.save(ref1);
0057:                Referrer ref2 = new Referrer(2);
0058:                store.save(ref2);
0059:                Book book1 = new Book("Refer collection", "1");
0060:                store.save(book1);
0061:                ListHolder holder = new ListHolder();
0062:                holder.setList(new Vector());
0063:                holder.getList().add(ref1);
0064:                holder.getList().add(ref2);
0065:                holder.getList().add(book1);
0066:                store.save(holder);
0067:                // Check
0068:                ListHolder dbHolder = (ListHolder) store
0069:                        .findSingle("find listholder");
0070:                assertEquals(3, dbHolder.getList().size());
0071:            }
0072:
0073:            public void testListFullToNullAndBack() throws Exception {
0074:                // Drop table
0075:                dropTables("listholder");
0076:                // Insert mixed stuff
0077:                ListHolder holder = new ListHolder();
0078:                holder.setList(new Vector());
0079:                holder.getList().add(new Referrer(1));
0080:                holder.getList().add(new Referrer(2));
0081:                holder.getList().add(new Book("Refer collection", "1"));
0082:                store.save(holder);
0083:                // Check
0084:                ListHolder dbHolder = (ListHolder) store
0085:                        .findSingle("find listholder");
0086:                assertEquals(3, dbHolder.getList().size());
0087:                // Set to null
0088:                dbHolder.setList(null);
0089:                store.save(dbHolder);
0090:                // Check
0091:                dbHolder = (ListHolder) store.findSingle("find listholder");
0092:                assertNull(dbHolder.getList());
0093:                // Set back
0094:                dbHolder.setList(new Vector());
0095:                dbHolder.getList().add(new Referrer(1));
0096:                dbHolder.getList().add(new Referrer(2));
0097:                store.save(dbHolder);
0098:                // Check
0099:                dbHolder = (ListHolder) store.findSingle("find listholder");
0100:                assertEquals(2, dbHolder.getList().size());
0101:            }
0102:
0103:            public void testListEmptyAddOnceNonexistingToCurrent()
0104:                    throws Exception {
0105:                // Drop table
0106:                dropTables("listholder");
0107:                // Add empty list
0108:                ListHolder holder = new ListHolder();
0109:                holder.setList(new Vector());
0110:                store.save(holder);
0111:                // Get
0112:                ListHolder dbHolder = (ListHolder) store
0113:                        .findSingle("find listholder");
0114:                dbHolder.getList().add(new Book("Second chance", "2"));
0115:                store.save(dbHolder);
0116:                // Check
0117:                dbHolder = (ListHolder) store.findSingle("find listholder");
0118:                assertEquals(1, dbHolder.getList().size());
0119:            }
0120:
0121:            public void testListNonemptyAddOnceNonexistingToCurrent()
0122:                    throws Exception {
0123:                // Drop table
0124:                dropTables("listholder");
0125:                // Add empty list
0126:                ListHolder holder = new ListHolder();
0127:                holder.setList(new Vector());
0128:                holder.getList().add(new Referrer(1));
0129:                holder.getList().add(new Referrer(2));
0130:                holder.getList().add(new Book("Refer collection", "1"));
0131:                store.save(holder);
0132:                // Get
0133:                ListHolder dbHolder = (ListHolder) store
0134:                        .findSingle("find listholder");
0135:                assertEquals(3, dbHolder.getList().size());
0136:                dbHolder.getList().add(new Book("Second chance", "2"));
0137:                store.save(dbHolder);
0138:                // Check
0139:                dbHolder = (ListHolder) store.findSingle("find listholder");
0140:                assertEquals(4, dbHolder.getList().size());
0141:            }
0142:
0143:            public void testListEmptyAddOnceExistingToCurrent()
0144:                    throws Exception {
0145:                // Drop table
0146:                dropTables("listholder");
0147:                // Add empty list
0148:                ListHolder holder = new ListHolder();
0149:                holder.setList(new Vector());
0150:                store.save(holder);
0151:                // Get
0152:                Book book2 = new Book("Second chance", "2");
0153:                store.save(book2);
0154:                ListHolder dbHolder = (ListHolder) store
0155:                        .findSingle("find listholder");
0156:                dbHolder.getList().add(book2);
0157:                store.save(dbHolder);
0158:                // Check
0159:                dbHolder = (ListHolder) store.findSingle("find listholder");
0160:                assertEquals(1, dbHolder.getList().size());
0161:            }
0162:
0163:            public void testListNonemptyAddOnceExistingToCurrent()
0164:                    throws Exception {
0165:                // Drop table
0166:                dropTables("listholder");
0167:                // Add empty list
0168:                ListHolder holder = new ListHolder();
0169:                holder.setList(new Vector());
0170:                holder.getList().add(new Referrer(1));
0171:                holder.getList().add(new Referrer(2));
0172:                holder.getList().add(new Book("Refer collection", "1"));
0173:                store.save(holder);
0174:                // Get
0175:                Book book2 = new Book("Second chance", "2");
0176:                store.save(book2);
0177:                ListHolder dbHolder = (ListHolder) store
0178:                        .findSingle("find listholder");
0179:                dbHolder.getList().add(book2);
0180:                store.save(dbHolder);
0181:                // Check
0182:                dbHolder = (ListHolder) store.findSingle("find listholder");
0183:                assertEquals(4, dbHolder.getList().size());
0184:            }
0185:
0186:            public void testListContainsAddOnceExistingToCurrent()
0187:                    throws Exception {
0188:                // Drop table
0189:                dropTables("listholder");
0190:                // Add empty list
0191:                ListHolder holder = new ListHolder();
0192:                holder.setList(new Vector());
0193:                holder.getList().add(new Referrer(1));
0194:                holder.getList().add(new Referrer(2));
0195:                Book book2 = new Book("Second chance", "2");
0196:                holder.getList().add(book2);
0197:                store.save(holder);
0198:                // Get
0199:                ListHolder dbHolder = (ListHolder) store
0200:                        .findSingle("find listholder");
0201:                assertEquals(3, dbHolder.getList().size());
0202:                dbHolder.getList().add(book2);
0203:                store.save(dbHolder);
0204:                // Check
0205:                dbHolder = (ListHolder) store.findSingle("find listholder");
0206:                assertEquals(4, dbHolder.getList().size());
0207:            }
0208:
0209:            public void testListEmptyAddTwiceNonexistingToCurrent()
0210:                    throws Exception {
0211:                // Drop table
0212:                dropTables("listholder");
0213:                // Add empty list
0214:                ListHolder holder = new ListHolder();
0215:                holder.setList(new Vector());
0216:                store.save(holder);
0217:                // Get
0218:                ListHolder dbHolder = (ListHolder) store
0219:                        .findSingle("find listholder");
0220:                Book book = new Book("Second chance", "2");
0221:                dbHolder.getList().add(book);
0222:                dbHolder.getList().add(book);
0223:                store.save(dbHolder);
0224:                // Check
0225:                dbHolder = (ListHolder) store.findSingle("find listholder");
0226:                assertEquals(2, dbHolder.getList().size());
0227:            }
0228:
0229:            public void testListNonemptyAddTwiceNonexistingToCurrent()
0230:                    throws Exception {
0231:                // Drop table
0232:                dropTables("listholder");
0233:                // Add empty list
0234:                ListHolder holder = new ListHolder();
0235:                holder.setList(new Vector());
0236:                holder.getList().add(new Referrer(1));
0237:                holder.getList().add(new Referrer(2));
0238:                holder.getList().add(new Book("Refer collection", "1"));
0239:                store.save(holder);
0240:                // Get
0241:                ListHolder dbHolder = (ListHolder) store
0242:                        .findSingle("find listholder");
0243:                Book book = new Book("Second chance", "2");
0244:                dbHolder.getList().add(book);
0245:                dbHolder.getList().add(book);
0246:                store.save(dbHolder);
0247:                // Check
0248:                dbHolder = (ListHolder) store.findSingle("find listholder");
0249:                assertEquals(5, dbHolder.getList().size());
0250:            }
0251:
0252:            public void testListEmptyAddTwiceExistingToCurrent()
0253:                    throws Exception {
0254:                // Drop table
0255:                dropTables("listholder");
0256:                // Add empty list
0257:                ListHolder holder = new ListHolder();
0258:                holder.setList(new Vector());
0259:                store.save(holder);
0260:                // Get
0261:                ListHolder dbHolder = (ListHolder) store
0262:                        .findSingle("find listholder");
0263:                Book book = new Book("Second chance", "2");
0264:                store.save(book);
0265:                dbHolder.getList().add(book);
0266:                dbHolder.getList().add(book);
0267:                store.save(dbHolder);
0268:                // Check
0269:                dbHolder = (ListHolder) store.findSingle("find listholder");
0270:                assertEquals(2, dbHolder.getList().size());
0271:            }
0272:
0273:            public void testListNonemptyAddTwiceExistingToCurrent()
0274:                    throws Exception {
0275:                // Drop table
0276:                dropTables("listholder");
0277:                // Add empty list
0278:                ListHolder holder = new ListHolder();
0279:                holder.setList(new Vector());
0280:                holder.getList().add(new Referrer(1));
0281:                holder.getList().add(new Referrer(2));
0282:                holder.getList().add(new Book("Refer collection", "1"));
0283:                store.save(holder);
0284:                // Get
0285:                ListHolder dbHolder = (ListHolder) store
0286:                        .findSingle("find listholder");
0287:                Book book = new Book("Second chance", "2");
0288:                store.save(book);
0289:                dbHolder.getList().add(book);
0290:                dbHolder.getList().add(book);
0291:                store.save(dbHolder);
0292:                // Check
0293:                dbHolder = (ListHolder) store.findSingle("find listholder");
0294:                assertEquals(5, dbHolder.getList().size());
0295:            }
0296:
0297:            public void testListContainsAddTwiceExistingToCurrent()
0298:                    throws Exception {
0299:                // Drop table
0300:                dropTables("listholder");
0301:                // Add empty list
0302:                ListHolder holder = new ListHolder();
0303:                Book book = new Book("Second chance", "2");
0304:                holder.setList(new Vector());
0305:                holder.getList().add(new Referrer(1));
0306:                holder.getList().add(new Referrer(2));
0307:                holder.getList().add(book);
0308:                holder.getList().add(new Book("Refer collection", "1"));
0309:                store.save(holder);
0310:                // Get
0311:                ListHolder dbHolder = (ListHolder) store
0312:                        .findSingle("find listholder");
0313:                store.save(book);
0314:                dbHolder.getList().add(book);
0315:                dbHolder.getList().add(book);
0316:                store.save(dbHolder);
0317:                // Check
0318:                dbHolder = (ListHolder) store.findSingle("find listholder");
0319:                assertEquals(6, dbHolder.getList().size());
0320:            }
0321:
0322:            public void testListEmptyAddOnceNonexistingToObsolete()
0323:                    throws Exception {
0324:                // Drop table
0325:                dropTables("listholder");
0326:                // Add empty list
0327:                ListHolder holder = new ListHolder();
0328:                holder.setList(new Vector());
0329:                store.save(holder);
0330:                // Get
0331:                ListHolder dbHolder = (ListHolder) store
0332:                        .findSingle("find listholder");
0333:                dbHolder.getList().add(new Book("Second chance", "2"));
0334:                // Make previous holder obsolate
0335:                ListHolder currentHolder = (ListHolder) store
0336:                        .findSingle("find listholder");
0337:                Book modBook = new Book("Modification Book", "2");
0338:                currentHolder.getList().add(modBook);
0339:                store.save(currentHolder);
0340:                currentHolder.getList().remove(modBook);
0341:                store.save(currentHolder);
0342:                // Operation
0343:                store.save(dbHolder);
0344:                // Check
0345:                dbHolder = (ListHolder) store.findSingle("find listholder");
0346:                assertEquals(1, dbHolder.getList().size());
0347:            }
0348:
0349:            public void testListNonemptyAddOnceNonexistingToObsolete()
0350:                    throws Exception {
0351:                // Drop table
0352:                dropTables("listholder");
0353:                // Add empty list
0354:                ListHolder holder = new ListHolder();
0355:                holder.setList(new Vector());
0356:                holder.getList().add(new Referrer(1));
0357:                holder.getList().add(new Referrer(2));
0358:                holder.getList().add(new Book("Refer collection", "1"));
0359:                store.save(holder);
0360:                // Get
0361:                ListHolder dbHolder = (ListHolder) store
0362:                        .findSingle("find listholder");
0363:                dbHolder.getList().add(new Book("Second chance", "2"));
0364:                // Make previous holder obsolate
0365:                ListHolder currentHolder = (ListHolder) store
0366:                        .findSingle("find listholder");
0367:                Book modBook = new Book("Modification Book", "2");
0368:                currentHolder.getList().add(modBook);
0369:                store.save(currentHolder);
0370:                currentHolder.getList().remove(modBook);
0371:                store.save(currentHolder);
0372:                // Check
0373:                store.save(dbHolder);
0374:                ListHolder result = (ListHolder) store
0375:                        .findSingle("find listholder");
0376:                assertEquals(4, result.getList().size());
0377:            }
0378:
0379:            public void testListEmptyAddOnceExistingToObsolete()
0380:                    throws Exception {
0381:                // Drop table
0382:                dropTables("listholder");
0383:                // Add empty list
0384:                ListHolder holder = new ListHolder();
0385:                holder.setList(new Vector());
0386:                store.save(holder);
0387:                // Get
0388:                Book book2 = new Book("Second chance", "2");
0389:                store.save(book2);
0390:                ListHolder dbHolder = (ListHolder) store
0391:                        .findSingle("find listholder");
0392:                dbHolder.getList().add(book2);
0393:                // Make previous holder obsolate
0394:                ListHolder currentHolder = (ListHolder) store
0395:                        .findSingle("find listholder");
0396:                Book modBook = new Book("Modification Book", "2");
0397:                currentHolder.getList().add(modBook);
0398:                store.save(currentHolder);
0399:                currentHolder.getList().remove(modBook);
0400:                store.save(currentHolder);
0401:                // Operation
0402:                store.save(dbHolder);
0403:                // Check
0404:                dbHolder = (ListHolder) store.findSingle("find listholder");
0405:                assertEquals(1, dbHolder.getList().size());
0406:            }
0407:
0408:            public void testListNonemptyAddOnceExistingToObsolete()
0409:                    throws Exception {
0410:                // Drop table
0411:                dropTables("listholder");
0412:                // Add empty list
0413:                ListHolder holder = new ListHolder();
0414:                holder.setList(new Vector());
0415:                holder.getList().add(new Referrer(1));
0416:                holder.getList().add(new Referrer(2));
0417:                holder.getList().add(new Book("Refer collection", "1"));
0418:                store.save(holder);
0419:                // Get
0420:                Book book2 = new Book("Second chance", "2");
0421:                store.save(book2);
0422:                ListHolder dbHolder = (ListHolder) store
0423:                        .findSingle("find listholder");
0424:                dbHolder.getList().add(book2);
0425:                // Make previous holder obsolate
0426:                ListHolder currentHolder = (ListHolder) store
0427:                        .findSingle("find listholder");
0428:                Book modBook = new Book("Modification Book", "2");
0429:                currentHolder.getList().add(modBook);
0430:                store.save(currentHolder);
0431:                currentHolder.getList().remove(modBook);
0432:                store.save(currentHolder);
0433:                // Check
0434:                store.save(dbHolder);
0435:                ListHolder result = (ListHolder) store
0436:                        .findSingle("find listholder");
0437:                assertEquals(4, result.getList().size());
0438:            }
0439:
0440:            public void testListContainsAddOnceExistingToObsolete()
0441:                    throws Exception {
0442:                // Drop table
0443:                dropTables("listholder");
0444:                // Add empty list
0445:                ListHolder holder = new ListHolder();
0446:                holder.setList(new Vector());
0447:                holder.getList().add(new Referrer(1));
0448:                holder.getList().add(new Referrer(2));
0449:                Book book2 = new Book("Second chance", "2");
0450:                holder.getList().add(book2);
0451:                store.save(holder);
0452:                // Get
0453:                ListHolder dbHolder = (ListHolder) store
0454:                        .findSingle("find listholder");
0455:                assertEquals(3, dbHolder.getList().size());
0456:                dbHolder.getList().add(book2);
0457:                // Make previous holder obsolate
0458:                ListHolder currentHolder = (ListHolder) store
0459:                        .findSingle("find listholder");
0460:                Book modBook = new Book("Modification Book", "2");
0461:                currentHolder.getList().add(modBook);
0462:                store.save(currentHolder);
0463:                currentHolder.getList().remove(modBook);
0464:                store.save(currentHolder);
0465:                // Check
0466:                store.save(dbHolder);
0467:                ListHolder result = (ListHolder) store
0468:                        .findSingle("find listholder");
0469:                assertEquals(4, result.getList().size());
0470:            }
0471:
0472:            public void testListEmptyAddTwiceNonexistingToObsolete()
0473:                    throws Exception {
0474:                // Drop table
0475:                dropTables("listholder");
0476:                // Add empty list
0477:                ListHolder holder = new ListHolder();
0478:                holder.setList(new Vector());
0479:                store.save(holder);
0480:                // Get
0481:                ListHolder dbHolder = (ListHolder) store
0482:                        .findSingle("find listholder");
0483:                Book book = new Book("Second chance", "2");
0484:                dbHolder.getList().add(book);
0485:                dbHolder.getList().add(book);
0486:                // Make previous holder obsolate
0487:                ListHolder currentHolder = (ListHolder) store
0488:                        .findSingle("find listholder");
0489:                Book modBook = new Book("Modification Book", "2");
0490:                currentHolder.getList().add(modBook);
0491:                store.save(currentHolder);
0492:                currentHolder.getList().remove(modBook);
0493:                store.save(currentHolder);
0494:                // Operation
0495:                store.save(dbHolder);
0496:                // Check
0497:                dbHolder = (ListHolder) store.findSingle("find listholder");
0498:                assertEquals(2, dbHolder.getList().size());
0499:            }
0500:
0501:            public void testListNonemptyAddTwiceNonexistingToObsolete()
0502:                    throws Exception {
0503:                // Drop table
0504:                dropTables("listholder");
0505:                // Add empty list
0506:                ListHolder holder = new ListHolder();
0507:                holder.setList(new Vector());
0508:                holder.getList().add(new Referrer(1));
0509:                holder.getList().add(new Referrer(2));
0510:                holder.getList().add(new Book("Refer collection", "1"));
0511:                store.save(holder);
0512:                // Get
0513:                ListHolder dbHolder = (ListHolder) store
0514:                        .findSingle("find listholder");
0515:                Book book = new Book("Second chance", "2");
0516:                dbHolder.getList().add(book);
0517:                dbHolder.getList().add(book);
0518:                // Make previous holder obsolate
0519:                ListHolder currentHolder = (ListHolder) store
0520:                        .findSingle("find listholder");
0521:                Book modBook = new Book("Modification Book", "2");
0522:                currentHolder.getList().add(modBook);
0523:                store.save(currentHolder);
0524:                currentHolder.getList().remove(modBook);
0525:                store.save(currentHolder);
0526:                // Check
0527:                store.save(dbHolder);
0528:                ListHolder result = (ListHolder) store
0529:                        .findSingle("find listholder");
0530:                assertEquals(5, result.getList().size());
0531:            }
0532:
0533:            public void testListEmptyAddTwiceExistingToObsolete()
0534:                    throws Exception {
0535:                // Drop table
0536:                dropTables("listholder");
0537:                // Add empty list
0538:                ListHolder holder = new ListHolder();
0539:                holder.setList(new Vector());
0540:                store.save(holder);
0541:                // Get
0542:                ListHolder dbHolder = (ListHolder) store
0543:                        .findSingle("find listholder");
0544:                Book book = new Book("Second chance", "2");
0545:                store.save(book);
0546:                dbHolder.getList().add(book);
0547:                dbHolder.getList().add(book);
0548:                // Make previous holder obsolate
0549:                ListHolder currentHolder = (ListHolder) store
0550:                        .findSingle("find listholder");
0551:                Book modBook = new Book("Modification Book", "2");
0552:                currentHolder.getList().add(modBook);
0553:                store.save(currentHolder);
0554:                currentHolder.getList().remove(modBook);
0555:                store.save(currentHolder);
0556:                // Operation
0557:                store.save(dbHolder);
0558:                // Check
0559:                dbHolder = (ListHolder) store.findSingle("find listholder");
0560:                assertEquals(2, dbHolder.getList().size());
0561:            }
0562:
0563:            public void testListNonemptyAddTwiceExistingToObsolete()
0564:                    throws Exception {
0565:                // Drop table
0566:                dropTables("listholder");
0567:                // Add empty list
0568:                ListHolder holder = new ListHolder();
0569:                holder.setList(new Vector());
0570:                holder.getList().add(new Referrer(1));
0571:                holder.getList().add(new Referrer(2));
0572:                holder.getList().add(new Book("Refer collection", "1"));
0573:                store.save(holder);
0574:                // Get
0575:                ListHolder dbHolder = (ListHolder) store
0576:                        .findSingle("find listholder");
0577:                Book book = new Book("Second chance", "2");
0578:                store.save(book);
0579:                dbHolder.getList().add(book);
0580:                dbHolder.getList().add(book);
0581:                // Make previous holder obsolate
0582:                ListHolder currentHolder = (ListHolder) store
0583:                        .findSingle("find listholder");
0584:                Book modBook = new Book("Modification Book", "2");
0585:                currentHolder.getList().add(modBook);
0586:                store.save(currentHolder);
0587:                currentHolder.getList().remove(modBook);
0588:                store.save(currentHolder);
0589:                // Check
0590:                store.save(dbHolder);
0591:                ListHolder result = (ListHolder) store
0592:                        .findSingle("find listholder");
0593:                assertEquals(5, result.getList().size());
0594:            }
0595:
0596:            public void testListContainsAddTwiceExistingToObsolete()
0597:                    throws Exception {
0598:                // Drop table
0599:                dropTables("listholder");
0600:                // Add empty list
0601:                ListHolder holder = new ListHolder();
0602:                Book book = new Book("Second chance", "2");
0603:                holder.setList(new Vector());
0604:                holder.getList().add(new Referrer(1));
0605:                holder.getList().add(new Referrer(2));
0606:                holder.getList().add(book);
0607:                holder.getList().add(new Book("Refer collection", "1"));
0608:                store.save(holder);
0609:                // Get
0610:                ListHolder dbHolder = (ListHolder) store
0611:                        .findSingle("find listholder");
0612:                store.save(book);
0613:                dbHolder.getList().add(book);
0614:                dbHolder.getList().add(book);
0615:                // Make previous holder obsolate
0616:                ListHolder currentHolder = (ListHolder) store
0617:                        .findSingle("find listholder");
0618:                Book modBook = new Book("Modification Book", "2");
0619:                currentHolder.getList().add(modBook);
0620:                store.save(currentHolder);
0621:                currentHolder.getList().remove(modBook);
0622:                store.save(currentHolder);
0623:                // Check
0624:                store.save(dbHolder);
0625:                ListHolder result = (ListHolder) store
0626:                        .findSingle("find listholder");
0627:                assertEquals(6, result.getList().size());
0628:            }
0629:
0630:            public void testListEmptyAddOnceNonexistingToCustom()
0631:                    throws Exception {
0632:                // Drop table
0633:                dropTables("listholder");
0634:                // Add empty list
0635:                ListHolder holder = new ListHolder();
0636:                holder.setList(new Vector());
0637:                store.save(holder);
0638:                // Get
0639:                ListHolder dbHolder = (ListHolder) store
0640:                        .findSingle("find listholder");
0641:                dbHolder.setList(new Vector());
0642:                dbHolder.getList().add(new Book("Second chance", "2"));
0643:                store.save(dbHolder);
0644:                // Check
0645:                dbHolder = (ListHolder) store.findSingle("find listholder");
0646:                assertEquals(1, dbHolder.getList().size());
0647:            }
0648:
0649:            public void testListNonemptyAddOnceNonexistingToCustom()
0650:                    throws Exception {
0651:                // Drop table
0652:                dropTables("listholder");
0653:                // Add empty list
0654:                ListHolder holder = new ListHolder();
0655:                holder.setList(new Vector());
0656:                holder.getList().add(new Referrer(1));
0657:                holder.getList().add(new Referrer(2));
0658:                holder.getList().add(new Book("Refer collection", "1"));
0659:                store.save(holder);
0660:                // Get
0661:                ListHolder dbHolder = (ListHolder) store
0662:                        .findSingle("find listholder");
0663:                dbHolder.setList(new Vector());
0664:                dbHolder.getList().add(new Book("Second chance", "2"));
0665:                store.save(dbHolder);
0666:                // Check
0667:                dbHolder = (ListHolder) store.findSingle("find listholder");
0668:                assertEquals(1, dbHolder.getList().size());
0669:            }
0670:
0671:            public void testListEmptyAddOnceExistingToCustom() throws Exception {
0672:                // Drop table
0673:                dropTables("listholder");
0674:                // Add empty list
0675:                ListHolder holder = new ListHolder();
0676:                holder.setList(new Vector());
0677:                store.save(holder);
0678:                // Get
0679:                Book book2 = new Book("Second chance", "2");
0680:                store.save(book2);
0681:                ListHolder dbHolder = (ListHolder) store
0682:                        .findSingle("find listholder");
0683:                dbHolder.setList(new Vector());
0684:                dbHolder.getList().add(book2);
0685:                store.save(dbHolder);
0686:                // Check
0687:                dbHolder = (ListHolder) store.findSingle("find listholder");
0688:                assertEquals(1, dbHolder.getList().size());
0689:            }
0690:
0691:            public void testListNonemptyAddOnceExistingToCustom()
0692:                    throws Exception {
0693:                // Drop table
0694:                dropTables("listholder");
0695:                // Add empty list
0696:                ListHolder holder = new ListHolder();
0697:                holder.setList(new Vector());
0698:                holder.getList().add(new Referrer(1));
0699:                holder.getList().add(new Referrer(2));
0700:                holder.getList().add(new Book("Refer collection", "1"));
0701:                store.save(holder);
0702:                // Get
0703:                Book book2 = new Book("Second chance", "2");
0704:                store.save(book2);
0705:                ListHolder dbHolder = (ListHolder) store
0706:                        .findSingle("find listholder");
0707:                dbHolder.setList(new Vector());
0708:                dbHolder.getList().add(book2);
0709:                store.save(dbHolder);
0710:                // Check
0711:                dbHolder = (ListHolder) store.findSingle("find listholder");
0712:                assertEquals(1, dbHolder.getList().size());
0713:            }
0714:
0715:            public void testListContainsAddOnceExistingToCustom()
0716:                    throws Exception {
0717:                // Drop table
0718:                dropTables("listholder");
0719:                // Add empty list
0720:                ListHolder holder = new ListHolder();
0721:                holder.setList(new Vector());
0722:                holder.getList().add(new Referrer(1));
0723:                holder.getList().add(new Referrer(2));
0724:                Book book2 = new Book("Second chance", "2");
0725:                holder.getList().add(book2);
0726:                store.save(holder);
0727:                // Get
0728:                ListHolder dbHolder = (ListHolder) store
0729:                        .findSingle("find listholder");
0730:                assertEquals(3, dbHolder.getList().size());
0731:                dbHolder.setList(new Vector());
0732:                dbHolder.getList().add(book2);
0733:                store.save(dbHolder);
0734:                // Check
0735:                dbHolder = (ListHolder) store.findSingle("find listholder");
0736:                assertEquals(1, dbHolder.getList().size());
0737:            }
0738:
0739:            public void testListEmptyAddTwiceNonexistingToCustom()
0740:                    throws Exception {
0741:                // Drop table
0742:                dropTables("listholder");
0743:                // Add empty list
0744:                ListHolder holder = new ListHolder();
0745:                holder.setList(new Vector());
0746:                store.save(holder);
0747:                // Get
0748:                ListHolder dbHolder = (ListHolder) store
0749:                        .findSingle("find listholder");
0750:                Book book = new Book("Second chance", "2");
0751:                dbHolder.setList(new Vector());
0752:                dbHolder.getList().add(book);
0753:                dbHolder.getList().add(book);
0754:                store.save(dbHolder);
0755:                // Check
0756:                dbHolder = (ListHolder) store.findSingle("find listholder");
0757:                assertEquals(2, dbHolder.getList().size());
0758:            }
0759:
0760:            public void testListNonemptyAddTwiceNonexistingToCustom()
0761:                    throws Exception {
0762:                // Drop table
0763:                dropTables("listholder");
0764:                // Add empty list
0765:                ListHolder holder = new ListHolder();
0766:                holder.setList(new Vector());
0767:                holder.getList().add(new Referrer(1));
0768:                holder.getList().add(new Referrer(2));
0769:                holder.getList().add(new Book("Refer collection", "1"));
0770:                store.save(holder);
0771:                // Get
0772:                ListHolder dbHolder = (ListHolder) store
0773:                        .findSingle("find listholder");
0774:                Book book = new Book("Second chance", "2");
0775:                dbHolder.setList(new Vector());
0776:                dbHolder.getList().add(book);
0777:                dbHolder.getList().add(book);
0778:                store.save(dbHolder);
0779:                // Check
0780:                dbHolder = (ListHolder) store.findSingle("find listholder");
0781:                assertEquals(2, dbHolder.getList().size());
0782:            }
0783:
0784:            public void testListEmptyAddTwiceExistingToCustom()
0785:                    throws Exception {
0786:                // Drop table
0787:                dropTables("listholder");
0788:                // Add empty list
0789:                ListHolder holder = new ListHolder();
0790:                holder.setList(new Vector());
0791:                store.save(holder);
0792:                // Get
0793:                ListHolder dbHolder = (ListHolder) store
0794:                        .findSingle("find listholder");
0795:                Book book = new Book("Second chance", "2");
0796:                dbHolder.setList(new Vector());
0797:                store.save(book);
0798:                dbHolder.getList().add(book);
0799:                dbHolder.getList().add(book);
0800:                store.save(dbHolder);
0801:                // Check
0802:                dbHolder = (ListHolder) store.findSingle("find listholder");
0803:                assertEquals(2, dbHolder.getList().size());
0804:            }
0805:
0806:            public void testListNonemptyAddTwiceExistingToCustom()
0807:                    throws Exception {
0808:                // Drop table
0809:                dropTables("listholder");
0810:                // Add empty list
0811:                ListHolder holder = new ListHolder();
0812:                holder.setList(new Vector());
0813:                holder.getList().add(new Referrer(1));
0814:                holder.getList().add(new Referrer(2));
0815:                holder.getList().add(new Book("Refer collection", "1"));
0816:                store.save(holder);
0817:                // Get
0818:                ListHolder dbHolder = (ListHolder) store
0819:                        .findSingle("find listholder");
0820:                Book book = new Book("Second chance", "2");
0821:                store.save(book);
0822:                dbHolder.setList(new Vector());
0823:                dbHolder.getList().add(book);
0824:                dbHolder.getList().add(book);
0825:                store.save(dbHolder);
0826:                // Check
0827:                dbHolder = (ListHolder) store.findSingle("find listholder");
0828:                assertEquals(2, dbHolder.getList().size());
0829:            }
0830:
0831:            public void testListContainsAddTwiceExistingToCustom()
0832:                    throws Exception {
0833:                // Drop table
0834:                dropTables("listholder");
0835:                // Add empty list
0836:                ListHolder holder = new ListHolder();
0837:                Book book = new Book("Second chance", "2");
0838:                holder.setList(new Vector());
0839:                holder.getList().add(new Referrer(1));
0840:                holder.getList().add(new Referrer(2));
0841:                holder.getList().add(book);
0842:                holder.getList().add(new Book("Refer collection", "1"));
0843:                store.save(holder);
0844:                // Get
0845:                ListHolder dbHolder = (ListHolder) store
0846:                        .findSingle("find listholder");
0847:                dbHolder.setList(new Vector());
0848:                store.save(book);
0849:                dbHolder.getList().add(book);
0850:                dbHolder.getList().add(book);
0851:                store.save(dbHolder);
0852:                // Check
0853:                dbHolder = (ListHolder) store.findSingle("find listholder");
0854:                assertEquals(2, dbHolder.getList().size());
0855:            }
0856:
0857:            public void testListAssignForeignListNonexisting() throws Exception {
0858:                // Drop table
0859:                dropTables("listholder");
0860:                // Add empty list
0861:                ListHolder holder = new ListHolder();
0862:                Book book = new Book("Second chance", "2");
0863:                holder.setList(new Vector());
0864:                holder.getList().add(new Referrer(1));
0865:                holder.getList().add(new Referrer(2));
0866:                holder.getList().add(book);
0867:                holder.getList().add(new Book("Refer collection", "1"));
0868:                store.save(holder);
0869:                // Get
0870:                ListHolder dbHolder = (ListHolder) store
0871:                        .findSingle("find listholder");
0872:                // Now assign that list to other listholder
0873:                ListHolder otherHolder = new ListHolder();
0874:                otherHolder.setList(dbHolder.getList());
0875:                store.save(otherHolder);
0876:                // Get the result
0877:                ListHolder dbOtherHolder = (ListHolder) store
0878:                        .findSingle("find listholder");
0879:                assertEquals(4, dbOtherHolder.getList().size());
0880:            }
0881:
0882:            public void testListAssignForeignListExisting() throws Exception {
0883:                // Drop table
0884:                dropTables("listholder");
0885:                // Add empty list
0886:                ListHolder holder = new ListHolder();
0887:                Book book = new Book("Second chance", "2");
0888:                holder.setList(new Vector());
0889:                holder.getList().add(new Referrer(1));
0890:                holder.getList().add(new Referrer(2));
0891:                holder.getList().add(book);
0892:                holder.getList().add(new Book("Refer collection", "1"));
0893:                store.save(holder);
0894:                // Get
0895:                ListHolder dbHolder = (ListHolder) store
0896:                        .findSingle("find listholder");
0897:                // Now assign that list to other listholder
0898:                ListHolder otherHolder = new ListHolder();
0899:                otherHolder.setList(new Vector());
0900:                store.save(otherHolder);
0901:                otherHolder = (ListHolder) store.findSingle("find listholder");
0902:                otherHolder.setList(dbHolder.getList());
0903:                store.save(otherHolder);
0904:                // Get the result
0905:                ListHolder dbOtherHolder = (ListHolder) store
0906:                        .findSingle("find listholder");
0907:                assertEquals(4, dbOtherHolder.getList().size());
0908:            }
0909:
0910:            public void testListClearOnCurrent() throws Exception {
0911:                // Drop table
0912:                dropTables("listholder");
0913:                // Insert mixed stuff
0914:                ListHolder holder = new ListHolder();
0915:                holder.setList(new Vector());
0916:                holder.getList().add(new Referrer(1));
0917:                holder.getList().add(new Referrer(2));
0918:                holder.getList().add(new Book("Refer collection", "1"));
0919:                store.save(holder);
0920:                // Check and clear
0921:                ListHolder dbHolder = (ListHolder) store
0922:                        .findSingle("find listholder");
0923:                assertEquals(3, dbHolder.getList().size());
0924:                dbHolder.getList().clear();
0925:                store.save(dbHolder);
0926:                // Get
0927:                dbHolder = (ListHolder) store.findSingle("find listholder");
0928:                assertEquals(0, dbHolder.getList().size());
0929:            }
0930:
0931:            public void testListClearOnObsolete() throws Exception {
0932:                // Drop table
0933:                dropTables("listholder");
0934:                // Add empty list
0935:                ListHolder holder = new ListHolder();
0936:                holder.setList(new Vector());
0937:                holder.getList().add(new Referrer(1));
0938:                holder.getList().add(new Referrer(2));
0939:                store.save(holder);
0940:                // Get
0941:                ListHolder dbHolder = (ListHolder) store
0942:                        .findSingle("find listholder");
0943:                dbHolder.getList().clear();
0944:                // Make previous holder obsolate
0945:                ListHolder currentHolder = (ListHolder) store
0946:                        .findSingle("find listholder");
0947:                Book modBook = new Book("Modification Book", "2");
0948:                currentHolder.getList().add(modBook);
0949:                store.save(currentHolder);
0950:                currentHolder.getList().remove(modBook);
0951:                store.save(currentHolder);
0952:                // Check
0953:                store.save(dbHolder);
0954:                ListHolder result = (ListHolder) store
0955:                        .findSingle("find listholder");
0956:                assertEquals(0, result.getList().size());
0957:            }
0958:
0959:            public void testListContainsNonexistingEquals() throws Exception {
0960:                // Drop table
0961:                dropTables("listholder");
0962:                // Insert mixed stuff
0963:                ListHolder holder = new ListHolder();
0964:                holder.setList(new Vector());
0965:                holder.getList().add(new Referrer(1));
0966:                holder.getList().add(new Referrer(2));
0967:                holder.getList().add(new Book("Refer collection", "1"));
0968:                store.save(holder);
0969:                // Check
0970:                ListHolder dbHolder = (ListHolder) store
0971:                        .findSingle("find listholder");
0972:                assertEquals(3, dbHolder.getList().size());
0973:                assertFalse(dbHolder.getList().contains(
0974:                        new Book("Refer collection", "1")));
0975:            }
0976:
0977:            public void testListContainsExistingEquals() throws Exception {
0978:                // Drop table
0979:                dropTables("listholder");
0980:                // Insert mixed stuff
0981:                ListHolder holder = new ListHolder();
0982:                holder.setList(new Vector());
0983:                holder.getList().add(new Referrer(1));
0984:                holder.getList().add(new Referrer(2));
0985:                holder.getList().add(new Book("Refer collection", "1"));
0986:                store.save(holder);
0987:                // Check
0988:                ListHolder dbHolder = (ListHolder) store
0989:                        .findSingle("find listholder");
0990:                assertEquals(3, dbHolder.getList().size());
0991:                Book book = new Book("Refer collection", "1");
0992:                assertFalse(dbHolder.getList().contains(book));
0993:            }
0994:
0995:            public void testListContainsExistingSame() throws Exception {
0996:                // Drop table
0997:                dropTables("listholder");
0998:                // Insert mixed stuff
0999:                ListHolder holder = new ListHolder();
1000:                holder.setList(new Vector());
1001:                holder.getList().add(new Referrer(1));
1002:                holder.getList().add(new Referrer(2));
1003:                Book book = new Book("Refer collection", "1");
1004:                holder.getList().add(book);
1005:                store.save(holder);
1006:                // Check
1007:                ListHolder dbHolder = (ListHolder) store
1008:                        .findSingle("find listholder");
1009:                assertEquals(3, dbHolder.getList().size());
1010:                assertTrue(dbHolder.getList().contains(book));
1011:            }
1012:
1013:            public void testListContainsAddedExistingSame() throws Exception {
1014:                // Drop table
1015:                dropTables("listholder");
1016:                // Insert mixed stuff
1017:                ListHolder holder = new ListHolder();
1018:                holder.setList(new Vector());
1019:                holder.getList().add(new Referrer(1));
1020:                holder.getList().add(new Referrer(2));
1021:                store.save(holder);
1022:                // Check
1023:                ListHolder dbHolder = (ListHolder) store
1024:                        .findSingle("find listholder");
1025:                assertEquals(2, dbHolder.getList().size());
1026:                Book book = new Book("Refer collection", "1");
1027:                store.save(book);
1028:                dbHolder.getList().add(book);
1029:                assertTrue(dbHolder.getList().contains(book));
1030:            }
1031:
1032:            public void testListContainsAddedExistingEquals() throws Exception {
1033:                // Drop table
1034:                dropTables("listholder");
1035:                // Insert mixed stuff
1036:                ListHolder holder = new ListHolder();
1037:                holder.setList(new Vector());
1038:                holder.getList().add(new Referrer(1));
1039:                holder.getList().add(new Referrer(2));
1040:                store.save(holder);
1041:                // Check
1042:                ListHolder dbHolder = (ListHolder) store
1043:                        .findSingle("find listholder");
1044:                assertEquals(2, dbHolder.getList().size());
1045:                Book book = new Book("Refer collection", "1");
1046:                store.save(book);
1047:                dbHolder.getList().add(book);
1048:                Book book2 = new Book("Refer collection", "1");
1049:                store.save(book2);
1050:                assertFalse(dbHolder.getList().contains(book2));
1051:            }
1052:
1053:            public void testListContainsAddedNonexistingSame() throws Exception {
1054:                // Drop table
1055:                dropTables("listholder");
1056:                // Insert mixed stuff
1057:                ListHolder holder = new ListHolder();
1058:                holder.setList(new Vector());
1059:                holder.getList().add(new Referrer(1));
1060:                holder.getList().add(new Referrer(2));
1061:                store.save(holder);
1062:                // Check
1063:                ListHolder dbHolder = (ListHolder) store
1064:                        .findSingle("find listholder");
1065:                assertEquals(2, dbHolder.getList().size());
1066:                Book book = new Book("Refer collection", "1");
1067:                dbHolder.getList().add(book);
1068:                assertTrue(dbHolder.getList().contains(book));
1069:            }
1070:
1071:            public void testListContainsAddedNonexistingEquals()
1072:                    throws Exception {
1073:                // Drop table
1074:                dropTables("listholder");
1075:                // Insert mixed stuff
1076:                ListHolder holder = new ListHolder();
1077:                holder.setList(new Vector());
1078:                holder.getList().add(new Referrer(1));
1079:                holder.getList().add(new Referrer(2));
1080:                store.save(holder);
1081:                // Check
1082:                ListHolder dbHolder = (ListHolder) store
1083:                        .findSingle("find listholder");
1084:                assertEquals(2, dbHolder.getList().size());
1085:                Book book = new Book("Refer collection", "1");
1086:                dbHolder.getList().add(book);
1087:                Book book2 = new Book("Refer collection", "1");
1088:                assertFalse(dbHolder.getList().contains(book2));
1089:            }
1090:
1091:            public void testListContainsLongNonexistingEquals()
1092:                    throws Exception {
1093:                // Drop table
1094:                dropTables("listholder");
1095:                // Insert mixed stuff
1096:                ListHolder holder = new ListHolder();
1097:                holder.setList(new Vector());
1098:                for (int i = 0; i < 50; i++)
1099:                    holder.getList().add(new Referrer(i));
1100:                holder.getList().add(new Book("Refer collection", "1"));
1101:                store.save(holder);
1102:                // Check
1103:                ListHolder dbHolder = (ListHolder) store
1104:                        .findSingle("find listholder");
1105:                assertEquals(51, dbHolder.getList().size());
1106:                assertFalse(dbHolder.getList().contains(
1107:                        new Book("Refer collection", "1")));
1108:            }
1109:
1110:            public void testListContainsLongExistingEquals() throws Exception {
1111:                // Drop table
1112:                dropTables("listholder");
1113:                // Insert mixed stuff
1114:                ListHolder holder = new ListHolder();
1115:                holder.setList(new Vector());
1116:                for (int i = 0; i < 50; i++)
1117:                    holder.getList().add(new Referrer(i));
1118:                holder.getList().add(new Book("Refer collection", "1"));
1119:                store.save(holder);
1120:                // Check
1121:                ListHolder dbHolder = (ListHolder) store
1122:                        .findSingle("find listholder");
1123:                assertEquals(51, dbHolder.getList().size());
1124:                Book book = new Book("Refer collection", "1");
1125:                assertFalse(dbHolder.getList().contains(book));
1126:            }
1127:
1128:            public void testListContainsLongExistingSame() throws Exception {
1129:                // Drop table
1130:                dropTables("listholder");
1131:                // Insert mixed stuff
1132:                ListHolder holder = new ListHolder();
1133:                holder.setList(new Vector());
1134:                for (int i = 0; i < 50; i++)
1135:                    holder.getList().add(new Referrer(i));
1136:                Book book = new Book("Refer collection", "1");
1137:                holder.getList().add(book);
1138:                store.save(holder);
1139:                // Check
1140:                ListHolder dbHolder = (ListHolder) store
1141:                        .findSingle("find listholder");
1142:                assertEquals(51, dbHolder.getList().size());
1143:                assertTrue(dbHolder.getList().contains(book));
1144:            }
1145:
1146:            public void testListContainsLongAddedExistingSame()
1147:                    throws Exception {
1148:                // Drop table
1149:                dropTables("listholder");
1150:                // Insert mixed stuff
1151:                ListHolder holder = new ListHolder();
1152:                holder.setList(new Vector());
1153:                for (int i = 0; i < 50; i++)
1154:                    holder.getList().add(new Referrer(i));
1155:                store.save(holder);
1156:                // Check
1157:                ListHolder dbHolder = (ListHolder) store
1158:                        .findSingle("find listholder");
1159:                assertEquals(50, dbHolder.getList().size());
1160:                Book book = new Book("Refer collection", "1");
1161:                store.save(book);
1162:                dbHolder.getList().add(book);
1163:                Book book2 = new Book("Refer collection", "1");
1164:                store.save(book2);
1165:                assertFalse(dbHolder.getList().contains(book2));
1166:            }
1167:
1168:            public void testListContainsLongAddedExistingEquals()
1169:                    throws Exception {
1170:                // Drop table
1171:                dropTables("listholder");
1172:                // Insert mixed stuff
1173:                ListHolder holder = new ListHolder();
1174:                holder.setList(new Vector());
1175:                for (int i = 0; i < 50; i++)
1176:                    holder.getList().add(new Referrer(i));
1177:                store.save(holder);
1178:                // Check
1179:                ListHolder dbHolder = (ListHolder) store
1180:                        .findSingle("find listholder");
1181:                assertEquals(50, dbHolder.getList().size());
1182:                Book book = new Book("Refer collection", "1");
1183:                store.save(book);
1184:                dbHolder.getList().add(book);
1185:                Book book2 = new Book("Refer collection", "1");
1186:                store.save(book2);
1187:                assertFalse(dbHolder.getList().contains(book2));
1188:            }
1189:
1190:            public void testListContainsLongAddedNonexistingSame()
1191:                    throws Exception {
1192:                // Drop table
1193:                dropTables("listholder");
1194:                // Insert mixed stuff
1195:                ListHolder holder = new ListHolder();
1196:                holder.setList(new Vector());
1197:                for (int i = 0; i < 50; i++)
1198:                    holder.getList().add(new Referrer(i));
1199:                store.save(holder);
1200:                // Check
1201:                ListHolder dbHolder = (ListHolder) store
1202:                        .findSingle("find listholder");
1203:                assertEquals(50, dbHolder.getList().size());
1204:                Book book = new Book("Refer collection", "1");
1205:                dbHolder.getList().add(book);
1206:                assertTrue(dbHolder.getList().contains(book));
1207:            }
1208:
1209:            public void testListContainsLongAddedNonexistingEquals()
1210:                    throws Exception {
1211:                // Drop table
1212:                dropTables("listholder");
1213:                // Insert mixed stuff
1214:                ListHolder holder = new ListHolder();
1215:                holder.setList(new Vector());
1216:                for (int i = 0; i < 50; i++)
1217:                    holder.getList().add(new Referrer(i));
1218:                store.save(holder);
1219:                // Check
1220:                ListHolder dbHolder = (ListHolder) store
1221:                        .findSingle("find listholder");
1222:                assertEquals(50, dbHolder.getList().size());
1223:                Book book = new Book("Refer collection", "1");
1224:                dbHolder.getList().add(book);
1225:                Book book2 = new Book("Refer collection", "1");
1226:                assertFalse(dbHolder.getList().contains(book2));
1227:            }
1228:
1229:            public void testListAddExistingTwiceToNewList() throws Exception {
1230:                // Drop table
1231:                dropTables("listholder");
1232:                // Insert mixed stuff
1233:                ListHolder holder = new ListHolder();
1234:                holder.setList(new Vector());
1235:                holder.getList().add(new Referrer(1));
1236:                holder.getList().add(new Referrer(2));
1237:                Book book = new Book("Refer collection", "1");
1238:                holder.getList().add(book);
1239:                holder.getList().add(0, book);
1240:                store.save(holder);
1241:                // Check
1242:                ListHolder dbHolder = (ListHolder) store
1243:                        .findSingle("find listholder");
1244:                assertEquals(4, dbHolder.getList().size());
1245:            }
1246:
1247:            public void testListsEqualCurrentToCurrent() throws Exception {
1248:                // Drop table
1249:                dropTables("listholder");
1250:                // Insert mixed stuff
1251:                ListHolder holder = new ListHolder();
1252:                holder.setList(new Vector());
1253:                holder.getList().add(new Referrer(1));
1254:                holder.getList().add(new Referrer(2));
1255:                holder.getList().add(new Book("Refer collection", "1"));
1256:                store.save(holder);
1257:                // Check
1258:                ListHolder dbHolder = (ListHolder) store
1259:                        .findSingle("find listholder");
1260:                assertEquals(3, dbHolder.getList().size());
1261:                ListHolder dbHolder2 = (ListHolder) store
1262:                        .findSingle("find listholder");
1263:                // Check
1264:                assertEquals(dbHolder.getList(), dbHolder2.getList());
1265:                assertEquals(dbHolder2.getList(), dbHolder.getList());
1266:            }
1267:
1268:            public void testListsEqualObsoleteToCurrentEqual() throws Exception {
1269:                // Drop table
1270:                dropTables("listholder");
1271:                // Insert mixed stuff
1272:                ListHolder holder = new ListHolder();
1273:                holder.setList(new Vector());
1274:                holder.getList().add(new Referrer(1));
1275:                holder.getList().add(new Referrer(2));
1276:                holder.getList().add(new Book("Refer collection", "1"));
1277:                store.save(holder);
1278:                // Check
1279:                ListHolder dbHolder = (ListHolder) store
1280:                        .findSingle("find listholder");
1281:                assertEquals(3, dbHolder.getList().size());
1282:                ListHolder dbHolder2 = (ListHolder) store
1283:                        .findSingle("find listholder");
1284:                // Make obsolete
1285:                Book modBook = new Book("Modification Book", "2");
1286:                dbHolder.getList().add(modBook);
1287:                store.save(dbHolder);
1288:                dbHolder.getList().remove(modBook);
1289:                store.save(dbHolder);
1290:                // Check
1291:                assertEquals(dbHolder.getList(), dbHolder2.getList());
1292:                assertEquals(dbHolder2.getList(), dbHolder.getList());
1293:            }
1294:
1295:            public void testListsEqualObsoleteToCurrentNonequal()
1296:                    throws Exception {
1297:                // Drop table
1298:                dropTables("listholder");
1299:                // Insert mixed stuff
1300:                ListHolder holder = new ListHolder();
1301:                holder.setList(new Vector());
1302:                holder.getList().add(new Referrer(1));
1303:                holder.getList().add(new Referrer(2));
1304:                holder.getList().add(new Book("Refer collection", "1"));
1305:                store.save(holder);
1306:                // Check
1307:                ListHolder dbHolder = (ListHolder) store
1308:                        .findSingle("find listholder");
1309:                assertEquals(3, dbHolder.getList().size());
1310:                ListHolder dbHolder2 = (ListHolder) store
1311:                        .findSingle("find listholder");
1312:                // Make obsolete
1313:                Book modBook = new Book("Modification Book", "2");
1314:                dbHolder.getList().add(modBook);
1315:                store.save(dbHolder);
1316:                // Check
1317:                assertFalse(dbHolder.getList().equals(dbHolder2.getList()));
1318:                assertFalse(dbHolder2.getList().equals(dbHolder.getList()));
1319:            }
1320:
1321:            public void testListsEqualCurrentToCustomEqual() throws Exception {
1322:                // Drop table
1323:                dropTables("listholder");
1324:                // Insert mixed stuff
1325:                Referrer ref1 = new Referrer(1);
1326:                store.save(ref1);
1327:                Referrer ref2 = new Referrer(2);
1328:                store.save(ref2);
1329:                Book book1 = new Book("Refer collection", "1");
1330:                store.save(book1);
1331:                ListHolder holder = new ListHolder();
1332:                holder.setList(new Vector());
1333:                holder.getList().add(ref1);
1334:                holder.getList().add(ref2);
1335:                holder.getList().add(book1);
1336:                store.save(holder);
1337:                // Check
1338:                ListHolder dbHolder = (ListHolder) store
1339:                        .findSingle("find listholder");
1340:                assertEquals(3, dbHolder.getList().size());
1341:                // Make custom which equal
1342:                Vector v = new Vector();
1343:                v.add(ref1);
1344:                v.add(ref2);
1345:                v.add(book1);
1346:                // Check
1347:                assertEquals(v, dbHolder.getList());
1348:            }
1349:
1350:            public void testListsEqualCurrentToCustomNonequal()
1351:                    throws Exception {
1352:                // Drop table
1353:                dropTables("listholder");
1354:                // Insert mixed stuff
1355:                Referrer ref1 = new Referrer(1);
1356:                store.save(ref1);
1357:                Referrer ref2 = new Referrer(2);
1358:                store.save(ref2);
1359:                Book book1 = new Book("Refer collection", "1");
1360:                store.save(book1);
1361:                ListHolder holder = new ListHolder();
1362:                holder.setList(new Vector());
1363:                holder.getList().add(ref1);
1364:                holder.getList().add(ref2);
1365:                holder.getList().add(book1);
1366:                store.save(holder);
1367:                // Check
1368:                ListHolder dbHolder = (ListHolder) store
1369:                        .findSingle("find listholder");
1370:                assertEquals(3, dbHolder.getList().size());
1371:                // Make custom which equal
1372:                Vector v = new Vector();
1373:                v.add(ref1);
1374:                v.add(ref2);
1375:                // Check
1376:                assertFalse(dbHolder.getList().equals(v));
1377:            }
1378:
1379:            public void testListsEqualsLongCurrentToCurrent() throws Exception {
1380:                // Drop table
1381:                dropTables("listholder");
1382:                // Insert mixed stuff
1383:                ListHolder holder = new ListHolder();
1384:                holder.setList(new Vector());
1385:                for (int i = 0; i < 50; i++)
1386:                    holder.getList().add(new Referrer(i));
1387:                holder.getList().add(new Book("Refer collection", "1"));
1388:                store.save(holder);
1389:                // Check
1390:                ListHolder dbHolder = (ListHolder) store
1391:                        .findSingle("find listholder");
1392:                assertEquals(51, dbHolder.getList().size());
1393:                ListHolder dbHolder2 = (ListHolder) store
1394:                        .findSingle("find listholder");
1395:                // Check
1396:                assertEquals(dbHolder.getList(), dbHolder2.getList());
1397:                assertEquals(dbHolder2.getList(), dbHolder.getList());
1398:            }
1399:
1400:            public void testListsEqualsLongObsoleteToCurrentEqual()
1401:                    throws Exception {
1402:                // Drop table
1403:                dropTables("listholder");
1404:                // Insert mixed stuff
1405:                ListHolder holder = new ListHolder();
1406:                holder.setList(new Vector());
1407:                for (int i = 0; i < 50; i++)
1408:                    holder.getList().add(new Referrer(i));
1409:                holder.getList().add(new Book("Refer collection", "1"));
1410:                store.save(holder);
1411:                // Check
1412:                ListHolder dbHolder = (ListHolder) store
1413:                        .findSingle("find listholder");
1414:                assertEquals(51, dbHolder.getList().size());
1415:                ListHolder dbHolder2 = (ListHolder) store
1416:                        .findSingle("find listholder");
1417:                // Make obsolete
1418:                Book modBook = new Book("Modification Book", "2");
1419:                dbHolder.getList().add(modBook);
1420:                store.save(dbHolder);
1421:                dbHolder.getList().remove(modBook);
1422:                store.save(dbHolder);
1423:                // Check
1424:                assertEquals(dbHolder.getList(), dbHolder2.getList());
1425:                assertEquals(dbHolder2.getList(), dbHolder.getList());
1426:            }
1427:
1428:            public void testListsEqualsLongObsoleteToCurrentNonequal()
1429:                    throws Exception {
1430:                // Drop table
1431:                dropTables("listholder");
1432:                // Insert mixed stuff
1433:                ListHolder holder = new ListHolder();
1434:                holder.setList(new Vector());
1435:                for (int i = 0; i < 50; i++)
1436:                    holder.getList().add(new Referrer(i));
1437:                holder.getList().add(new Book("Refer collection", "1"));
1438:                store.save(holder);
1439:                // Check
1440:                ListHolder dbHolder = (ListHolder) store
1441:                        .findSingle("find listholder");
1442:                assertEquals(51, dbHolder.getList().size());
1443:                ListHolder dbHolder2 = (ListHolder) store
1444:                        .findSingle("find listholder");
1445:                // Make obsolete
1446:                Book modBook = new Book("Modification Book", "2");
1447:                dbHolder.getList().add(modBook);
1448:                store.save(dbHolder);
1449:                // Check
1450:                assertFalse(dbHolder.getList().equals(dbHolder2.getList()));
1451:                assertFalse(dbHolder2.getList().equals(dbHolder.getList()));
1452:            }
1453:
1454:            public void testListGetOutOfBounds() throws Exception {
1455:                // Drop table
1456:                dropTables("listholder");
1457:                // Insert mixed stuff
1458:                ListHolder holder = new ListHolder();
1459:                holder.setList(new Vector());
1460:                holder.getList().add(new Referrer(1));
1461:                holder.getList().add(new Referrer(2));
1462:                holder.getList().add(new Book("Refer collection", "1"));
1463:                store.save(holder);
1464:                // Check
1465:                ListHolder dbHolder = (ListHolder) store
1466:                        .findSingle("find listholder");
1467:                try {
1468:                    dbHolder.getList().get(4);
1469:                    fail("4th item could be get, but there is no such item.");
1470:                } catch (ArrayIndexOutOfBoundsException e) {
1471:                }
1472:                try {
1473:                    dbHolder.getList().get(-1);
1474:                    fail("-1st item could be get, but there is no such item.");
1475:                } catch (ArrayIndexOutOfBoundsException e) {
1476:                }
1477:            }
1478:
1479:            public void testListRemoveNonexisting() throws Exception {
1480:                // Drop table
1481:                dropTables("listholder");
1482:                // Insert mixed stuff
1483:                ListHolder holder = new ListHolder();
1484:                holder.setList(new Vector());
1485:                holder.getList().add(new Referrer(1));
1486:                holder.getList().add(new Referrer(2));
1487:                holder.getList().add(new Book("Refer collection", "1"));
1488:                store.save(holder);
1489:                // Check
1490:                ListHolder dbHolder = (ListHolder) store
1491:                        .findSingle("find listholder");
1492:                assertEquals(3, dbHolder.getList().size());
1493:                dbHolder.getList().remove(new Book("Noone's Land", "1"));
1494:                assertEquals(3, dbHolder.getList().size());
1495:                dbHolder = (ListHolder) store.findSingle("find listholder");
1496:                assertEquals(3, dbHolder.getList().size());
1497:            }
1498:
1499:            public void testListRemoveExisting() throws Exception {
1500:                // Drop table
1501:                dropTables("listholder");
1502:                // Insert mixed stuff
1503:                ListHolder holder = new ListHolder();
1504:                holder.setList(new Vector());
1505:                holder.getList().add(new Referrer(1));
1506:                holder.getList().add(new Referrer(2));
1507:                holder.getList().add(new Book("Refer collection", "1"));
1508:                store.save(holder);
1509:                // Check
1510:                ListHolder dbHolder = (ListHolder) store
1511:                        .findSingle("find listholder");
1512:                assertEquals(3, dbHolder.getList().size());
1513:                Book book = new Book("Noone's Land", "1");
1514:                store.save(book);
1515:                dbHolder.getList().remove(book);
1516:                assertEquals(3, dbHolder.getList().size());
1517:                dbHolder = (ListHolder) store.findSingle("find listholder");
1518:                assertEquals(3, dbHolder.getList().size());
1519:            }
1520:
1521:            public void testListRemoveMember() throws Exception {
1522:                // Drop table
1523:                dropTables("listholder");
1524:                // Insert mixed stuff
1525:                ListHolder holder = new ListHolder();
1526:                holder.setList(new Vector());
1527:                holder.getList().add(new Referrer(1));
1528:                holder.getList().add(new Referrer(2));
1529:                Book book = new Book("Refer collection", "1");
1530:                holder.getList().add(book);
1531:                store.save(holder);
1532:                // Check
1533:                ListHolder dbHolder = (ListHolder) store
1534:                        .findSingle("find listholder");
1535:                assertEquals(3, dbHolder.getList().size());
1536:                dbHolder.getList().remove(book);
1537:                assertEquals(2, dbHolder.getList().size());
1538:                store.save(dbHolder);
1539:                dbHolder = (ListHolder) store.findSingle("find listholder");
1540:                assertEquals(2, dbHolder.getList().size());
1541:            }
1542:
1543:            public void testListRemoveLongNonexisting() throws Exception {
1544:                // Drop table
1545:                dropTables("listholder");
1546:                // Insert mixed stuff
1547:                ListHolder holder = new ListHolder();
1548:                holder.setList(new Vector());
1549:                for (int i = 0; i < 50; i++)
1550:                    holder.getList().add(new Referrer(i));
1551:                holder.getList().add(new Book("Refer collection", "1"));
1552:                store.save(holder);
1553:                // Check
1554:                ListHolder dbHolder = (ListHolder) store
1555:                        .findSingle("find listholder");
1556:                assertEquals(51, dbHolder.getList().size());
1557:                Book book = new Book("Noone's Land", "1");
1558:                dbHolder.getList().remove(book);
1559:                assertEquals(51, dbHolder.getList().size());
1560:                dbHolder = (ListHolder) store.findSingle("find listholder");
1561:                assertEquals(51, dbHolder.getList().size());
1562:            }
1563:
1564:            public void testListRemoveLongExisting() throws Exception {
1565:                // Drop table
1566:                dropTables("listholder");
1567:                // Insert mixed stuff
1568:                ListHolder holder = new ListHolder();
1569:                holder.setList(new Vector());
1570:                for (int i = 0; i < 50; i++)
1571:                    holder.getList().add(new Referrer(i));
1572:                holder.getList().add(new Book("Refer collection", "1"));
1573:                store.save(holder);
1574:                // Check
1575:                ListHolder dbHolder = (ListHolder) store
1576:                        .findSingle("find listholder");
1577:                assertEquals(51, dbHolder.getList().size());
1578:                Book book = new Book("Noone's Land", "1");
1579:                store.save(book);
1580:                dbHolder.getList().remove(book);
1581:                assertEquals(51, dbHolder.getList().size());
1582:                dbHolder = (ListHolder) store.findSingle("find listholder");
1583:                assertEquals(51, dbHolder.getList().size());
1584:            }
1585:
1586:            public void testListRemoveLongMember() throws Exception {
1587:                // Drop table
1588:                dropTables("listholder");
1589:                // Insert mixed stuff
1590:                ListHolder holder = new ListHolder();
1591:                holder.setList(new Vector());
1592:                for (int i = 0; i < 50; i++)
1593:                    holder.getList().add(new Referrer(i));
1594:                Book book = new Book("Noone's Land", "1");
1595:                holder.getList().add(book);
1596:                store.save(holder);
1597:                // Check
1598:                ListHolder dbHolder = (ListHolder) store
1599:                        .findSingle("find listholder");
1600:                assertEquals(51, dbHolder.getList().size());
1601:                dbHolder.getList().remove(book);
1602:                assertEquals(50, dbHolder.getList().size());
1603:                store.save(dbHolder);
1604:                dbHolder = (ListHolder) store.findSingle("find listholder");
1605:                assertEquals(50, dbHolder.getList().size());
1606:            }
1607:
1608:            public void testListRemoveLongOutside() throws Exception {
1609:                // Drop table
1610:                dropTables("listholder");
1611:                // Insert mixed stuff
1612:                ListHolder holder = new ListHolder();
1613:                holder.setList(new Vector());
1614:                for (int i = 0; i < 50; i++)
1615:                    holder.getList().add(new Referrer(i));
1616:                Book book = new Book("Noone's Land", "1");
1617:                holder.getList().add(book);
1618:                store.save(holder);
1619:                // Check
1620:                ListHolder dbHolder = (ListHolder) store
1621:                        .findSingle("find listholder");
1622:                assertEquals(51, dbHolder.getList().size());
1623:                store.remove(book);
1624:                dbHolder = (ListHolder) store.findSingle("find listholder");
1625:                assertEquals(50, dbHolder.getList().size());
1626:            }
1627:
1628:            public void testListIterationRemove() throws Exception {
1629:                // Drop table
1630:                dropTables("listholder");
1631:                // Add empty list
1632:                ListHolder holder = new ListHolder();
1633:                holder.setList(new Vector());
1634:                holder.getList().add(new Referrer(1));
1635:                holder.getList().add(new Referrer(2));
1636:                holder.getList().add(new Book("Refer collection", "1"));
1637:                store.save(holder);
1638:                // Get and add a nonexisting object too
1639:                ListHolder dbHolder = (ListHolder) store
1640:                        .findSingle("find listholder");
1641:                assertEquals(3, dbHolder.getList().size());
1642:                // Iterate
1643:                Iterator iterator = dbHolder.getList().iterator();
1644:                while (iterator.hasNext()) {
1645:                    iterator.next();
1646:                    iterator.remove();
1647:                }
1648:                store.save(dbHolder);
1649:                // Check
1650:                dbHolder = (ListHolder) store.findSingle("find listholder");
1651:                assertEquals(0, dbHolder.getList().size());
1652:            }
1653:
1654:            public void testListIterationNormal() throws Exception {
1655:                // Drop table
1656:                dropTables("listholder");
1657:                // Add empty list
1658:                ListHolder holder = new ListHolder();
1659:                holder.setList(new Vector());
1660:                holder.getList().add(new Referrer(1));
1661:                holder.getList().add(new Referrer(2));
1662:                holder.getList().add(new Book("Refer collection", "1"));
1663:                store.save(holder);
1664:                // Get and add a nonexisting object too
1665:                ListHolder dbHolder = (ListHolder) store
1666:                        .findSingle("find listholder");
1667:                // Iterate
1668:                assertEquals(3, dbHolder.getList().size());
1669:                Iterator iterator = dbHolder.getList().iterator();
1670:                while (iterator.hasNext())
1671:                    iterator.next();
1672:            }
1673:
1674:            public void testListIterationRemoved() throws Exception {
1675:                // Drop table
1676:                dropTables("listholder");
1677:                // Add empty list
1678:                ListHolder holder = new ListHolder();
1679:                holder.setList(new Vector());
1680:                holder.getList().add(new Referrer(1));
1681:                holder.getList().add(new Referrer(2));
1682:                Book book = new Book("Refer collection", "1");
1683:                holder.getList().add(book);
1684:                store.save(holder);
1685:                // Get and add a nonexisting object too
1686:                ListHolder dbHolder = (ListHolder) store
1687:                        .findSingle("find listholder");
1688:                dbHolder.getList().remove(book);
1689:                // Iterate
1690:                assertEquals(2, dbHolder.getList().size());
1691:                Iterator iterator = dbHolder.getList().iterator();
1692:                while (iterator.hasNext())
1693:                    iterator.next();
1694:            }
1695:
1696:            public void testListIterationAdded() throws Exception {
1697:                // Drop table
1698:                dropTables("listholder");
1699:                // Add empty list
1700:                ListHolder holder = new ListHolder();
1701:                holder.setList(new Vector());
1702:                holder.getList().add(new Referrer(1));
1703:                holder.getList().add(new Referrer(2));
1704:                holder.getList().add(new Book("Refer collection", "1"));
1705:                store.save(holder);
1706:                // Get and add a nonexisting object too
1707:                ListHolder dbHolder = (ListHolder) store
1708:                        .findSingle("find listholder");
1709:                dbHolder.getList().add(new Book("Second chance", "2"));
1710:                // Iterate
1711:                assertEquals(4, dbHolder.getList().size());
1712:                Iterator iterator = dbHolder.getList().iterator();
1713:                while (iterator.hasNext())
1714:                    iterator.next();
1715:            }
1716:
1717:            public void testListIterationAddedLong() throws Exception {
1718:                // Drop table
1719:                dropTables("listholder");
1720:                // Add empty list
1721:                ListHolder holder = new ListHolder();
1722:                holder.setList(new Vector());
1723:                for (int i = 0; i < 50; i++)
1724:                    holder.getList().add(new Referrer(i));
1725:                holder.getList().add(new Book("Refer collection", "1"));
1726:                store.save(holder);
1727:                // Get and add a nonexisting object too
1728:                ListHolder dbHolder = (ListHolder) store
1729:                        .findSingle("find listholder");
1730:                dbHolder.getList().add(new Book("Second chance", "2"));
1731:                // Iterate
1732:                assertEquals(52, dbHolder.getList().size());
1733:                Iterator iterator = dbHolder.getList().iterator();
1734:                while (iterator.hasNext())
1735:                    iterator.next();
1736:            }
1737:
1738:            public void testListPrimitives() throws Exception {
1739:                // Drop table
1740:                dropTables("listholder");
1741:                // Save
1742:                ListHolder holder = new ListHolder();
1743:                Vector content = new Vector();
1744:                holder.setList(content);
1745:                content
1746:                        .add(new Book("I Am Surrounded By Primitives",
1747:                                "1-1-1-1"));
1748:                content.add("Primitive String");
1749:                content.add(new Integer(1));
1750:                content.add(new Short((short) 2));
1751:                content.add(new Byte((byte) 3));
1752:                content.add(new Long(4));
1753:                content.add(new Float(5.5));
1754:                content.add(new Double(6.6));
1755:                content.add(new Character('a'));
1756:                content.add(new Boolean(true));
1757:                content.add(new Date());
1758:                store.save(holder);
1759:                // Recall
1760:                ListHolder result = (ListHolder) store
1761:                        .findSingle("find listholder");
1762:                List list = result.getList();
1763:                assertEquals(1, getCount(list, Book.class));
1764:                assertEquals(1, getCount(list, String.class));
1765:                assertEquals(1, getCount(list, Short.class));
1766:                assertEquals(1, getCount(list, Byte.class));
1767:                assertEquals(1, getCount(list, Long.class));
1768:                assertEquals(1, getCount(list, Float.class));
1769:                assertEquals(1, getCount(list, Double.class));
1770:                assertEquals(1, getCount(list, Character.class));
1771:                assertEquals(1, getCount(list, Boolean.class));
1772:                assertEquals(1, getCount(list, Date.class));
1773:                logger.debug("test result list is: " + list);
1774:            }
1775:
1776:            public void testIndexOfSmall() throws Exception {
1777:                // Drop table
1778:                dropTables("listholder");
1779:                // Create object
1780:                Book book = new Book("Second chance", "2");
1781:                store.save(book);
1782:                // Create list
1783:                ListHolder holder = new ListHolder();
1784:                holder.setList(new Vector());
1785:                holder.getList().add(new Referrer(1));
1786:                holder.getList().add(new Referrer(2));
1787:                holder.getList().add(book);
1788:                holder.getList().add(new Referrer(3));
1789:                holder.getList().add(new Referrer(4));
1790:                holder.getList().add(book);
1791:                store.save(holder);
1792:                // Check
1793:                ListHolder dbHolder = (ListHolder) store
1794:                        .findSingle("find listholder");
1795:                assertEquals(6, dbHolder.getList().size());
1796:                assertEquals(2, dbHolder.getList().indexOf(book));
1797:                assertEquals(5, dbHolder.getList().lastIndexOf(book));
1798:            }
1799:
1800:            public void testIndexOfLarge() throws Exception {
1801:                // Drop table
1802:                dropTables("listholder");
1803:                // Create object
1804:                Book book = new Book("Second chance", "2");
1805:                store.save(book);
1806:                // Create list
1807:                ListHolder holder = new ListHolder();
1808:                holder.setList(new Vector());
1809:                for (int i = 0; i < 20; i++)
1810:                    holder.getList().add(new Referrer(i));
1811:                holder.getList().add(book);
1812:                for (int i = 0; i < 20; i++)
1813:                    holder.getList().add(new Referrer(i));
1814:                holder.getList().add(book);
1815:                store.save(holder);
1816:                // Check
1817:                ListHolder dbHolder = (ListHolder) store
1818:                        .findSingle("find listholder");
1819:                assertEquals(42, dbHolder.getList().size());
1820:                assertEquals(20, dbHolder.getList().indexOf(book));
1821:                assertEquals(41, dbHolder.getList().lastIndexOf(book));
1822:            }
1823:
1824:            public void testContainsPrimitiveSmall() throws Exception {
1825:                // Drop table
1826:                dropTables("listholder");
1827:                // Create list
1828:                ListHolder holder = new ListHolder();
1829:                holder.setList(new Vector());
1830:                holder.getList().add(new Referrer(1));
1831:                holder.getList().add(new Referrer(2));
1832:                holder.getList().add(new StringBuffer("String Ni").toString());
1833:                holder.getList().add(new Referrer(3));
1834:                holder.getList().add(new Referrer(4));
1835:                holder.getList().add(new StringBuffer("String Ni").toString());
1836:                store.save(holder);
1837:                // Check
1838:                ListHolder dbHolder = (ListHolder) store
1839:                        .findSingle("find listholder");
1840:                assertEquals(6, dbHolder.getList().size());
1841:                assertEquals(2, dbHolder.getList().indexOf("String Ni"));
1842:                assertEquals(5, dbHolder.getList().lastIndexOf("String Ni"));
1843:                assertTrue(dbHolder.getList().contains("String Ni"));
1844:                assertFalse(dbHolder.getList().contains("String No"));
1845:            }
1846:
1847:            public void testContainsPrimitiveNonsavedSmall() throws Exception {
1848:                // Drop table
1849:                dropTables("listholder");
1850:                // Create list
1851:                ListHolder holder = new ListHolder();
1852:                holder.setList(new Vector());
1853:                holder.getList().add(new Referrer(1));
1854:                holder.getList().add(new Referrer(2));
1855:                store.save(holder);
1856:                // Check
1857:                ListHolder dbHolder = (ListHolder) store
1858:                        .findSingle("find listholder");
1859:                dbHolder.getList()
1860:                        .add(new StringBuffer("String Ni").toString());
1861:                assertTrue(dbHolder.getList().contains("String Ni"));
1862:                assertFalse(dbHolder.getList().contains("String No"));
1863:            }
1864:
1865:            public void testContainsPrimitiveLarge() throws Exception {
1866:                // Drop table
1867:                dropTables("listholder");
1868:                // Create object
1869:                Book book = new Book("Second chance", "2");
1870:                store.save(book);
1871:                // Create list
1872:                ListHolder holder = new ListHolder();
1873:                holder.setList(new Vector());
1874:                for (int i = 0; i < 20; i++)
1875:                    holder.getList().add(new Referrer(i));
1876:                holder.getList().add(new StringBuffer("String Ni").toString());
1877:                for (int i = 0; i < 20; i++)
1878:                    holder.getList().add(new Referrer(i));
1879:                holder.getList().add(new StringBuffer("String Ni").toString());
1880:                store.save(holder);
1881:                // Check
1882:                ListHolder dbHolder = (ListHolder) store
1883:                        .findSingle("find listholder");
1884:                assertEquals(42, dbHolder.getList().size());
1885:                assertEquals(20, dbHolder.getList().indexOf("String Ni"));
1886:                assertEquals(41, dbHolder.getList().lastIndexOf("String Ni"));
1887:                assertTrue(dbHolder.getList().contains("String Ni"));
1888:                assertFalse(dbHolder.getList().contains("String No"));
1889:            }
1890:
1891:            public void testContainsDeletedSmall() throws Exception {
1892:                // Drop table
1893:                dropTables("listholder");
1894:                // Create author
1895:                Author author = new Author("Stephenson", "Neal");
1896:                store.save(author);
1897:                // Create list
1898:                ListHolder holder = new ListHolder();
1899:                holder.setList(new Vector());
1900:                holder.getList().add(author);
1901:                store.save(holder);
1902:                // Remove author
1903:                store.remove(author);
1904:                // Check
1905:                ListHolder dbHolder = (ListHolder) store
1906:                        .findSingle("find listholder");
1907:                assertEquals(0, dbHolder.getList().size());
1908:                assertEquals(-1, dbHolder.getList().indexOf(author));
1909:                assertEquals(-1, dbHolder.getList().lastIndexOf(author));
1910:                assertFalse(dbHolder.getList().contains(author));
1911:            }
1912:
1913:            public void testContainsDeletedLarge() throws Exception {
1914:                // Drop table
1915:                dropTables("listholder");
1916:                // Create author
1917:                Author author = new Author("Stephenson", "Neal");
1918:                store.save(author);
1919:                // Create list
1920:                ListHolder holder = new ListHolder();
1921:                holder.setList(new Vector());
1922:                for (int i = 0; i < 40; i++)
1923:                    holder.getList().add(new Referrer(i));
1924:                holder.getList().add(author);
1925:                store.save(holder);
1926:                // Remove author
1927:                store.remove(author);
1928:                // Check
1929:                ListHolder dbHolder = (ListHolder) store
1930:                        .findSingle("find listholder");
1931:                assertEquals(40, dbHolder.getList().size());
1932:                assertEquals(-1, dbHolder.getList().indexOf(author));
1933:                assertEquals(-1, dbHolder.getList().lastIndexOf(author));
1934:                assertFalse(dbHolder.getList().contains(author));
1935:            }
1936:
1937:            public void testListInsertMiddle() throws Exception {
1938:                // Drop table
1939:                dropTables("listholder");
1940:                dropTables("referrer");
1941:                // Create list
1942:                ListHolder holder = new ListHolder();
1943:                holder.setList(new Vector());
1944:                holder.getList().add(new Referrer(1));
1945:                holder.getList().add(new Referrer(2));
1946:                store.save(holder);
1947:                // Insert middle
1948:                ListHolder dbHolder = (ListHolder) store
1949:                        .findSingle("find listholder");
1950:                dbHolder.getList().add(1, new Referrer(3));
1951:                store.save(dbHolder);
1952:                // Query again, and check
1953:                dbHolder = (ListHolder) store.findSingle("find listholder");
1954:                logger.debug("insert middle list is: " + dbHolder.getList());
1955:                assertEquals(1, ((Referrer) dbHolder.getList().get(0))
1956:                        .getIdentity());
1957:                assertEquals(3, ((Referrer) dbHolder.getList().get(1))
1958:                        .getIdentity());
1959:                assertEquals(2, ((Referrer) dbHolder.getList().get(2))
1960:                        .getIdentity());
1961:            }
1962:
1963:            public void testReindexing() throws Exception {
1964:                // Drop table
1965:                dropTables("listholder");
1966:                dropTables("referrer");
1967:                // Create list
1968:                ListHolder holder = new ListHolder();
1969:                holder.setList(new Vector());
1970:                holder.getList().add(new Referrer(1));
1971:                holder.getList().add(new Referrer(2));
1972:                holder.getList().add(new Referrer(3));
1973:                holder.getList().add(new Referrer(4));
1974:                store.save(holder);
1975:                // Load
1976:                ListHolder dbHolder = (ListHolder) store
1977:                        .findSingle("find listholder");
1978:                // Insert 40 referrers between 2 and 3
1979:                for (int i = 0; i < 40; i++)
1980:                    dbHolder.getList().add(2, new Referrer(10 + i));
1981:                store.save(dbHolder); // Reindexing must occur here
1982:                // Check
1983:                dbHolder = (ListHolder) store.findSingle("find listholder");
1984:                logger.debug("reindexing test result: " + dbHolder.getList());
1985:                for (int i = 0; i < 40; i++)
1986:                    assertEquals(49 - i, ((Referrer) dbHolder.getList().get(
1987:                            i + 2)).getIdentity());
1988:                assertEquals(1, ((Referrer) dbHolder.getList().get(0))
1989:                        .getIdentity());
1990:                assertEquals(2, ((Referrer) dbHolder.getList().get(1))
1991:                        .getIdentity());
1992:                assertEquals(3, ((Referrer) dbHolder.getList().get(42))
1993:                        .getIdentity());
1994:                assertEquals(4, ((Referrer) dbHolder.getList().get(43))
1995:                        .getIdentity());
1996:            }
1997:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.