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