001: ///////////////////////////////
002: // Makumba, Makumba tag library
003: // Copyright (C) 2000-2003 http://www.makumba.org
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //
019: // -------------
020:
021: package test;
022:
023: import java.io.BufferedInputStream;
024: import java.io.File;
025: import java.io.FileInputStream;
026: import java.io.IOException;
027: import java.io.InputStream;
028: import java.util.Calendar;
029: import java.util.Date;
030: import java.util.Dictionary;
031: import java.util.Enumeration;
032: import java.util.Hashtable;
033: import java.util.Properties;
034: import java.util.Vector;
035:
036: import junit.framework.Test;
037: import junit.framework.TestCase;
038: import junit.framework.TestResult;
039: import junit.framework.TestSuite;
040:
041: import org.makumba.Transaction;
042: import org.makumba.MakumbaSystem;
043: import org.makumba.Pointer;
044: import org.makumba.Text;
045: import org.makumba.commons.NamedResources;
046: import org.makumba.providers.DataDefinitionProvider;
047: import org.makumba.providers.TransactionProvider;
048:
049: /**
050: * Testing table operations
051: *
052: * @author Cristian Bogdan
053: */
054: public class table extends TestCase {
055:
056: static Transaction db;
057:
058: static long epsilon = 2000;
059:
060: public table(String name) {
061: super (name);
062: }
063:
064: public static void main(String[] args) {
065: junit.textui.TestRunner.run(suite());
066: }
067:
068: public static Test suite() {
069: return new TestSuite(table.class);
070: }
071:
072: public void setUp() {
073: db = tp.getConnectionTo(tp
074: .getDataSourceName("test/testDatabase.properties"));
075: }
076:
077: public void tearDown() {
078: db.close();
079: }
080:
081: private TransactionProvider tp = new TransactionProvider();
082:
083: static Pointer ptr, ptr1;
084:
085: static Pointer fptr1, fptr2, fptr;
086:
087: static Date create;
088:
089: static String[] personFields = { "TS_modify", "TS_create",
090: "extraData", "birthdate" };
091:
092: static String[] ptrOneFields = { "something" };
093:
094: static String[] subsetFields = { "description" };
095:
096: static Dictionary pc, pc1;
097:
098: static Date now;
099:
100: static Pointer ptrOne;
101:
102: static Pointer set1, set2;
103:
104: String readPerson = "SELECT p.indiv.name AS name, p.indiv.surname AS surname, p.birthdate AS birthdate, p.TS_modify as TS_modify, p.TS_create as TS_create, p.extraData.something as something, p.extraData as extraData FROM test.Person p WHERE p= $1";
105:
106: String readPerson1 = "SELECT p.indiv.name AS name, p.indiv.surname AS surname, p.birthdate AS birthdate, p.weight as weight, p.TS_modify as TS_modify, p.TS_create as TS_create, p.extraData.something as something, p.extraData as extraData, p.comment as comment, p.picture AS picture FROM test.Person p WHERE p= $1";
107:
108: String readPerson2 = "SELECT p.indiv.name AS name, p.indiv.surname AS surname, p.birthdate AS birthdate, p.weight as weight, p.brother as brother, p.TS_modify as TS_modify, p.TS_create as TS_create, p.extraData.something as something, p.extraData as extraData, p.comment as comment, p.picture AS picture FROM test.Person p WHERE p= $1";
109:
110: String readIntSet = "SELECT i as member FROM test.Person p, p.intSet i WHERE p=$1 ORDER BY i";
111:
112: String readCharSet = "SELECT c as member FROM test.Person p, p.charSet c WHERE p=$1 ORDER BY c";
113:
114: static InputStream getExampleData() {
115: try {
116: return new BufferedInputStream(new FileInputStream(
117: "lib/antlr.jar".replace('/', File.separatorChar)));
118: } catch (IOException e) {
119: e.printStackTrace();
120: return null;
121: }
122: }
123:
124: public void testQueryValidMdds() {
125: Vector v = org.makumba.MakumbaSystem
126: .mddsInDirectory("test/validMdds");
127: DataDefinitionProvider ddp = new DataDefinitionProvider();
128:
129: Vector errors = new Vector();
130: for (int i = 0; i < v.size(); i++) {
131: try {
132: Vector v1 = db.executeQuery(
133: "SELECT t FROM test.validMdds."
134: + (String) v.elementAt(i) + " t", null);
135: Vector fields = ddp.getDataDefinition(
136: "test.validMdds." + (String) v.elementAt(i))
137: .getFieldNames();
138: String what = "";
139: for (Enumeration e = fields.elements(); e
140: .hasMoreElements();) {
141: String fname = (String) e.nextElement();
142: String ftype = ddp
143: .getDataDefinition(
144: "test.validMdds."
145: + (String) v.elementAt(i))
146: .getFieldDefinition(fname).getDataType();
147: // System.out.println(fname+": "+ftype);
148: if (ftype != null && !ftype.equals("null")
149: && !ftype.startsWith("set")) // skip setComplex
150: // fields
151: what = what + (what.length() > 0 ? ", " : "")
152: + "t." + fname;
153: }
154: // System.out.println(what);
155: if (what.length() > 0)
156: v1 = db.executeQuery("SELECT " + what
157: + " FROM test.validMdds."
158: + (String) v.elementAt(i) + " t", null);
159: } catch (Exception e) {
160: errors.add("\n ." + (errors.size() + 1)
161: + ") Error querying valid MDD <"
162: + (String) v.elementAt(i) + ">:\n\t " + e);
163: }
164: }
165: if (errors.size() > 0)
166: fail("\n Tested " + v.size() + " valid MDDs, of which "
167: + errors.size() + " cant be used for DB queries:"
168: + errors.toString());
169: }
170:
171: public void testInsert() {
172: Properties p = new Properties();
173: Calendar c = Calendar.getInstance();
174: c.clear();
175: c.set(1977, 2, 5);
176: Date birth = c.getTime();
177:
178: Text comment = new Text("Itrntinliztin");
179:
180: p.put("birthdate", birth);
181: p.put("comment", comment);
182: p.put("picture", new Text(getExampleData()));
183:
184: p.put("weight", new Double(85.7d));
185:
186: p.put("indiv.name", "john");
187: p.put("indiv.surname", "doe");
188: p.put("extraData.something", "else");
189:
190: Vector setintElem = new Vector();
191: setintElem.addElement(new Integer(1));
192: setintElem.addElement(new Integer(0));
193:
194: Vector setcharElem = new Vector();
195: setcharElem.addElement("f");
196: setcharElem.addElement("e");
197:
198: p.put("intSet", setintElem);
199: p.put("charSet", setcharElem);
200:
201: ptr = db.insert("test.Person", p);
202: assertNotNull(ptr);
203: assertEquals(ptr.getType(), "test.Person");
204:
205: now = new Date();
206:
207: Vector v = db.executeQuery(readPerson1, ptr);
208:
209: assertEquals(1, v.size());
210:
211: pc = (Dictionary) v.elementAt(0);
212:
213: create = (Date) pc.get("TS_create");
214: ptrOne = (Pointer) pc.get("extraData");
215: assertEquals("Name", "john", pc.get("name"));
216: assertEquals("Surname", "doe", pc.get("surname"));
217: assertEquals("Weight(real)", new Double(85.7d), pc
218: .get("weight"));
219: assertEquals("Birthdate", birth, pc.get("birthdate"));
220: assertEquals("Something else", "else", pc.get("something"));
221: assertEquals("Comment text", pc.get("comment"), comment
222: .toString());
223: assertEquals("Picture", pc.get("picture"), new Text(
224: getExampleData()));
225: assertNotNull(ptrOne);
226:
227: v = db.executeQuery(readIntSet, ptr);
228: assertEquals(2, v.size());
229: assertEquals(new Integer(0), ((Dictionary) v.elementAt(0))
230: .get("member"));
231: assertEquals(new Integer(1), ((Dictionary) v.elementAt(1))
232: .get("member"));
233:
234: v = db.executeQuery(readCharSet, ptr);
235: assertEquals(v.size(), 2);
236: assertEquals("e", ((Dictionary) v.elementAt(0)).get("member"));
237: assertEquals("f", ((Dictionary) v.elementAt(1)).get("member"));
238:
239: assertEquals(create, pc.get("TS_modify"));
240: assertTrue(now.getTime() - create.getTime() < 3 * epsilon);
241: }
242:
243: public void testForeignKeys() {
244: assertTrue(org.makumba.db.makumba.sql.Database
245: .supportsForeignKeys());
246:
247: // try to delete brother = that ID
248: // try to delete the other brother
249:
250: // insert the first person
251: Properties p = new Properties();
252:
253: Text comment = new Text("Hello world!!!!");
254:
255: p.put("comment", comment);
256:
257: p.put("indiv.name", "john");
258: p.put("indiv.surname", "doe_1");
259: p.put("extraData.something", "else");
260:
261: fptr = db.insert("test.Person", p);
262:
263: // check if he got inserted
264: assertNotNull(fptr);
265: assertEquals(fptr.getType(), "test.Person");
266:
267: Vector v = db.executeQuery(readPerson2, fptr);
268: //System.out.println(v.size());
269: assertEquals(1, v.size());
270:
271: // insert the second person (brother)
272: p = new Properties();
273:
274: comment = new Text("Itrntinliztin");
275:
276: p.put("comment", comment);
277: p.put("brother", fptr);
278: p.put("indiv.name", "john");
279: p.put("indiv.surname", "doe_2");
280: p.put("extraData.something", "else");
281:
282: fptr1 = db.insert("test.Person", p);
283: assertNotNull(fptr1);
284: assertEquals(fptr.getType(), "test.Person");
285:
286: // check if it links to the first one correctly
287: v = db.executeQuery(readPerson2, fptr1);
288:
289: assertEquals(1, v.size());
290:
291: pc = (Dictionary) v.elementAt(0);
292:
293: fptr2 = (Pointer) pc.get("brother");
294: assertNotNull(fptr2);
295: assertEquals("Brother", fptr2, fptr);
296:
297: // try to delete the first guy (who was set as a brother. should fail)
298: try {
299: db.delete(fptr);
300: // we could delete him... the foreign keys don't work
301: assertTrue(false);
302: } catch (org.makumba.DBError e) {
303: }
304:
305: // try to delete the second guy
306: db.delete(fptr1);
307:
308: // delete the first guy again, this time he shouldn't be linked to from anywhere
309: db.delete(fptr);
310:
311: }
312:
313: static String subsetQuery = "SELECT a.description, a, a.description, a.sth.aaa FROM test.Person p, p.address a WHERE p=$1 ORDER BY a.description";
314:
315: public void testSetInsert() {
316: Dictionary p = new Hashtable();
317: p.put("description", "home");
318: p.put("sth.aaa", "bbb");
319:
320: set1 = db.insert(ptr, "address", p);
321:
322: assertNotNull(set1);
323: Vector v = db.executeQuery(subsetQuery, ptr);
324: assertEquals(1, v.size());
325: assertEquals("home", ((Dictionary) v.elementAt(0)).get("col1"));
326: assertEquals(set1, ((Dictionary) v.elementAt(0)).get("col2"));
327: assertEquals("home", ((Dictionary) v.elementAt(0)).get("col3"));
328: assertEquals("bbb", ((Dictionary) v.elementAt(0)).get("col4"));
329:
330: p.put("description", "away");
331:
332: set2 = db.insert(ptr, "address", p);
333: assertNotNull(set2);
334: assertEquals("away", db.read(set2, subsetFields).get(
335: "description"));
336: v = db.executeQuery(subsetQuery, ptr);
337: assertEquals(2, v.size());
338: assertEquals("away", ((Dictionary) v.elementAt(0)).get("col1"));
339: assertEquals(set2, ((Dictionary) v.elementAt(0)).get("col2"));
340: assertEquals("home", ((Dictionary) v.elementAt(1)).get("col1"));
341: assertEquals(set1, ((Dictionary) v.elementAt(1)).get("col2"));
342: }
343:
344: public void testSetMemberUpdate() {
345: Dictionary p = new Hashtable();
346: p.put("description", "somewhere");
347:
348: db.update(set2, p);
349:
350: Vector v = db.executeQuery(subsetQuery, ptr);
351:
352: assertEquals("somewhere", db.read(set2, subsetFields).get(
353: "description"));
354: v = db.executeQuery(subsetQuery, ptr);
355: assertEquals(v.size(), 2);
356: assertEquals("home", ((Dictionary) v.elementAt(0)).get("col1"));
357: assertEquals(set1, ((Dictionary) v.elementAt(0)).get("col2"));
358: assertEquals("somewhere", ((Dictionary) v.elementAt(1))
359: .get("col1"));
360: assertEquals(set2, ((Dictionary) v.elementAt(1)).get("col2"));
361: }
362:
363: public void testSetMemberDelete() {
364: db.delete(set1);
365: assertNull(db.read(set1, subsetFields));
366: Vector v = db.executeQuery(subsetQuery, ptr);
367: assertEquals(1, v.size());
368: assertEquals("somewhere", ((Dictionary) v.elementAt(0))
369: .get("col1"));
370: assertEquals(set2, ((Dictionary) v.elementAt(0)).get("col2"));
371:
372: // we put it back
373: Dictionary p = new Hashtable();
374: p.put("description", "home");
375:
376: set1 = db.insert(ptr, "address", p);
377: }
378:
379: public void testSubrecordUpdate() {
380: Dictionary p = new Hashtable();
381: p.put("something", "else2");
382:
383: db.update(ptrOne, p);
384:
385: Dictionary d = db.read(ptr, personFields);
386: assertNotNull(d);
387: assertEquals(ptrOne, d.get("extraData"));
388:
389: d = db.read(ptrOne, ptrOneFields);
390: assertNotNull(d);
391: assertEquals("else2", d.get("something"));
392: }
393:
394: static Object[][] languageData = { { "English", "en" },
395: { "French", "fr" }, { "German", "de" },
396: { "Italian", "it" }, { "Spanish", "sp" } };
397:
398: static String[] toInsert = { "German", "Italian" };
399:
400: static String langQuery = "SELECT l FROM test.Language l WHERE l.name=$1";
401:
402: static String speaksQuery = "SELECT l as k, l.name as name FROM test.Person p, p.speaks l WHERE p=$1";
403:
404: static String checkSpeaksQuery = "SELECT l, l.Language FROM test.Person.speaks l WHERE l.Person=$1";
405:
406: void workWithSet(String[] t) {
407: Vector v = new Vector();
408: for (int i = 0; i < t.length; i++)
409: v.addElement(((Dictionary) (db
410: .executeQuery(langQuery, t[i]).elementAt(0)))
411: .get("col1"));
412:
413: Hashtable dt = new Hashtable();
414: dt.put("speaks", v);
415: db.update(ptr, dt);
416:
417: Vector result = db.executeQuery(speaksQuery, ptr);
418: Vector result1 = db.executeQuery(checkSpeaksQuery, ptr);
419:
420: assertEquals(t.length, result.size());
421: assertEquals(t.length, result1.size());
422:
423: for (int i = 0; i < t.length; i++) {
424: for (int j = 0; j < result.size(); j++) {
425: Dictionary d = (Dictionary) result.elementAt(j);
426: if (d.get("name").equals(t[i])) {
427: for (int k = 0; j < result1.size(); k++)
428: if (((Dictionary) result1.elementAt(k)).get(
429: "col2").equals(d.get("k"))) {
430: result1.removeElementAt(k);
431: break;
432: }
433: result.removeElementAt(j);
434: break;
435: }
436: }
437: }
438: assertEquals(0, result.size());
439: assertEquals(0, result1.size());
440: }
441:
442: public void testSetUpdate() {
443: Dictionary p = new Hashtable();
444: if (db.executeQuery("SELECT l FROM test.Language l", null)
445: .size() == 0)
446: for (int i = 0; i < languageData.length; i++) {
447: p.put("name", languageData[i][0]);
448: p.put("isoCode", languageData[i][1]);
449: db.insert("test.Language", p);
450: }
451: p = new Hashtable();
452:
453: workWithSet(toInsert);
454: }
455:
456: static String[] toInsert2 = { "English", "Italian", "French" };
457:
458: public void testSetUpdate2() {
459: workWithSet(toInsert2);
460: }
461:
462: static String[] toInsert3 = { "English", "German", "French" };
463:
464: public void testSetDelete() {
465: Dictionary p = new Hashtable();
466:
467: Vector v = new Vector();
468:
469: Hashtable dt = new Hashtable();
470: dt.put("speaks", new Vector());
471:
472: db.update(ptr, dt);
473: Vector result = db.executeQuery(speaksQuery, ptr);
474: assertEquals(0, result.size());
475:
476: assertEquals(
477: 0,
478: db
479: .executeQuery(
480: "SELECT l FROM test.Person.speaks l WHERE l.Person=$1",
481: ptr).size());
482:
483: workWithSet(toInsert3);
484: db.delete("test.Language l", "1=1", null); //delete garbage
485: }
486:
487: public void testPtrOneDelete() {
488: db.delete(ptrOne);
489:
490: Dictionary d = db.read(ptr, personFields);
491: assertNotNull(d);
492: assertNull(d.get("extraData"));
493:
494: assertNull(db.read(ptrOne, ptrOneFields));
495: }
496:
497: public void testPtrOneReInsert() {
498: Dictionary p = new Hashtable();
499: p.put("extraData.something", "else2");
500: db.update(ptr, p);
501: Dictionary d = db.read(ptr, personFields);
502: ptrOne = (Pointer) d.get("extraData");
503: assertNotNull(ptrOne);
504: Dictionary read;
505: assertNotNull(read = db.read(ptrOne, ptrOneFields));
506: assertEquals("else2", read.get("something"));
507: }
508:
509: public void testUpdate() {
510: Properties pmod = new Properties();
511: String val = "A completely new guy";
512: pmod.put("indiv.name", val);
513:
514: Vector setintElem = new Vector();
515: setintElem.addElement(new Integer(2));
516:
517: Vector setcharElem = new Vector();
518: setcharElem.addElement("d");
519:
520: pmod.put("intSet", setintElem);
521: pmod.put("charSet", setcharElem);
522:
523: db.update(ptr, pmod);
524:
525: now = new Date();
526: Vector v = db.executeQuery(readPerson, ptr);
527: assertEquals(1, v.size());
528:
529: Dictionary modc = (Dictionary) v.elementAt(0);
530:
531: assertNotNull(modc);
532: create = (Date) modc.get("TS_create");
533: assertEquals(val, modc.get("name"));
534: assertEquals("doe", modc.get("surname"));
535: assertTrue(now.getTime()
536: - ((Date) modc.get("TS_modify")).getTime() < epsilon);
537: assertNotNull(db.read(ptrOne, ptrOneFields));
538:
539: v = db.executeQuery(readIntSet, ptr);
540: assertEquals(1, v.size());
541: assertEquals(new Integer(2), ((Dictionary) v.elementAt(0))
542: .get("member"));
543:
544: v = db.executeQuery(readCharSet, ptr);
545: assertEquals(1, v.size());
546: assertEquals("d", ((Dictionary) v.elementAt(0)).get("member"));
547: }
548:
549: public void testDelete() {
550: db.delete(ptr);
551:
552: assertNull(db.read(ptr, personFields));
553: assertNull(db.read(ptrOne, ptrOneFields));
554: assertEquals(0, db.executeQuery(subsetQuery, ptr).size());
555: assertNull(db.read(set1, subsetFields));
556: assertNull(db.read(set2, subsetFields));
557: assertEquals(0, db.executeQuery(speaksQuery, ptr).size());
558: assertEquals(0, db.executeQuery(readIntSet, ptr).size());
559: assertEquals(0, db.executeQuery(readCharSet, ptr).size());
560: assertEquals(
561: 0,
562: db
563: .executeQuery(
564: "SELECT l FROM test.Person.speaks l WHERE l.Person=$1",
565: ptr).size());
566: assertEquals(
567: 0,
568: db
569: .executeQuery(
570: "SELECT l FROM test.Person.intSet l WHERE l.Person=$1",
571: ptr).size());
572: assertEquals(
573: 0,
574: db
575: .executeQuery(
576: "SELECT l FROM test.Person.charSet l WHERE l.Person=$1",
577: ptr).size());
578:
579: // delete all entries, bug 673:
580: db.delete("test.validMdds.CharWithLength name",
581: "name.name='bla'", null);
582: db.delete("test.validMdds.CharWithLength t", "5=5", null);
583: db.delete("test.validMdds.CharWithLength t",
584: "t.name LIKE \"www\"", null);
585: db.delete("test.validMdds.CharWithLength bla", "'x'=bla.name",
586: null);
587: }
588:
589: public void testRealAggregation() {
590: db.delete("test.validMdds.Real r", "r=r", null); // delete all
591: // entries first
592: Dictionary p = new Hashtable();
593: p.put("r", new Double(.5d));
594: db.insert("test.validMdds.Real", p);
595: p.put("r", new Double(.2d));
596: db.insert("test.validMdds.Real", p);
597: p.put("r", new Double(1.8d));
598: db.insert("test.validMdds.Real", p);
599: p.put("r", new Double(.0008d));
600: db.insert("test.validMdds.Real", p);
601: Vector v = db
602: .executeQuery(
603: "SELECT avg(r.r) as av, sum(r.r) as su FROM test.validMdds.Real r",
604: null);
605: assertEquals("Real aggregation", 1, v.size());
606: assertEquals("Avg(reals)", new Double(0.6252d), ((Dictionary) v
607: .firstElement()).get("av"));
608: assertEquals("Sum(reals)", new Double(2.5008d), ((Dictionary) v
609: .firstElement()).get("su"));
610:
611: Object[] args = { new Double(0.2), new Double(1.8) };
612: v = db
613: .executeQuery(
614: "SELECT r FROM test.validMdds.Real r WHERE r.r>$1 AND r.r<=$2",
615: args);
616: assertEquals("Real comparisment", 2, v.size());
617:
618: // should we allow this? FIXME!
619: Object[] args2 = { new Integer(-1), new Double(1.5) };
620: v = db
621: .executeQuery(
622: "SELECT count(r) as cnt FROM test.validMdds.Real r WHERE r.r>$1 AND r.r<=$2",
623: args2);
624: assertEquals("Real comparison with integer parameter",
625: new Integer(3), ((Dictionary) v.firstElement())
626: .get("cnt"));
627:
628: Object[] args3 = { new Double(1.5) };
629: v = db
630: .executeQuery(
631: "SELECT count(r) as cnt FROM test.validMdds.Real r WHERE r.r>-1 AND r.r<=$1",
632: args3);
633: assertEquals("Real comparison with hardcoded integer",
634: new Integer(3), ((Dictionary) v.firstElement())
635: .get("cnt"));
636:
637: db.delete("test.validMdds.Real r", "r=r", null); // delete garbage
638: }
639:
640: public void testIntAggregation() {
641: db.delete("test.validMdds.Int iii", "5=5", null); // delete all
642: // entries first
643: Dictionary p = new Hashtable();
644: p.put("i", new Integer(0));
645: db.insert("test.validMdds.Int", p);
646: p.put("i", new Integer(1));
647: db.insert("test.validMdds.Int", p);
648: p.put("i", new Integer(2));
649: db.insert("test.validMdds.Int", p);
650: p.put("i", new Integer(3));
651: db.insert("test.validMdds.Int", p);
652: p.put("i", new Integer(4));
653: db.insert("test.validMdds.Int", p);
654: p.put("i", new Integer(5));
655: db.insert("test.validMdds.Int", p);
656: Vector v = db
657: .executeQuery(
658: "SELECT avg(i.i) as av, sum(i.i) as su FROM test.validMdds.Int i",
659: null);
660: assertEquals("Int aggregation", 1, v.size());
661: assertEquals("Avg(ints)", new Double(2.5d), ((Dictionary) v
662: .firstElement()).get("av"));
663: assertEquals("Sum(ints)", new Integer(15), ((Dictionary) v
664: .firstElement()).get("su"));
665:
666: db.delete("test.validMdds.Int iii", "5=5", null); // delete garbage
667: }
668:
669: public void testCopy() {
670: Properties p = new Properties();
671: p.put("birthdate", new java.util.GregorianCalendar(1977, 7, 7)
672: .getTime());
673: p.put("indiv.name", "john");
674: p.put("indiv.surname", "Copy");
675: p.put("extraData.something", "else");
676:
677: Calendar c = Calendar.getInstance();
678: c.clear();
679: c.set(1976, 2, 9);
680:
681: Date cr = c.getTime();
682: p.put("TS_create", cr);
683:
684: c.clear();
685: c.set(1976, 2, 10);
686:
687: Date mod = c.getTime();
688: p.put("TS_modify", mod);
689:
690: ptr1 = db.insert("test.Person", p);
691: assertNotNull(ptr1);
692:
693: now = new Date();
694: Vector v = db.executeQuery(readPerson, ptr1);
695: assertEquals(1, v.size());
696:
697: pc1 = (Dictionary) v.elementAt(0);
698: assertNotNull(pc1);
699:
700: assertEquals("john", pc1.get("name"));
701: assertEquals("Copy", pc1.get("surname"));
702: assertEquals(cr, new Date(((Date) pc1.get("TS_create"))
703: .getTime()));
704: assertEquals(mod, new Date(((Date) pc1.get("TS_modify"))
705: .getTime()));
706: db.delete(ptr1);
707: db.delete("test.Individual i", "1=1", null);
708: }
709:
710: public void run(TestResult r) {
711: try {
712: super .run(r);
713:
714: } catch (Throwable t) {
715: t.printStackTrace();
716: }
717:
718: /* very shitty solution, more JUnit should be studied for a better one...
719: * we want to find out whether we just finished the last test
720: * if yes, we do cleanup
721: */
722: if (toString().equals("testCopy(test.table)")) {
723: String nm = tp
724: .getDataSourceName("test/testDatabase.properties");
725:
726: System.out.println("\nworked with: "
727: + MakumbaSystem.getDatabaseProperty(nm,
728: "sql_engine.name")
729: + " version: "
730: + MakumbaSystem.getDatabaseProperty(nm,
731: "sql_engine.version")
732: + "\njdbc driver: "
733: + MakumbaSystem.getDatabaseProperty(nm,
734: "jdbc_driver.name")
735: + " version: "
736: + MakumbaSystem.getDatabaseProperty(nm,
737: "jdbc_driver.version")
738: + "\njdbc connections allocated: "
739: + MakumbaSystem.getDatabaseProperty(nm,
740: "jdbc_connections") + "\ncaches: "
741: + org.makumba.commons.NamedResources.getCacheInfo()
742:
743: );
744: java.util.logging.Logger.getLogger(
745: "org.makumba." + "system").info(
746: "destroying makumba caches");
747: NamedResources.cleanup();
748: }
749: }
750: }
|