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:
0021: /**
0022: * Test the container framework.
0023: * @author Brautigam Robert
0024: * @version Revision: $Revision$
0025: */
0026: public class SetContainerTests extends AbstractPersistenceTest {
0027: public SetContainerTests(String name) throws Exception {
0028: super (name);
0029: }
0030:
0031: public void testSetInitializeWithNonexisting() throws Exception {
0032: // Drop table
0033: dropTables("setholder");
0034: // Insert mixed stuff
0035: SetHolder holder = new SetHolder();
0036: holder.setSet(new HashSet());
0037: holder.getSet().add(new Referrer(1));
0038: holder.getSet().add(new Referrer(2));
0039: holder.getSet().add(new Book("Refer collection", "1"));
0040: store.save(holder);
0041: // Check
0042: SetHolder dbHolder = (SetHolder) store
0043: .findSingle("find setholder");
0044: assertEquals(3, dbHolder.getSet().size());
0045: }
0046:
0047: public void testSetInitializeWithExisting() throws Exception {
0048: // Drop table
0049: dropTables("setholder");
0050: // Insert mixed stuff
0051: Referrer ref1 = new Referrer(1);
0052: store.save(ref1);
0053: Referrer ref2 = new Referrer(2);
0054: store.save(ref2);
0055: Book book1 = new Book("Refer collection", "1");
0056: store.save(book1);
0057: SetHolder holder = new SetHolder();
0058: holder.setSet(new HashSet());
0059: holder.getSet().add(ref1);
0060: holder.getSet().add(ref2);
0061: holder.getSet().add(book1);
0062: store.save(holder);
0063: // Check
0064: SetHolder dbHolder = (SetHolder) store
0065: .findSingle("find setholder");
0066: assertEquals(3, dbHolder.getSet().size());
0067: }
0068:
0069: public void testSetFullToNullAndBack() throws Exception {
0070: // Drop table
0071: dropTables("setholder");
0072: // Insert mixed stuff
0073: SetHolder holder = new SetHolder();
0074: holder.setSet(new HashSet());
0075: holder.getSet().add(new Referrer(1));
0076: holder.getSet().add(new Referrer(2));
0077: holder.getSet().add(new Book("Refer collection", "1"));
0078: store.save(holder);
0079: // Check
0080: SetHolder dbHolder = (SetHolder) store
0081: .findSingle("find setholder");
0082: assertEquals(3, dbHolder.getSet().size());
0083: // Set to null
0084: dbHolder.setSet(null);
0085: store.save(dbHolder);
0086: // Check
0087: dbHolder = (SetHolder) store.findSingle("find setholder");
0088: assertNull(dbHolder.getSet());
0089: // Set back
0090: dbHolder.setSet(new HashSet());
0091: dbHolder.getSet().add(new Referrer(1));
0092: dbHolder.getSet().add(new Referrer(2));
0093: store.save(dbHolder);
0094: // Check
0095: dbHolder = (SetHolder) store.findSingle("find setholder");
0096: assertEquals(2, dbHolder.getSet().size());
0097: }
0098:
0099: public void testSetEmptyAddOnceNonexistingToCurrent()
0100: throws Exception {
0101: // Drop table
0102: dropTables("setholder");
0103: // Add empty set
0104: SetHolder holder = new SetHolder();
0105: holder.setSet(new HashSet());
0106: store.save(holder);
0107: // Get
0108: SetHolder dbHolder = (SetHolder) store
0109: .findSingle("find setholder");
0110: dbHolder.getSet().add(new Book("Second chance", "2"));
0111: store.save(dbHolder);
0112: // Check
0113: dbHolder = (SetHolder) store.findSingle("find setholder");
0114: assertEquals(1, dbHolder.getSet().size());
0115: }
0116:
0117: public void testSetNonemptyAddOnceNonexistingToCurrent()
0118: throws Exception {
0119: // Drop table
0120: dropTables("setholder");
0121: // Add empty set
0122: SetHolder holder = new SetHolder();
0123: holder.setSet(new HashSet());
0124: holder.getSet().add(new Referrer(1));
0125: holder.getSet().add(new Referrer(2));
0126: holder.getSet().add(new Book("Refer collection", "1"));
0127: store.save(holder);
0128: // Get
0129: SetHolder dbHolder = (SetHolder) store
0130: .findSingle("find setholder");
0131: dbHolder.getSet().add(new Book("Second chance", "2"));
0132: store.save(dbHolder);
0133: // Check
0134: dbHolder = (SetHolder) store.findSingle("find setholder");
0135: assertEquals(4, dbHolder.getSet().size());
0136: }
0137:
0138: public void testSetEmptyAddOnceExistingToCurrent() throws Exception {
0139: // Drop table
0140: dropTables("setholder");
0141: // Add empty set
0142: SetHolder holder = new SetHolder();
0143: holder.setSet(new HashSet());
0144: store.save(holder);
0145: // Get
0146: Book book2 = new Book("Second chance", "2");
0147: store.save(book2);
0148: SetHolder dbHolder = (SetHolder) store
0149: .findSingle("find setholder");
0150: dbHolder.getSet().add(book2);
0151: store.save(dbHolder);
0152: // Check
0153: dbHolder = (SetHolder) store.findSingle("find setholder");
0154: assertEquals(1, dbHolder.getSet().size());
0155: }
0156:
0157: public void testSetNonemptyAddOnceExistingToCurrent()
0158: throws Exception {
0159: // Drop table
0160: dropTables("setholder");
0161: // Add empty set
0162: SetHolder holder = new SetHolder();
0163: holder.setSet(new HashSet());
0164: holder.getSet().add(new Referrer(1));
0165: holder.getSet().add(new Referrer(2));
0166: holder.getSet().add(new Book("Refer collection", "1"));
0167: store.save(holder);
0168: // Get
0169: Book book2 = new Book("Second chance", "2");
0170: store.save(book2);
0171: SetHolder dbHolder = (SetHolder) store
0172: .findSingle("find setholder");
0173: dbHolder.getSet().add(book2);
0174: store.save(dbHolder);
0175: // Check
0176: dbHolder = (SetHolder) store.findSingle("find setholder");
0177: assertEquals(4, dbHolder.getSet().size());
0178: }
0179:
0180: public void testSetContainsAddOnceExistingToCurrent()
0181: throws Exception {
0182: // Drop table
0183: dropTables("setholder");
0184: // Add empty set
0185: SetHolder holder = new SetHolder();
0186: holder.setSet(new HashSet());
0187: holder.getSet().add(new Referrer(1));
0188: holder.getSet().add(new Referrer(2));
0189: Book book2 = new Book("Second chance", "2");
0190: holder.getSet().add(book2);
0191: store.save(holder);
0192: // Get
0193: SetHolder dbHolder = (SetHolder) store
0194: .findSingle("find setholder");
0195: assertEquals(3, dbHolder.getSet().size());
0196: dbHolder.getSet().add(book2);
0197: store.save(dbHolder);
0198: // Check
0199: dbHolder = (SetHolder) store.findSingle("find setholder");
0200: assertEquals(3, dbHolder.getSet().size());
0201: }
0202:
0203: public void testSetEmptyAddTwiceNonexistingToCurrent()
0204: throws Exception {
0205: // Drop table
0206: dropTables("setholder");
0207: // Add empty set
0208: SetHolder holder = new SetHolder();
0209: holder.setSet(new HashSet());
0210: store.save(holder);
0211: // Get
0212: SetHolder dbHolder = (SetHolder) store
0213: .findSingle("find setholder");
0214: Book book = new Book("Second chance", "2");
0215: dbHolder.getSet().add(book);
0216: dbHolder.getSet().add(book);
0217: store.save(dbHolder);
0218: // Check
0219: dbHolder = (SetHolder) store.findSingle("find setholder");
0220: assertEquals(1, dbHolder.getSet().size());
0221: }
0222:
0223: public void testSetNonemptyAddTwiceNonexistingToCurrent()
0224: throws Exception {
0225: // Drop table
0226: dropTables("setholder");
0227: // Add empty set
0228: SetHolder holder = new SetHolder();
0229: holder.setSet(new HashSet());
0230: holder.getSet().add(new Referrer(1));
0231: holder.getSet().add(new Referrer(2));
0232: holder.getSet().add(new Book("Refer collection", "1"));
0233: store.save(holder);
0234: // Get
0235: SetHolder dbHolder = (SetHolder) store
0236: .findSingle("find setholder");
0237: Book book = new Book("Second chance", "2");
0238: dbHolder.getSet().add(book);
0239: dbHolder.getSet().add(book);
0240: store.save(dbHolder);
0241: // Check
0242: dbHolder = (SetHolder) store.findSingle("find setholder");
0243: assertEquals(4, dbHolder.getSet().size());
0244: }
0245:
0246: public void testSetEmptyAddTwiceExistingToCurrent()
0247: throws Exception {
0248: // Drop table
0249: dropTables("setholder");
0250: // Add empty set
0251: SetHolder holder = new SetHolder();
0252: holder.setSet(new HashSet());
0253: store.save(holder);
0254: // Get
0255: SetHolder dbHolder = (SetHolder) store
0256: .findSingle("find setholder");
0257: Book book = new Book("Second chance", "2");
0258: store.save(book);
0259: dbHolder.getSet().add(book);
0260: dbHolder.getSet().add(book);
0261: store.save(dbHolder);
0262: // Check
0263: dbHolder = (SetHolder) store.findSingle("find setholder");
0264: assertEquals(1, dbHolder.getSet().size());
0265: }
0266:
0267: public void testSetNonemptyAddTwiceExistingToCurrent()
0268: throws Exception {
0269: // Drop table
0270: dropTables("setholder");
0271: // Add empty set
0272: SetHolder holder = new SetHolder();
0273: holder.setSet(new HashSet());
0274: holder.getSet().add(new Referrer(1));
0275: holder.getSet().add(new Referrer(2));
0276: holder.getSet().add(new Book("Refer collection", "1"));
0277: store.save(holder);
0278: // Get
0279: SetHolder dbHolder = (SetHolder) store
0280: .findSingle("find setholder");
0281: Book book = new Book("Second chance", "2");
0282: store.save(book);
0283: dbHolder.getSet().add(book);
0284: dbHolder.getSet().add(book);
0285: store.save(dbHolder);
0286: // Check
0287: dbHolder = (SetHolder) store.findSingle("find setholder");
0288: assertEquals(4, dbHolder.getSet().size());
0289: }
0290:
0291: public void testSetContainsAddTwiceExistingToCurrent()
0292: throws Exception {
0293: // Drop table
0294: dropTables("setholder");
0295: // Add empty set
0296: SetHolder holder = new SetHolder();
0297: Book book = new Book("Second chance", "2");
0298: holder.setSet(new HashSet());
0299: holder.getSet().add(new Referrer(1));
0300: holder.getSet().add(new Referrer(2));
0301: holder.getSet().add(book);
0302: holder.getSet().add(new Book("Refer collection", "1"));
0303: store.save(holder);
0304: // Get
0305: SetHolder dbHolder = (SetHolder) store
0306: .findSingle("find setholder");
0307: store.save(book);
0308: dbHolder.getSet().add(book);
0309: dbHolder.getSet().add(book);
0310: store.save(dbHolder);
0311: // Check
0312: dbHolder = (SetHolder) store.findSingle("find setholder");
0313: assertEquals(4, dbHolder.getSet().size());
0314: }
0315:
0316: public void testSetEmptyAddOnceNonexistingToObsolete()
0317: throws Exception {
0318: // Drop table
0319: dropTables("setholder");
0320: // Add empty set
0321: SetHolder holder = new SetHolder();
0322: holder.setSet(new HashSet());
0323: store.save(holder);
0324: // Get
0325: SetHolder dbHolder = (SetHolder) store
0326: .findSingle("find setholder");
0327: dbHolder.getSet().add(new Book("Second chance", "2"));
0328: // Make previous holder obsolate
0329: SetHolder currentHolder = (SetHolder) store
0330: .findSingle("find setholder");
0331: Book modBook = new Book("Modification Book", "2");
0332: currentHolder.getSet().add(modBook);
0333: store.save(currentHolder);
0334: currentHolder.getSet().remove(modBook);
0335: store.save(currentHolder);
0336: // Operation
0337: store.save(dbHolder);
0338: // Check
0339: dbHolder = (SetHolder) store.findSingle("find setholder");
0340: assertEquals(1, dbHolder.getSet().size());
0341: }
0342:
0343: public void testSetNonemptyAddOnceNonexistingToObsolete()
0344: throws Exception {
0345: // Drop table
0346: dropTables("setholder");
0347: // Add empty set
0348: SetHolder holder = new SetHolder();
0349: holder.setSet(new HashSet());
0350: holder.getSet().add(new Referrer(1));
0351: holder.getSet().add(new Referrer(2));
0352: holder.getSet().add(new Book("Refer collection", "1"));
0353: store.save(holder);
0354: // Get
0355: SetHolder dbHolder = (SetHolder) store
0356: .findSingle("find setholder");
0357: dbHolder.getSet().add(new Book("Second chance", "2"));
0358: // Make previous holder obsolate
0359: SetHolder currentHolder = (SetHolder) store
0360: .findSingle("find setholder");
0361: Book modBook = new Book("Modification Book", "2");
0362: currentHolder.getSet().add(modBook);
0363: store.save(currentHolder);
0364: currentHolder.getSet().remove(modBook);
0365: store.save(currentHolder);
0366: // Check
0367: store.save(dbHolder);
0368: SetHolder result = (SetHolder) store
0369: .findSingle("find setholder");
0370: assertEquals(4, result.getSet().size());
0371: }
0372:
0373: public void testSetEmptyAddOnceExistingToObsolete()
0374: throws Exception {
0375: // Drop table
0376: dropTables("setholder");
0377: // Add empty set
0378: SetHolder holder = new SetHolder();
0379: holder.setSet(new HashSet());
0380: store.save(holder);
0381: // Get
0382: Book book2 = new Book("Second chance", "2");
0383: store.save(book2);
0384: SetHolder dbHolder = (SetHolder) store
0385: .findSingle("find setholder");
0386: dbHolder.getSet().add(book2);
0387: // Make previous holder obsolate
0388: SetHolder currentHolder = (SetHolder) store
0389: .findSingle("find setholder");
0390: Book modBook = new Book("Modification Book", "2");
0391: currentHolder.getSet().add(modBook);
0392: store.save(currentHolder);
0393: currentHolder.getSet().remove(modBook);
0394: store.save(currentHolder);
0395: // Operation
0396: store.save(dbHolder);
0397: // Check
0398: dbHolder = (SetHolder) store.findSingle("find setholder");
0399: assertEquals(1, dbHolder.getSet().size());
0400: }
0401:
0402: public void testSetNonemptyAddOnceExistingToObsolete()
0403: throws Exception {
0404: // Drop table
0405: dropTables("setholder");
0406: // Add empty set
0407: SetHolder holder = new SetHolder();
0408: holder.setSet(new HashSet());
0409: holder.getSet().add(new Referrer(1));
0410: holder.getSet().add(new Referrer(2));
0411: holder.getSet().add(new Book("Refer collection", "1"));
0412: store.save(holder);
0413: // Get
0414: Book book2 = new Book("Second chance", "2");
0415: store.save(book2);
0416: SetHolder dbHolder = (SetHolder) store
0417: .findSingle("find setholder");
0418: dbHolder.getSet().add(book2);
0419: // Make previous holder obsolate
0420: SetHolder currentHolder = (SetHolder) store
0421: .findSingle("find setholder");
0422: Book modBook = new Book("Modification Book", "2");
0423: currentHolder.getSet().add(modBook);
0424: store.save(currentHolder);
0425: currentHolder.getSet().remove(modBook);
0426: store.save(currentHolder);
0427: // Check
0428: store.save(dbHolder);
0429: SetHolder result = (SetHolder) store
0430: .findSingle("find setholder");
0431: assertEquals(4, result.getSet().size());
0432: }
0433:
0434: public void testSetContainsAddOnceExistingToObsolete()
0435: throws Exception {
0436: // Drop table
0437: dropTables("setholder");
0438: // Add empty set
0439: SetHolder holder = new SetHolder();
0440: holder.setSet(new HashSet());
0441: holder.getSet().add(new Referrer(1));
0442: holder.getSet().add(new Referrer(2));
0443: Book book2 = new Book("Second chance", "2");
0444: holder.getSet().add(book2);
0445: store.save(holder);
0446: // Get
0447: SetHolder dbHolder = (SetHolder) store
0448: .findSingle("find setholder");
0449: assertEquals(3, dbHolder.getSet().size());
0450: dbHolder.getSet().add(book2);
0451: // Make previous holder obsolate
0452: SetHolder currentHolder = (SetHolder) store
0453: .findSingle("find setholder");
0454: Book modBook = new Book("Modification Book", "2");
0455: currentHolder.getSet().add(modBook);
0456: store.save(currentHolder);
0457: currentHolder.getSet().remove(modBook);
0458: store.save(currentHolder);
0459: // Check
0460: store.save(dbHolder);
0461: SetHolder result = (SetHolder) store
0462: .findSingle("find setholder");
0463: assertEquals(3, result.getSet().size());
0464: }
0465:
0466: public void testSetEmptyAddTwiceNonexistingToObsolete()
0467: throws Exception {
0468: // Drop table
0469: dropTables("setholder");
0470: // Add empty set
0471: SetHolder holder = new SetHolder();
0472: holder.setSet(new HashSet());
0473: store.save(holder);
0474: // Get
0475: SetHolder dbHolder = (SetHolder) store
0476: .findSingle("find setholder");
0477: Book book = new Book("Second chance", "2");
0478: dbHolder.getSet().add(book);
0479: dbHolder.getSet().add(book);
0480: // Make previous holder obsolate
0481: SetHolder currentHolder = (SetHolder) store
0482: .findSingle("find setholder");
0483: Book modBook = new Book("Modification Book", "2");
0484: currentHolder.getSet().add(modBook);
0485: store.save(currentHolder);
0486: currentHolder.getSet().remove(modBook);
0487: store.save(currentHolder);
0488: // Operation
0489: store.save(dbHolder);
0490: // Check
0491: dbHolder = (SetHolder) store.findSingle("find setholder");
0492: assertEquals(1, dbHolder.getSet().size());
0493: }
0494:
0495: public void testSetNonemptyAddTwiceNonexistingToObsolete()
0496: throws Exception {
0497: // Drop table
0498: dropTables("setholder");
0499: // Add empty set
0500: SetHolder holder = new SetHolder();
0501: holder.setSet(new HashSet());
0502: holder.getSet().add(new Referrer(1));
0503: holder.getSet().add(new Referrer(2));
0504: holder.getSet().add(new Book("Refer collection", "1"));
0505: store.save(holder);
0506: // Get
0507: SetHolder dbHolder = (SetHolder) store
0508: .findSingle("find setholder");
0509: Book book = new Book("Second chance", "2");
0510: dbHolder.getSet().add(book);
0511: dbHolder.getSet().add(book);
0512: // Make previous holder obsolate
0513: SetHolder currentHolder = (SetHolder) store
0514: .findSingle("find setholder");
0515: Book modBook = new Book("Modification Book", "2");
0516: currentHolder.getSet().add(modBook);
0517: store.save(currentHolder);
0518: currentHolder.getSet().remove(modBook);
0519: store.save(currentHolder);
0520: // Check
0521: store.save(dbHolder);
0522: SetHolder result = (SetHolder) store
0523: .findSingle("find setholder");
0524: assertEquals(4, result.getSet().size());
0525: }
0526:
0527: public void testSetEmptyAddTwiceExistingToObsolete()
0528: throws Exception {
0529: // Drop table
0530: dropTables("setholder");
0531: // Add empty set
0532: SetHolder holder = new SetHolder();
0533: holder.setSet(new HashSet());
0534: store.save(holder);
0535: // Get
0536: SetHolder dbHolder = (SetHolder) store
0537: .findSingle("find setholder");
0538: Book book = new Book("Second chance", "2");
0539: store.save(book);
0540: dbHolder.getSet().add(book);
0541: dbHolder.getSet().add(book);
0542: // Make previous holder obsolate
0543: SetHolder currentHolder = (SetHolder) store
0544: .findSingle("find setholder");
0545: Book modBook = new Book("Modification Book", "2");
0546: currentHolder.getSet().add(modBook);
0547: store.save(currentHolder);
0548: currentHolder.getSet().remove(modBook);
0549: store.save(currentHolder);
0550: // Operation
0551: store.save(dbHolder);
0552: // Check
0553: dbHolder = (SetHolder) store.findSingle("find setholder");
0554: assertEquals(1, dbHolder.getSet().size());
0555: }
0556:
0557: public void testSetNonemptyAddTwiceExistingToObsolete()
0558: throws Exception {
0559: // Drop table
0560: dropTables("setholder");
0561: // Add empty set
0562: SetHolder holder = new SetHolder();
0563: holder.setSet(new HashSet());
0564: holder.getSet().add(new Referrer(1));
0565: holder.getSet().add(new Referrer(2));
0566: holder.getSet().add(new Book("Refer collection", "1"));
0567: store.save(holder);
0568: // Get
0569: SetHolder dbHolder = (SetHolder) store
0570: .findSingle("find setholder");
0571: Book book = new Book("Second chance", "2");
0572: store.save(book);
0573: dbHolder.getSet().add(book);
0574: dbHolder.getSet().add(book);
0575: // Make previous holder obsolate
0576: SetHolder currentHolder = (SetHolder) store
0577: .findSingle("find setholder");
0578: Book modBook = new Book("Modification Book", "2");
0579: currentHolder.getSet().add(modBook);
0580: store.save(currentHolder);
0581: currentHolder.getSet().remove(modBook);
0582: store.save(currentHolder);
0583: // Check
0584: store.save(dbHolder);
0585: SetHolder result = (SetHolder) store
0586: .findSingle("find setholder");
0587: assertEquals(4, result.getSet().size());
0588: }
0589:
0590: public void testSetContainsAddTwiceExistingToObsolete()
0591: throws Exception {
0592: // Drop table
0593: dropTables("setholder");
0594: // Add empty set
0595: SetHolder holder = new SetHolder();
0596: Book book = new Book("Second chance", "2");
0597: holder.setSet(new HashSet());
0598: holder.getSet().add(new Referrer(1));
0599: holder.getSet().add(new Referrer(2));
0600: holder.getSet().add(book);
0601: holder.getSet().add(new Book("Refer collection", "1"));
0602: store.save(holder);
0603: // Get
0604: SetHolder dbHolder = (SetHolder) store
0605: .findSingle("find setholder");
0606: store.save(book);
0607: dbHolder.getSet().add(book);
0608: dbHolder.getSet().add(book);
0609: // Make previous holder obsolate
0610: SetHolder currentHolder = (SetHolder) store
0611: .findSingle("find setholder");
0612: Book modBook = new Book("Modification Book", "2");
0613: currentHolder.getSet().add(modBook);
0614: store.save(currentHolder);
0615: currentHolder.getSet().remove(modBook);
0616: store.save(currentHolder);
0617: // Check
0618: store.save(dbHolder);
0619: SetHolder result = (SetHolder) store
0620: .findSingle("find setholder");
0621: assertEquals(4, result.getSet().size());
0622: }
0623:
0624: public void testSetEmptyAddOnceNonexistingToCustom()
0625: throws Exception {
0626: // Drop table
0627: dropTables("setholder");
0628: // Add empty set
0629: SetHolder holder = new SetHolder();
0630: holder.setSet(new HashSet());
0631: store.save(holder);
0632: // Get
0633: SetHolder dbHolder = (SetHolder) store
0634: .findSingle("find setholder");
0635: dbHolder.setSet(new HashSet());
0636: dbHolder.getSet().add(new Book("Second chance", "2"));
0637: store.save(dbHolder);
0638: // Check
0639: dbHolder = (SetHolder) store.findSingle("find setholder");
0640: assertEquals(1, dbHolder.getSet().size());
0641: }
0642:
0643: public void testSetNonemptyAddOnceNonexistingToCustom()
0644: throws Exception {
0645: // Drop table
0646: dropTables("setholder");
0647: // Add empty set
0648: SetHolder holder = new SetHolder();
0649: holder.setSet(new HashSet());
0650: holder.getSet().add(new Referrer(1));
0651: holder.getSet().add(new Referrer(2));
0652: holder.getSet().add(new Book("Refer collection", "1"));
0653: store.save(holder);
0654: // Get
0655: SetHolder dbHolder = (SetHolder) store
0656: .findSingle("find setholder");
0657: dbHolder.setSet(new HashSet());
0658: dbHolder.getSet().add(new Book("Second chance", "2"));
0659: store.save(dbHolder);
0660: // Check
0661: dbHolder = (SetHolder) store.findSingle("find setholder");
0662: assertEquals(1, dbHolder.getSet().size());
0663: }
0664:
0665: public void testSetEmptyAddOnceExistingToCustom() throws Exception {
0666: // Drop table
0667: dropTables("setholder");
0668: // Add empty set
0669: SetHolder holder = new SetHolder();
0670: holder.setSet(new HashSet());
0671: store.save(holder);
0672: // Get
0673: Book book2 = new Book("Second chance", "2");
0674: store.save(book2);
0675: SetHolder dbHolder = (SetHolder) store
0676: .findSingle("find setholder");
0677: dbHolder.setSet(new HashSet());
0678: dbHolder.getSet().add(book2);
0679: store.save(dbHolder);
0680: // Check
0681: dbHolder = (SetHolder) store.findSingle("find setholder");
0682: assertEquals(1, dbHolder.getSet().size());
0683: }
0684:
0685: public void testSetNonemptyAddOnceExistingToCustom()
0686: throws Exception {
0687: // Drop table
0688: dropTables("setholder");
0689: // Add empty set
0690: SetHolder holder = new SetHolder();
0691: holder.setSet(new HashSet());
0692: holder.getSet().add(new Referrer(1));
0693: holder.getSet().add(new Referrer(2));
0694: holder.getSet().add(new Book("Refer collection", "1"));
0695: store.save(holder);
0696: // Get
0697: Book book2 = new Book("Second chance", "2");
0698: store.save(book2);
0699: SetHolder dbHolder = (SetHolder) store
0700: .findSingle("find setholder");
0701: dbHolder.setSet(new HashSet());
0702: dbHolder.getSet().add(book2);
0703: store.save(dbHolder);
0704: // Check
0705: dbHolder = (SetHolder) store.findSingle("find setholder");
0706: assertEquals(1, dbHolder.getSet().size());
0707: }
0708:
0709: public void testSetContainsAddOnceExistingToCustom()
0710: throws Exception {
0711: // Drop table
0712: dropTables("setholder");
0713: // Add empty set
0714: SetHolder holder = new SetHolder();
0715: holder.setSet(new HashSet());
0716: holder.getSet().add(new Referrer(1));
0717: holder.getSet().add(new Referrer(2));
0718: Book book2 = new Book("Second chance", "2");
0719: holder.getSet().add(book2);
0720: store.save(holder);
0721: // Get
0722: SetHolder dbHolder = (SetHolder) store
0723: .findSingle("find setholder");
0724: assertEquals(3, dbHolder.getSet().size());
0725: dbHolder.setSet(new HashSet());
0726: dbHolder.getSet().add(book2);
0727: store.save(dbHolder);
0728: // Check
0729: dbHolder = (SetHolder) store.findSingle("find setholder");
0730: assertEquals(1, dbHolder.getSet().size());
0731: }
0732:
0733: public void testSetEmptyAddTwiceNonexistingToCustom()
0734: throws Exception {
0735: // Drop table
0736: dropTables("setholder");
0737: // Add empty set
0738: SetHolder holder = new SetHolder();
0739: holder.setSet(new HashSet());
0740: store.save(holder);
0741: // Get
0742: SetHolder dbHolder = (SetHolder) store
0743: .findSingle("find setholder");
0744: Book book = new Book("Second chance", "2");
0745: dbHolder.setSet(new HashSet());
0746: dbHolder.getSet().add(book);
0747: dbHolder.getSet().add(book);
0748: store.save(dbHolder);
0749: // Check
0750: dbHolder = (SetHolder) store.findSingle("find setholder");
0751: assertEquals(1, dbHolder.getSet().size());
0752: }
0753:
0754: public void testSetNonemptyAddTwiceNonexistingToCustom()
0755: throws Exception {
0756: // Drop table
0757: dropTables("setholder");
0758: // Add empty set
0759: SetHolder holder = new SetHolder();
0760: holder.setSet(new HashSet());
0761: holder.getSet().add(new Referrer(1));
0762: holder.getSet().add(new Referrer(2));
0763: holder.getSet().add(new Book("Refer collection", "1"));
0764: store.save(holder);
0765: // Get
0766: SetHolder dbHolder = (SetHolder) store
0767: .findSingle("find setholder");
0768: Book book = new Book("Second chance", "2");
0769: dbHolder.setSet(new HashSet());
0770: dbHolder.getSet().add(book);
0771: dbHolder.getSet().add(book);
0772: store.save(dbHolder);
0773: // Check
0774: dbHolder = (SetHolder) store.findSingle("find setholder");
0775: assertEquals(1, dbHolder.getSet().size());
0776: }
0777:
0778: public void testSetEmptyAddTwiceExistingToCustom() throws Exception {
0779: // Drop table
0780: dropTables("setholder");
0781: // Add empty set
0782: SetHolder holder = new SetHolder();
0783: holder.setSet(new HashSet());
0784: store.save(holder);
0785: // Get
0786: SetHolder dbHolder = (SetHolder) store
0787: .findSingle("find setholder");
0788: Book book = new Book("Second chance", "2");
0789: dbHolder.setSet(new HashSet());
0790: store.save(book);
0791: dbHolder.getSet().add(book);
0792: dbHolder.getSet().add(book);
0793: store.save(dbHolder);
0794: // Check
0795: dbHolder = (SetHolder) store.findSingle("find setholder");
0796: assertEquals(1, dbHolder.getSet().size());
0797: }
0798:
0799: public void testSetNonemptyAddTwiceExistingToCustom()
0800: throws Exception {
0801: // Drop table
0802: dropTables("setholder");
0803: // Add empty set
0804: SetHolder holder = new SetHolder();
0805: holder.setSet(new HashSet());
0806: holder.getSet().add(new Referrer(1));
0807: holder.getSet().add(new Referrer(2));
0808: holder.getSet().add(new Book("Refer collection", "1"));
0809: store.save(holder);
0810: // Get
0811: SetHolder dbHolder = (SetHolder) store
0812: .findSingle("find setholder");
0813: Book book = new Book("Second chance", "2");
0814: store.save(book);
0815: dbHolder.setSet(new HashSet());
0816: dbHolder.getSet().add(book);
0817: dbHolder.getSet().add(book);
0818: store.save(dbHolder);
0819: // Check
0820: dbHolder = (SetHolder) store.findSingle("find setholder");
0821: assertEquals(1, dbHolder.getSet().size());
0822: }
0823:
0824: public void testSetContainsAddTwiceExistingToCustom()
0825: throws Exception {
0826: // Drop table
0827: dropTables("setholder");
0828: // Add empty set
0829: SetHolder holder = new SetHolder();
0830: Book book = new Book("Second chance", "2");
0831: holder.setSet(new HashSet());
0832: holder.getSet().add(new Referrer(1));
0833: holder.getSet().add(new Referrer(2));
0834: holder.getSet().add(book);
0835: holder.getSet().add(new Book("Refer collection", "1"));
0836: store.save(holder);
0837: // Get
0838: SetHolder dbHolder = (SetHolder) store
0839: .findSingle("find setholder");
0840: dbHolder.setSet(new HashSet());
0841: store.save(book);
0842: dbHolder.getSet().add(book);
0843: dbHolder.getSet().add(book);
0844: store.save(dbHolder);
0845: // Check
0846: dbHolder = (SetHolder) store.findSingle("find setholder");
0847: assertEquals(1, dbHolder.getSet().size());
0848: }
0849:
0850: public void testSetAssignForeignSetNonexisting() throws Exception {
0851: // Drop table
0852: dropTables("setholder");
0853: // Add empty set
0854: SetHolder holder = new SetHolder();
0855: Book book = new Book("Second chance", "2");
0856: holder.setSet(new HashSet());
0857: holder.getSet().add(new Referrer(1));
0858: holder.getSet().add(new Referrer(2));
0859: holder.getSet().add(book);
0860: holder.getSet().add(new Book("Refer collection", "1"));
0861: store.save(holder);
0862: // Get
0863: SetHolder dbHolder = (SetHolder) store
0864: .findSingle("find setholder");
0865: // Now assign that set to other setholder
0866: SetHolder otherHolder = new SetHolder();
0867: otherHolder.setSet(dbHolder.getSet());
0868: store.save(otherHolder);
0869: // Get the result
0870: SetHolder dbOtherHolder = (SetHolder) store
0871: .findSingle("find setholder");
0872: assertEquals(4, dbOtherHolder.getSet().size());
0873: }
0874:
0875: public void testSetAssignForeignSetExisting() throws Exception {
0876: // Drop table
0877: dropTables("setholder");
0878: // Add empty set
0879: SetHolder holder = new SetHolder();
0880: Book book = new Book("Second chance", "2");
0881: holder.setSet(new HashSet());
0882: holder.getSet().add(new Referrer(1));
0883: holder.getSet().add(new Referrer(2));
0884: holder.getSet().add(book);
0885: holder.getSet().add(new Book("Refer collection", "1"));
0886: store.save(holder);
0887: // Get
0888: SetHolder dbHolder = (SetHolder) store
0889: .findSingle("find setholder");
0890: // Now assign that set to other setholder
0891: SetHolder otherHolder = new SetHolder();
0892: otherHolder.setSet(new HashSet());
0893: store.save(otherHolder);
0894: otherHolder = (SetHolder) store.findSingle("find setholder");
0895: otherHolder.setSet(dbHolder.getSet());
0896: store.save(otherHolder);
0897: // Get the result
0898: SetHolder dbOtherHolder = (SetHolder) store
0899: .findSingle("find setholder");
0900: assertEquals(4, dbOtherHolder.getSet().size());
0901: }
0902:
0903: public void testSetClearOnCurrent() throws Exception {
0904: // Drop table
0905: dropTables("setholder");
0906: // Insert mixed stuff
0907: SetHolder holder = new SetHolder();
0908: holder.setSet(new HashSet());
0909: holder.getSet().add(new Referrer(1));
0910: holder.getSet().add(new Referrer(2));
0911: holder.getSet().add(new Book("Refer collection", "1"));
0912: store.save(holder);
0913: // Check and clear
0914: SetHolder dbHolder = (SetHolder) store
0915: .findSingle("find setholder");
0916: assertEquals(3, dbHolder.getSet().size());
0917: dbHolder.getSet().clear();
0918: store.save(dbHolder);
0919: // Get
0920: dbHolder = (SetHolder) store.findSingle("find setholder");
0921: assertEquals(0, dbHolder.getSet().size());
0922: }
0923:
0924: public void testSetClearOnObsolete() throws Exception {
0925: // Drop table
0926: dropTables("setholder");
0927: // Add empty set
0928: SetHolder holder = new SetHolder();
0929: holder.setSet(new HashSet());
0930: holder.getSet().add(new Referrer(1));
0931: holder.getSet().add(new Referrer(2));
0932: store.save(holder);
0933: // Get
0934: SetHolder dbHolder = (SetHolder) store
0935: .findSingle("find setholder");
0936: dbHolder.getSet().clear();
0937: // Make previous holder obsolate
0938: SetHolder currentHolder = (SetHolder) store
0939: .findSingle("find setholder");
0940: Book modBook = new Book("Modification Book", "2");
0941: currentHolder.getSet().add(modBook);
0942: store.save(currentHolder);
0943: currentHolder.getSet().remove(modBook);
0944: store.save(currentHolder);
0945: // Check
0946: store.save(dbHolder);
0947: SetHolder result = (SetHolder) store
0948: .findSingle("find setholder");
0949: assertEquals(0, result.getSet().size());
0950: }
0951:
0952: public void testSetContainsNonexistingEquals() throws Exception {
0953: // Drop table
0954: dropTables("setholder");
0955: // Insert mixed stuff
0956: SetHolder holder = new SetHolder();
0957: holder.setSet(new HashSet());
0958: holder.getSet().add(new Referrer(1));
0959: holder.getSet().add(new Referrer(2));
0960: holder.getSet().add(new Book("Refer collection", "1"));
0961: store.save(holder);
0962: // Check
0963: SetHolder dbHolder = (SetHolder) store
0964: .findSingle("find setholder");
0965: assertEquals(3, dbHolder.getSet().size());
0966: assertFalse(dbHolder.getSet().contains(
0967: new Book("Refer collection", "1")));
0968: }
0969:
0970: public void testSetContainsExistingEquals() throws Exception {
0971: // Drop table
0972: dropTables("setholder");
0973: // Insert mixed stuff
0974: SetHolder holder = new SetHolder();
0975: holder.setSet(new HashSet());
0976: holder.getSet().add(new Referrer(1));
0977: holder.getSet().add(new Referrer(2));
0978: holder.getSet().add(new Book("Refer collection", "1"));
0979: store.save(holder);
0980: // Check
0981: SetHolder dbHolder = (SetHolder) store
0982: .findSingle("find setholder");
0983: assertEquals(3, dbHolder.getSet().size());
0984: Book book = new Book("Refer collection", "1");
0985: assertFalse(dbHolder.getSet().contains(book));
0986: }
0987:
0988: public void testSetContainsExistingSame() throws Exception {
0989: // Drop table
0990: dropTables("setholder");
0991: // Insert mixed stuff
0992: SetHolder holder = new SetHolder();
0993: holder.setSet(new HashSet());
0994: holder.getSet().add(new Referrer(1));
0995: holder.getSet().add(new Referrer(2));
0996: Book book = new Book("Refer collection", "1");
0997: holder.getSet().add(book);
0998: store.save(holder);
0999: // Check
1000: SetHolder dbHolder = (SetHolder) store
1001: .findSingle("find setholder");
1002: assertEquals(3, dbHolder.getSet().size());
1003: assertTrue(dbHolder.getSet().contains(book));
1004: }
1005:
1006: public void testSetContainsAddedExistingSame() throws Exception {
1007: // Drop table
1008: dropTables("setholder");
1009: // Insert mixed stuff
1010: SetHolder holder = new SetHolder();
1011: holder.setSet(new HashSet());
1012: holder.getSet().add(new Referrer(1));
1013: holder.getSet().add(new Referrer(2));
1014: store.save(holder);
1015: // Check
1016: SetHolder dbHolder = (SetHolder) store
1017: .findSingle("find setholder");
1018: assertEquals(2, dbHolder.getSet().size());
1019: Book book = new Book("Refer collection", "1");
1020: store.save(book);
1021: dbHolder.getSet().add(book);
1022: assertTrue(dbHolder.getSet().contains(book));
1023: }
1024:
1025: public void testSetContainsAddedExistingEquals() throws Exception {
1026: // Drop table
1027: dropTables("setholder");
1028: // Insert mixed stuff
1029: SetHolder holder = new SetHolder();
1030: holder.setSet(new HashSet());
1031: holder.getSet().add(new Referrer(1));
1032: holder.getSet().add(new Referrer(2));
1033: store.save(holder);
1034: // Check
1035: SetHolder dbHolder = (SetHolder) store
1036: .findSingle("find setholder");
1037: assertEquals(2, dbHolder.getSet().size());
1038: Book book = new Book("Refer collection", "1");
1039: store.save(book);
1040: dbHolder.getSet().add(book);
1041: Book book2 = new Book("Refer collection", "1");
1042: store.save(book2);
1043: assertFalse(dbHolder.getSet().contains(book2));
1044: }
1045:
1046: public void testSetContainsAddedNonexistingSame() throws Exception {
1047: // Drop table
1048: dropTables("setholder");
1049: // Insert mixed stuff
1050: SetHolder holder = new SetHolder();
1051: holder.setSet(new HashSet());
1052: holder.getSet().add(new Referrer(1));
1053: holder.getSet().add(new Referrer(2));
1054: store.save(holder);
1055: // Check
1056: SetHolder dbHolder = (SetHolder) store
1057: .findSingle("find setholder");
1058: assertEquals(2, dbHolder.getSet().size());
1059: Book book = new Book("Refer collection", "1");
1060: dbHolder.getSet().add(book);
1061: assertTrue(dbHolder.getSet().contains(book));
1062: }
1063:
1064: public void testSetContainsAddedNonexistingEquals()
1065: throws Exception {
1066: // Drop table
1067: dropTables("setholder");
1068: // Insert mixed stuff
1069: SetHolder holder = new SetHolder();
1070: holder.setSet(new HashSet());
1071: holder.getSet().add(new Referrer(1));
1072: holder.getSet().add(new Referrer(2));
1073: store.save(holder);
1074: // Check
1075: SetHolder dbHolder = (SetHolder) store
1076: .findSingle("find setholder");
1077: assertEquals(2, dbHolder.getSet().size());
1078: Book book = new Book("Refer collection", "1");
1079: dbHolder.getSet().add(book);
1080: Book book2 = new Book("Refer collection", "1");
1081: assertFalse(dbHolder.getSet().contains(book2));
1082: }
1083:
1084: public void testSetContainsLongNonexistingEquals() throws Exception {
1085: // Drop table
1086: dropTables("setholder");
1087: // Insert mixed stuff
1088: SetHolder holder = new SetHolder();
1089: holder.setSet(new HashSet());
1090: for (int i = 0; i < 50; i++)
1091: holder.getSet().add(new Referrer(i));
1092: holder.getSet().add(new Book("Refer collection", "1"));
1093: store.save(holder);
1094: // Check
1095: SetHolder dbHolder = (SetHolder) store
1096: .findSingle("find setholder");
1097: assertEquals(51, dbHolder.getSet().size());
1098: assertFalse(dbHolder.getSet().contains(
1099: new Book("Refer collection", "1")));
1100: }
1101:
1102: public void testSetContainsLongExistingEquals() throws Exception {
1103: // Drop table
1104: dropTables("setholder");
1105: // Insert mixed stuff
1106: SetHolder holder = new SetHolder();
1107: holder.setSet(new HashSet());
1108: for (int i = 0; i < 50; i++)
1109: holder.getSet().add(new Referrer(i));
1110: holder.getSet().add(new Book("Refer collection", "1"));
1111: store.save(holder);
1112: // Check
1113: SetHolder dbHolder = (SetHolder) store
1114: .findSingle("find setholder");
1115: assertEquals(51, dbHolder.getSet().size());
1116: Book book = new Book("Refer collection", "1");
1117: assertFalse(dbHolder.getSet().contains(book));
1118: }
1119:
1120: public void testSetContainsLongExistingSame() throws Exception {
1121: // Drop table
1122: dropTables("setholder");
1123: // Insert mixed stuff
1124: SetHolder holder = new SetHolder();
1125: holder.setSet(new HashSet());
1126: for (int i = 0; i < 50; i++)
1127: holder.getSet().add(new Referrer(i));
1128: Book book = new Book("Refer collection", "1");
1129: holder.getSet().add(book);
1130: store.save(holder);
1131: // Check
1132: SetHolder dbHolder = (SetHolder) store
1133: .findSingle("find setholder");
1134: assertEquals(51, dbHolder.getSet().size());
1135: assertTrue(dbHolder.getSet().contains(book));
1136: }
1137:
1138: public void testSetContainsLongAddedExistingSame() throws Exception {
1139: // Drop table
1140: dropTables("setholder");
1141: // Insert mixed stuff
1142: SetHolder holder = new SetHolder();
1143: holder.setSet(new HashSet());
1144: for (int i = 0; i < 50; i++)
1145: holder.getSet().add(new Referrer(i));
1146: store.save(holder);
1147: // Check
1148: SetHolder dbHolder = (SetHolder) store
1149: .findSingle("find setholder");
1150: assertEquals(50, dbHolder.getSet().size());
1151: Book book = new Book("Refer collection", "1");
1152: store.save(book);
1153: dbHolder.getSet().add(book);
1154: Book book2 = new Book("Refer collection", "1");
1155: store.save(book2);
1156: assertFalse(dbHolder.getSet().contains(book2));
1157: }
1158:
1159: public void testSetContainsLongAddedExistingEquals()
1160: throws Exception {
1161: // Drop table
1162: dropTables("setholder");
1163: // Insert mixed stuff
1164: SetHolder holder = new SetHolder();
1165: holder.setSet(new HashSet());
1166: for (int i = 0; i < 50; i++)
1167: holder.getSet().add(new Referrer(i));
1168: store.save(holder);
1169: // Check
1170: SetHolder dbHolder = (SetHolder) store
1171: .findSingle("find setholder");
1172: assertEquals(50, dbHolder.getSet().size());
1173: Book book = new Book("Refer collection", "1");
1174: store.save(book);
1175: dbHolder.getSet().add(book);
1176: Book book2 = new Book("Refer collection", "1");
1177: store.save(book2);
1178: assertFalse(dbHolder.getSet().contains(book2));
1179: }
1180:
1181: public void testSetContainsLongAddedNonexistingSame()
1182: throws Exception {
1183: // Drop table
1184: dropTables("setholder");
1185: // Insert mixed stuff
1186: SetHolder holder = new SetHolder();
1187: holder.setSet(new HashSet());
1188: for (int i = 0; i < 50; i++)
1189: holder.getSet().add(new Referrer(i));
1190: store.save(holder);
1191: // Check
1192: SetHolder dbHolder = (SetHolder) store
1193: .findSingle("find setholder");
1194: assertEquals(50, dbHolder.getSet().size());
1195: Book book = new Book("Refer collection", "1");
1196: dbHolder.getSet().add(book);
1197: assertTrue(dbHolder.getSet().contains(book));
1198: }
1199:
1200: public void testSetContainsLongAddedNonexistingEquals()
1201: throws Exception {
1202: // Drop table
1203: dropTables("setholder");
1204: // Insert mixed stuff
1205: SetHolder holder = new SetHolder();
1206: holder.setSet(new HashSet());
1207: for (int i = 0; i < 50; i++)
1208: holder.getSet().add(new Referrer(i));
1209: store.save(holder);
1210: // Check
1211: SetHolder dbHolder = (SetHolder) store
1212: .findSingle("find setholder");
1213: assertEquals(50, dbHolder.getSet().size());
1214: Book book = new Book("Refer collection", "1");
1215: dbHolder.getSet().add(book);
1216: Book book2 = new Book("Refer collection", "1");
1217: assertFalse(dbHolder.getSet().contains(book2));
1218: }
1219:
1220: public void testSetAddExistingTwiceToNewSet() throws Exception {
1221: // Drop table
1222: dropTables("setholder");
1223: // Insert mixed stuff
1224: SetHolder holder = new SetHolder();
1225: holder.setSet(new HashSet());
1226: holder.getSet().add(new Referrer(1));
1227: holder.getSet().add(new Referrer(2));
1228: Book book = new Book("Refer collection", "1");
1229: holder.getSet().add(book);
1230: holder.getSet().add(book);
1231: store.save(holder);
1232: // Check
1233: SetHolder dbHolder = (SetHolder) store
1234: .findSingle("find setholder");
1235: assertEquals(3, dbHolder.getSet().size());
1236: }
1237:
1238: public void testSetsEqualCurrentToCurrent() throws Exception {
1239: // Drop table
1240: dropTables("setholder");
1241: // Insert mixed stuff
1242: SetHolder holder = new SetHolder();
1243: holder.setSet(new HashSet());
1244: holder.getSet().add(new Referrer(1));
1245: holder.getSet().add(new Referrer(2));
1246: holder.getSet().add(new Book("Refer collection", "1"));
1247: store.save(holder);
1248: // Check
1249: SetHolder dbHolder = (SetHolder) store
1250: .findSingle("find setholder");
1251: assertEquals(3, dbHolder.getSet().size());
1252: SetHolder dbHolder2 = (SetHolder) store
1253: .findSingle("find setholder");
1254: // Check
1255: assertEquals(dbHolder.getSet(), dbHolder2.getSet());
1256: assertEquals(dbHolder2.getSet(), dbHolder.getSet());
1257: }
1258:
1259: public void testSetsEqualObsoleteToCurrentEqual() throws Exception {
1260: // Drop table
1261: dropTables("setholder");
1262: // Insert mixed stuff
1263: SetHolder holder = new SetHolder();
1264: holder.setSet(new HashSet());
1265: holder.getSet().add(new Referrer(1));
1266: holder.getSet().add(new Referrer(2));
1267: holder.getSet().add(new Book("Refer collection", "1"));
1268: store.save(holder);
1269: // Check
1270: SetHolder dbHolder = (SetHolder) store
1271: .findSingle("find setholder");
1272: assertEquals(3, dbHolder.getSet().size());
1273: SetHolder dbHolder2 = (SetHolder) store
1274: .findSingle("find setholder");
1275: // Make obsolete
1276: Book modBook = new Book("Modification Book", "2");
1277: dbHolder.getSet().add(modBook);
1278: store.save(dbHolder);
1279: dbHolder.getSet().remove(modBook);
1280: store.save(dbHolder);
1281: // Check
1282: assertEquals(dbHolder.getSet(), dbHolder2.getSet());
1283: assertEquals(dbHolder2.getSet(), dbHolder.getSet());
1284: }
1285:
1286: public void testSetsEqualObsoleteToCurrentNonequal()
1287: throws Exception {
1288: // Drop table
1289: dropTables("setholder");
1290: // Insert mixed stuff
1291: SetHolder holder = new SetHolder();
1292: holder.setSet(new HashSet());
1293: holder.getSet().add(new Referrer(1));
1294: holder.getSet().add(new Referrer(2));
1295: holder.getSet().add(new Book("Refer collection", "1"));
1296: store.save(holder);
1297: // Check
1298: SetHolder dbHolder = (SetHolder) store
1299: .findSingle("find setholder");
1300: assertEquals(3, dbHolder.getSet().size());
1301: SetHolder dbHolder2 = (SetHolder) store
1302: .findSingle("find setholder");
1303: // Make obsolete
1304: Book modBook = new Book("Modification Book", "2");
1305: dbHolder.getSet().add(modBook);
1306: store.save(dbHolder);
1307: // Check
1308: assertFalse(dbHolder.getSet().equals(dbHolder2.getSet()));
1309: assertFalse(dbHolder2.getSet().equals(dbHolder.getSet()));
1310: }
1311:
1312: public void testSetsEqualCurrentToCustomEqual() throws Exception {
1313: // Drop table
1314: dropTables("setholder");
1315: // Insert mixed stuff
1316: Referrer ref1 = new Referrer(1);
1317: store.save(ref1);
1318: Referrer ref2 = new Referrer(2);
1319: store.save(ref2);
1320: Book book1 = new Book("Refer collection", "1");
1321: store.save(book1);
1322: SetHolder holder = new SetHolder();
1323: holder.setSet(new HashSet());
1324: holder.getSet().add(ref1);
1325: holder.getSet().add(ref2);
1326: holder.getSet().add(book1);
1327: store.save(holder);
1328: // Check
1329: SetHolder dbHolder = (SetHolder) store
1330: .findSingle("find setholder");
1331: assertEquals(3, dbHolder.getSet().size());
1332: // Make custom which equal
1333: HashSet v = new HashSet();
1334: v.add(ref1);
1335: v.add(ref2);
1336: v.add(book1);
1337: // Check
1338: assertEquals(dbHolder.getSet(), v);
1339: }
1340:
1341: public void testSetsEqualCurrentToCustomNonequal() throws Exception {
1342: // Drop table
1343: dropTables("setholder");
1344: // Insert mixed stuff
1345: Referrer ref1 = new Referrer(1);
1346: store.save(ref1);
1347: Referrer ref2 = new Referrer(2);
1348: store.save(ref2);
1349: Book book1 = new Book("Refer collection", "1");
1350: store.save(book1);
1351: SetHolder holder = new SetHolder();
1352: holder.setSet(new HashSet());
1353: holder.getSet().add(ref1);
1354: holder.getSet().add(ref2);
1355: holder.getSet().add(book1);
1356: store.save(holder);
1357: // Check
1358: SetHolder dbHolder = (SetHolder) store
1359: .findSingle("find setholder");
1360: assertEquals(3, dbHolder.getSet().size());
1361: // Make custom which equal
1362: HashSet v = new HashSet();
1363: v.add(ref1);
1364: v.add(ref2);
1365: // Check
1366: assertFalse(dbHolder.getSet().equals(v));
1367: }
1368:
1369: public void testSetsEqualsLongCurrentToCurrent() throws Exception {
1370: // Drop table
1371: dropTables("setholder");
1372: // Insert mixed stuff
1373: SetHolder holder = new SetHolder();
1374: holder.setSet(new HashSet());
1375: for (int i = 0; i < 50; i++)
1376: holder.getSet().add(new Referrer(i));
1377: holder.getSet().add(new Book("Refer collection", "1"));
1378: store.save(holder);
1379: // Check
1380: SetHolder dbHolder = (SetHolder) store
1381: .findSingle("find setholder");
1382: assertEquals(51, dbHolder.getSet().size());
1383: SetHolder dbHolder2 = (SetHolder) store
1384: .findSingle("find setholder");
1385: // Check
1386: assertEquals(dbHolder.getSet(), dbHolder2.getSet());
1387: assertEquals(dbHolder2.getSet(), dbHolder.getSet());
1388: }
1389:
1390: public void testSetsEqualsLongObsoleteToCurrentEqual()
1391: throws Exception {
1392: // Drop table
1393: dropTables("setholder");
1394: // Insert mixed stuff
1395: SetHolder holder = new SetHolder();
1396: holder.setSet(new HashSet());
1397: for (int i = 0; i < 50; i++)
1398: holder.getSet().add(new Referrer(i));
1399: holder.getSet().add(new Book("Refer collection", "1"));
1400: store.save(holder);
1401: // Check
1402: SetHolder dbHolder = (SetHolder) store
1403: .findSingle("find setholder");
1404: assertEquals(51, dbHolder.getSet().size());
1405: SetHolder dbHolder2 = (SetHolder) store
1406: .findSingle("find setholder");
1407: // Make obsolete
1408: Book modBook = new Book("Modification Book", "2");
1409: dbHolder.getSet().add(modBook);
1410: store.save(dbHolder);
1411: dbHolder.getSet().remove(modBook);
1412: store.save(dbHolder);
1413: // Check
1414: assertEquals(dbHolder.getSet(), dbHolder2.getSet());
1415: assertEquals(dbHolder2.getSet(), dbHolder.getSet());
1416: }
1417:
1418: public void testSetsEqualsLongObsoleteToCurrentNonequal()
1419: throws Exception {
1420: // Drop table
1421: dropTables("setholder");
1422: // Insert mixed stuff
1423: SetHolder holder = new SetHolder();
1424: holder.setSet(new HashSet());
1425: for (int i = 0; i < 50; i++)
1426: holder.getSet().add(new Referrer(i));
1427: holder.getSet().add(new Book("Refer collection", "1"));
1428: store.save(holder);
1429: // Check
1430: SetHolder dbHolder = (SetHolder) store
1431: .findSingle("find setholder");
1432: assertEquals(51, dbHolder.getSet().size());
1433: SetHolder dbHolder2 = (SetHolder) store
1434: .findSingle("find setholder");
1435: // Make obsolete
1436: Book modBook = new Book("Modification Book", "2");
1437: dbHolder.getSet().add(modBook);
1438: store.save(dbHolder);
1439: // Check
1440: assertFalse(dbHolder.getSet().equals(dbHolder2.getSet()));
1441: assertFalse(dbHolder2.getSet().equals(dbHolder.getSet()));
1442: }
1443:
1444: public void testSetRemoveNonexisting() throws Exception {
1445: // Drop table
1446: dropTables("setholder");
1447: // Insert mixed stuff
1448: SetHolder holder = new SetHolder();
1449: holder.setSet(new HashSet());
1450: holder.getSet().add(new Referrer(1));
1451: holder.getSet().add(new Referrer(2));
1452: holder.getSet().add(new Book("Refer collection", "1"));
1453: store.save(holder);
1454: // Check
1455: SetHolder dbHolder = (SetHolder) store
1456: .findSingle("find setholder");
1457: assertEquals(3, dbHolder.getSet().size());
1458: dbHolder.getSet().remove(new Book("Noone's Land", "1"));
1459: assertEquals(3, dbHolder.getSet().size());
1460: dbHolder = (SetHolder) store.findSingle("find setholder");
1461: assertEquals(3, dbHolder.getSet().size());
1462: }
1463:
1464: public void testSetRemoveExisting() throws Exception {
1465: // Drop table
1466: dropTables("setholder");
1467: // Insert mixed stuff
1468: SetHolder holder = new SetHolder();
1469: holder.setSet(new HashSet());
1470: holder.getSet().add(new Referrer(1));
1471: holder.getSet().add(new Referrer(2));
1472: holder.getSet().add(new Book("Refer collection", "1"));
1473: store.save(holder);
1474: // Check
1475: SetHolder dbHolder = (SetHolder) store
1476: .findSingle("find setholder");
1477: assertEquals(3, dbHolder.getSet().size());
1478: Book book = new Book("Noone's Land", "1");
1479: store.save(book);
1480: dbHolder.getSet().remove(book);
1481: assertEquals(3, dbHolder.getSet().size());
1482: dbHolder = (SetHolder) store.findSingle("find setholder");
1483: assertEquals(3, dbHolder.getSet().size());
1484: }
1485:
1486: public void testSetRemoveMember() throws Exception {
1487: // Drop table
1488: dropTables("setholder");
1489: // Insert mixed stuff
1490: SetHolder holder = new SetHolder();
1491: holder.setSet(new HashSet());
1492: holder.getSet().add(new Referrer(1));
1493: holder.getSet().add(new Referrer(2));
1494: Book book = new Book("Refer collection", "1");
1495: holder.getSet().add(book);
1496: store.save(holder);
1497: // Check
1498: SetHolder dbHolder = (SetHolder) store
1499: .findSingle("find setholder");
1500: assertEquals(3, dbHolder.getSet().size());
1501: dbHolder.getSet().remove(book);
1502: assertEquals(2, dbHolder.getSet().size());
1503: store.save(dbHolder);
1504: dbHolder = (SetHolder) store.findSingle("find setholder");
1505: assertEquals(2, dbHolder.getSet().size());
1506: }
1507:
1508: public void testSetRemoveLongNonexisting() throws Exception {
1509: // Drop table
1510: dropTables("setholder");
1511: // Insert mixed stuff
1512: SetHolder holder = new SetHolder();
1513: holder.setSet(new HashSet());
1514: for (int i = 0; i < 50; i++)
1515: holder.getSet().add(new Referrer(i));
1516: holder.getSet().add(new Book("Refer collection", "1"));
1517: store.save(holder);
1518: // Check
1519: SetHolder dbHolder = (SetHolder) store
1520: .findSingle("find setholder");
1521: assertEquals(51, dbHolder.getSet().size());
1522: Book book = new Book("Noone's Land", "1");
1523: dbHolder.getSet().remove(book);
1524: assertEquals(51, dbHolder.getSet().size());
1525: dbHolder = (SetHolder) store.findSingle("find setholder");
1526: assertEquals(51, dbHolder.getSet().size());
1527: }
1528:
1529: public void testSetRemoveLongExisting() throws Exception {
1530: // Drop table
1531: dropTables("setholder");
1532: // Insert mixed stuff
1533: SetHolder holder = new SetHolder();
1534: holder.setSet(new HashSet());
1535: for (int i = 0; i < 50; i++)
1536: holder.getSet().add(new Referrer(i));
1537: holder.getSet().add(new Book("Refer collection", "1"));
1538: store.save(holder);
1539: // Check
1540: SetHolder dbHolder = (SetHolder) store
1541: .findSingle("find setholder");
1542: assertEquals(51, dbHolder.getSet().size());
1543: Book book = new Book("Noone's Land", "1");
1544: store.save(book);
1545: dbHolder.getSet().remove(book);
1546: assertEquals(51, dbHolder.getSet().size());
1547: dbHolder = (SetHolder) store.findSingle("find setholder");
1548: assertEquals(51, dbHolder.getSet().size());
1549: }
1550:
1551: public void testSetRemoveLongMember() throws Exception {
1552: // Drop table
1553: dropTables("setholder");
1554: // Insert mixed stuff
1555: SetHolder holder = new SetHolder();
1556: holder.setSet(new HashSet());
1557: for (int i = 0; i < 50; i++)
1558: holder.getSet().add(new Referrer(i));
1559: Book book = new Book("Noone's Land", "1");
1560: holder.getSet().add(book);
1561: store.save(holder);
1562: // Check
1563: SetHolder dbHolder = (SetHolder) store
1564: .findSingle("find setholder");
1565: assertEquals(51, dbHolder.getSet().size());
1566: dbHolder.getSet().remove(book);
1567: assertEquals(50, dbHolder.getSet().size());
1568: store.save(dbHolder);
1569: dbHolder = (SetHolder) store.findSingle("find setholder");
1570: assertEquals(50, dbHolder.getSet().size());
1571: }
1572:
1573: public void testSetRemoveLongOutside() throws Exception {
1574: // Drop table
1575: dropTables("setholder");
1576: // Insert mixed stuff
1577: SetHolder holder = new SetHolder();
1578: holder.setSet(new HashSet());
1579: for (int i = 0; i < 50; i++)
1580: holder.getSet().add(new Referrer(i));
1581: Book book = new Book("Noone's Land", "1");
1582: holder.getSet().add(book);
1583: store.save(holder);
1584: // Check
1585: SetHolder dbHolder = (SetHolder) store
1586: .findSingle("find setholder");
1587: assertEquals(51, dbHolder.getSet().size());
1588: store.remove(book);
1589: dbHolder = (SetHolder) store.findSingle("find setholder");
1590: assertEquals(50, dbHolder.getSet().size());
1591: }
1592:
1593: public void testSetIterationRemove() throws Exception {
1594: // Drop table
1595: dropTables("setholder");
1596: // Add empty set
1597: SetHolder holder = new SetHolder();
1598: holder.setSet(new HashSet());
1599: holder.getSet().add(new Referrer(1));
1600: holder.getSet().add(new Referrer(2));
1601: holder.getSet().add(new Book("Refer collection", "1"));
1602: store.save(holder);
1603: // Get and add a nonexisting object too
1604: SetHolder dbHolder = (SetHolder) store
1605: .findSingle("find setholder");
1606: assertEquals(3, dbHolder.getSet().size());
1607: // Iterate
1608: Iterator iterator = dbHolder.getSet().iterator();
1609: while (iterator.hasNext()) {
1610: iterator.next();
1611: iterator.remove();
1612: }
1613: store.save(dbHolder);
1614: // Check
1615: dbHolder = (SetHolder) store.findSingle("find setholder");
1616: assertEquals(0, dbHolder.getSet().size());
1617: }
1618:
1619: public void testSetIterationNormal() throws Exception {
1620: // Drop table
1621: dropTables("setholder");
1622: // Add empty set
1623: SetHolder holder = new SetHolder();
1624: holder.setSet(new HashSet());
1625: holder.getSet().add(new Referrer(1));
1626: holder.getSet().add(new Referrer(2));
1627: holder.getSet().add(new Book("Refer collection", "1"));
1628: store.save(holder);
1629: // Get and add a nonexisting object too
1630: SetHolder dbHolder = (SetHolder) store
1631: .findSingle("find setholder");
1632: // Iterate
1633: assertEquals(3, dbHolder.getSet().size());
1634: Iterator iterator = dbHolder.getSet().iterator();
1635: while (iterator.hasNext())
1636: iterator.next();
1637: }
1638:
1639: public void testSetIterationRemoved() throws Exception {
1640: // Drop table
1641: dropTables("setholder");
1642: // Add empty set
1643: SetHolder holder = new SetHolder();
1644: holder.setSet(new HashSet());
1645: holder.getSet().add(new Referrer(1));
1646: holder.getSet().add(new Referrer(2));
1647: Book book = new Book("Refer collection", "1");
1648: holder.getSet().add(book);
1649: store.save(holder);
1650: // Get and add a nonexisting object too
1651: SetHolder dbHolder = (SetHolder) store
1652: .findSingle("find setholder");
1653: dbHolder.getSet().remove(book);
1654: // Iterate
1655: assertEquals(2, dbHolder.getSet().size());
1656: Iterator iterator = dbHolder.getSet().iterator();
1657: while (iterator.hasNext())
1658: iterator.next();
1659: }
1660:
1661: public void testSetIterationAdded() throws Exception {
1662: // Drop table
1663: dropTables("setholder");
1664: // Add empty set
1665: SetHolder holder = new SetHolder();
1666: holder.setSet(new HashSet());
1667: holder.getSet().add(new Referrer(1));
1668: holder.getSet().add(new Referrer(2));
1669: holder.getSet().add(new Book("Refer collection", "1"));
1670: store.save(holder);
1671: // Get and add a nonexisting object too
1672: SetHolder dbHolder = (SetHolder) store
1673: .findSingle("find setholder");
1674: dbHolder.getSet().add(new Book("Second chance", "2"));
1675: // Iterate
1676: assertEquals(4, dbHolder.getSet().size());
1677: Iterator iterator = dbHolder.getSet().iterator();
1678: while (iterator.hasNext())
1679: iterator.next();
1680: }
1681:
1682: public void testSetIterationAddedLong() throws Exception {
1683: // Drop table
1684: dropTables("setholder");
1685: // Add empty set
1686: SetHolder holder = new SetHolder();
1687: holder.setSet(new HashSet());
1688: for (int i = 0; i < 50; i++)
1689: holder.getSet().add(new Referrer(i));
1690: holder.getSet().add(new Book("Refer collection", "1"));
1691: store.save(holder);
1692: // Get and add a nonexisting object too
1693: SetHolder dbHolder = (SetHolder) store
1694: .findSingle("find setholder");
1695: dbHolder.getSet().add(new Book("Second chance", "2"));
1696: // Iterate
1697: assertEquals(52, dbHolder.getSet().size());
1698: Iterator iterator = dbHolder.getSet().iterator();
1699: while (iterator.hasNext())
1700: iterator.next();
1701: }
1702:
1703: public void testSetPrimitives() throws Exception {
1704: // Drop table
1705: dropTables("setholder");
1706: // Save
1707: SetHolder holder = new SetHolder();
1708: HashSet content = new HashSet();
1709: holder.setSet(content);
1710: content
1711: .add(new Book("I Am Surrounded By Primitives",
1712: "1-1-1-1"));
1713: content.add("Primitive String");
1714: content.add(new Integer(1));
1715: content.add(new Short((short) 2));
1716: content.add(new Byte((byte) 3));
1717: content.add(new Long(4));
1718: content.add(new Float(5.5));
1719: content.add(new Double(6.6));
1720: content.add(new Character('a'));
1721: content.add(new Boolean(true));
1722: content.add(new Date());
1723: store.save(holder);
1724: // Recall
1725: SetHolder result = (SetHolder) store
1726: .findSingle("find setholder");
1727: Set set = result.getSet();
1728: assertEquals(1, getCount(set, Book.class));
1729: assertEquals(1, getCount(set, String.class));
1730: assertEquals(1, getCount(set, Short.class));
1731: assertEquals(1, getCount(set, Byte.class));
1732: assertEquals(1, getCount(set, Long.class));
1733: assertEquals(1, getCount(set, Float.class));
1734: assertEquals(1, getCount(set, Double.class));
1735: assertEquals(1, getCount(set, Character.class));
1736: assertEquals(1, getCount(set, Boolean.class));
1737: assertEquals(1, getCount(set, Date.class));
1738: }
1739:
1740: public void testContainsPrimitiveSmall() throws Exception {
1741: // Drop table
1742: dropTables("setholder");
1743: // Create set
1744: SetHolder holder = new SetHolder();
1745: holder.setSet(new HashSet());
1746: holder.getSet().add(new Referrer(1));
1747: holder.getSet().add(new Referrer(2));
1748: holder.getSet().add(new Referrer(3));
1749: holder.getSet().add(new Referrer(4));
1750: holder.getSet().add(new StringBuffer("String Ni").toString());
1751: store.save(holder);
1752: // Check
1753: SetHolder dbHolder = (SetHolder) store
1754: .findSingle("find setholder");
1755: assertEquals(5, dbHolder.getSet().size());
1756: assertTrue(dbHolder.getSet().contains("String Ni"));
1757: assertFalse(dbHolder.getSet().contains("String No"));
1758: }
1759:
1760: public void testContainsPrimitiveNonsavedSmall() throws Exception {
1761: // Drop table
1762: dropTables("setholder");
1763: // Create set
1764: SetHolder holder = new SetHolder();
1765: holder.setSet(new HashSet());
1766: holder.getSet().add(new Referrer(1));
1767: holder.getSet().add(new Referrer(2));
1768: store.save(holder);
1769: // Check
1770: SetHolder dbHolder = (SetHolder) store
1771: .findSingle("find setholder");
1772: dbHolder.getSet().add(new StringBuffer("String Ni").toString());
1773: assertTrue(dbHolder.getSet().contains("String Ni"));
1774: assertFalse(dbHolder.getSet().contains("String No"));
1775: }
1776:
1777: public void testContainsPrimitiveLarge() throws Exception {
1778: // Drop table
1779: dropTables("setholder");
1780: // Create object
1781: Book book = new Book("Second chance", "2");
1782: store.save(book);
1783: // Create set
1784: SetHolder holder = new SetHolder();
1785: holder.setSet(new HashSet());
1786: for (int i = 0; i < 20; i++)
1787: holder.getSet().add(new Referrer(i));
1788: holder.getSet().add(new StringBuffer("String Ni").toString());
1789: for (int i = 0; i < 20; i++)
1790: holder.getSet().add(new Referrer(i));
1791: store.save(holder);
1792: // Check
1793: SetHolder dbHolder = (SetHolder) store
1794: .findSingle("find setholder");
1795: assertEquals(41, dbHolder.getSet().size());
1796: assertTrue(dbHolder.getSet().contains("String Ni"));
1797: assertFalse(dbHolder.getSet().contains("String No"));
1798: }
1799:
1800: public void testContainsDeletedSmall() throws Exception {
1801: // Drop table
1802: dropTables("setholder");
1803: // Create author
1804: Author author = new Author("Stephenson", "Neal");
1805: store.save(author);
1806: // Create set
1807: SetHolder holder = new SetHolder();
1808: holder.setSet(new HashSet());
1809: holder.getSet().add(author);
1810: store.save(holder);
1811: // Remove author
1812: store.remove(author);
1813: // Check
1814: SetHolder dbHolder = (SetHolder) store
1815: .findSingle("find setholder");
1816: assertEquals(0, dbHolder.getSet().size());
1817: assertFalse(dbHolder.getSet().contains(author));
1818: }
1819:
1820: public void testContainsDeletedLarge() throws Exception {
1821: // Drop table
1822: dropTables("setholder");
1823: // Create author
1824: Author author = new Author("Stephenson", "Neal");
1825: store.save(author);
1826: // Create set
1827: SetHolder holder = new SetHolder();
1828: holder.setSet(new HashSet());
1829: for (int i = 0; i < 40; i++)
1830: holder.getSet().add(new Referrer(i));
1831: holder.getSet().add(author);
1832: store.save(holder);
1833: // Remove author
1834: store.remove(author);
1835: // Check
1836: SetHolder dbHolder = (SetHolder) store
1837: .findSingle("find setholder");
1838: assertEquals(40, dbHolder.getSet().size());
1839: assertFalse(dbHolder.getSet().contains(author));
1840: }
1841: }
|