1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Calendar;
29 import java.util.GregorianCalendar;
30 import java.util.HashSet;
31 import java.util.Iterator;
32 import java.util.List;
33 import java.util.Set;
34
35 import de.bea.domingo.util.GregorianDate;
36 import de.bea.domingo.util.GregorianTime;
37
38 /***
39 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
40 */
41 public abstract class BaseDocumentProxyTest extends BaseProxyTest {
42
43 private String itemName;
44 private Calendar correctNow;
45
46 /***
47 * @param name the name of the test
48 */
49 protected BaseDocumentProxyTest(String name) {
50 super(name);
51 }
52
53 /***
54 * Tests the getAttachment method.
55 */
56 public final void testGetAttachment() {
57 System.out.println("-> testGetAttachment");
58 DBaseDocument doc = createDBaseDocument();
59 DRichTextItem rtItem = doc.createRichTextItem(itemName);
60
61 String pre = System.currentTimeMillis() + "testGetAttachment";
62 String suf = ".txt";
63 File file = null;
64 try {
65 file = File.createTempFile(pre, suf);
66 } catch (IOException e) {
67 assertTrue("Could not create test attachment file.", false);
68 }
69
70 String key = file.getAbsolutePath();
71
72 rtItem.embedAttachment(key);
73
74 doc.save();
75
76 DEmbeddedObject embObj = doc.getAttachment(file.getName());
77
78 assertNotNull("The embedded object should not be null.", embObj);
79 assertEquals(
80 "The name of the embedded object should be the same as the name at embedding.",
81 file.getName(),
82 embObj.getName());
83
84 file.delete();
85 doc.remove(true);
86 }
87
88 /***
89 * Tests testGetEmbeddedObjects().
90 */
91 public final void testGetEmbeddedObjects() {
92 System.out.println("-> testGetEmbeddedObjects");
93 DBaseDocument doc = createDBaseDocument();
94
95
96
97 String pre1 = System.currentTimeMillis() + "testGetEmbeddedObjects1";
98 String pre2 = System.currentTimeMillis() + "testGetEmbeddedObjects2";
99 String suf = ".txt";
100 File file1 = null;
101 File file2 = null;
102 try {
103 file1 = File.createTempFile(pre1, suf);
104 file2 = File.createTempFile(pre2, suf);
105 } catch (IOException e) {
106 assertTrue("Could not create test attachment file.", false);
107 }
108
109 file1.delete();
110 file2.delete();
111 doc.remove(true);
112 }
113
114 /***
115 * Tests the method to create a RichTextItem.
116 */
117 public final void testCreateRichTextItem() {
118 System.out.println("-> testCreateRichTextItem");
119 DBaseDocument doc = createDBaseDocument();
120
121 DRichTextItem rtItem = doc.createRichTextItem(itemName);
122 assertNotNull("The created RichTextItem should exist.", rtItem);
123 assertEquals("The RichTextItem's name should match.", rtItem.getName(), rtItem.getName());
124 }
125
126 /***
127 * Tests the getAuthors method of a document.
128 */
129 public final void testGetAuthors() {
130 System.out.println("-> testGetAuthors");
131 DBaseDocument doc = createDBaseDocument();
132 List authors = doc.getAuthors();
133 assertNotNull("Document should have a authors list.", authors);
134 if (doc instanceof DDocument) {
135 assertTrue("The authors list should have a empty authors list.", authors.size() == 0);
136 } else {
137 assertTrue("The authors list should have a one-entry-authors list.", authors.size() == 1);
138 assertEquals("The authors name should be the session's user name.", getSession().getUserName(), authors.get(0));
139 }
140 doc.save();
141 authors = doc.getAuthors();
142 assertTrue("The authors list should have at least one entry.", authors.size() > 0);
143 assertEquals("The authors name should be the user name of the session.", getSession().getUserName(), authors.get(0));
144 }
145
146 /***
147 * Tests doc.getLastAccessed().
148 */
149 public final void testGetLastAccessed() {
150 System.out.println("-> testGetLastAccessed");
151 DBaseDocument doc = createDBaseDocument();
152 assertNotNull("Document now should have a LastAccessed field (also before save).", doc.getLastAccessed());
153 doc.save();
154 assertNotNull("Document now should have a LastAccessed field.", doc.getLastAccessed());
155 }
156
157 /***
158 * Tests doc.testGetLastModified().
159 */
160 public final void testGetLastModified() {
161 System.out.println("-> testGetLastModified");
162 DBaseDocument doc = createDBaseDocument();
163 if (doc instanceof DDocument) {
164 assertNull("Document should have no LastModified field, because it is new.", doc.getLastModified());
165 } else {
166 assertNotNull("Document now should have a LastModified field (also before save).", doc.getLastModified());
167 }
168 doc.save();
169 assertNotNull("Document now should have a LastModified field.", doc.getLastModified());
170 }
171
172 /***
173 * Tests the creation field getter.
174 */
175 public final void testGetCreated() {
176 System.out.println("-> testGetCreated");
177 DBaseDocument doc = createDBaseDocument();
178 assertNotNull("Document now should have a created field (also before save).", doc.getCreated());
179 doc.save();
180 assertNotNull("Document now should have a created field.", doc.getCreated());
181 }
182
183 /***
184 * Tests appending item values for all types.
185 */
186 public final void testAppendItemValue() {
187 System.out.println("-> testAppendItemValue");
188 String appendItemName = "" + System.currentTimeMillis();
189 DBaseDocument doc = createDBaseDocument();
190 DItem nullItem = (DItem) doc.getFirstItem(appendItemName);
191 assertTrue("Document had an item named '" + appendItemName + "' but should NOT have one.", nullItem == null);
192
193 {
194 doc.appendItemValue(appendItemName);
195 DItem emptyItem = (DItem) doc.getFirstItem(appendItemName);
196 if (emptyItem.getValues().size() == 0) {
197 assertTrue("Item should be empty (item with an empty string), but item IS empty.", false);
198 } else {
199 boolean emptyOK = "".equals((String) emptyItem.getValues().iterator().next());
200 assertTrue("Document should have empty item, but recipient was:" + emptyItem.getValues(), emptyOK);
201 }
202 removeItem(doc, appendItemName);
203 }
204
205 {
206 doc.appendItemValue(appendItemName, 4.4);
207 DItem doubleItem = (DItem) doc.getFirstItem(appendItemName);
208 Object o = doubleItem.getValues().iterator().next();
209 boolean doubleOK = (o instanceof Double) ? ((Double) o).doubleValue() == 4.4 : false;
210 assertTrue("Received object should be a Double with a value of 4.4, but is not: " + o, doubleOK);
211 removeItem(doc, appendItemName);
212 }
213
214 {
215 String value1 = "value1";
216 String value2 = "value2";
217 doc.appendItemValue(appendItemName, value1);
218 doc.appendItemValue(appendItemName, value2);
219 DItem item = (DItem) doc.getFirstItem(appendItemName);
220 List values = item.getValues();
221 assertTrue("Item should have only one value but has: " + values,
222 values.size() == 1 && (value1.equals(values.get(0)) || value2.equals(values.get(0))));
223
224 doc.removeItem(appendItemName);
225 removeItem(doc, appendItemName);
226 }
227
228 {
229 doc.appendItemValue(appendItemName, 3);
230 DItem intItem = (DItem) doc.getFirstItem(appendItemName);
231 Object o = intItem.getValues().iterator().next();
232 boolean intOK = (o instanceof Double) ? ((Double) o).intValue() == 3 : false;
233 assertTrue("Received object should be Integer 3, but is: " + o.getClass() + ": " + o, intOK);
234 removeItem(doc, appendItemName);
235 }
236
237 {
238 Integer two = new Integer(2);
239 Integer five = new Integer(5);
240 List manyInts = new ArrayList();
241 manyInts.add(two);
242 manyInts.add(five);
243 doc.appendItemValue(appendItemName, manyInts);
244 DItem intListItem = (DItem) doc.getFirstItem(appendItemName);
245 List list = intListItem.getValues();
246 boolean intListOK =
247 list.size() == 2 ? (((Double) list.get(0)).intValue() == 2
248 && ((Double) list.get(1)).intValue() == 5) : false;
249 assertTrue("object should be Integer list (" + two + ", " + five + "), but is: " + list, intListOK);
250 removeItem(doc, appendItemName);
251 }
252
253 {
254 List dateList = new ArrayList();
255 dateList.add(correctNow.clone());
256 dateList.add(correctNow.clone());
257 doc.appendItemValue(appendItemName, dateList);
258 DItem dateListItem = (DItem) doc.getFirstItem(appendItemName);
259 List list = dateListItem.getValues();
260 assertEquals("Appended and retrieved list of dates do not equal.", dateList, list);
261 removeItem(doc, appendItemName);
262 }
263
264 {
265 Calendar now = correctNow;
266 doc.appendItemValue(appendItemName, now);
267 DItem stringItem = (DItem) doc.getFirstItem(appendItemName);
268 Object o = stringItem.getValues().iterator().next();
269 assertEquals("Received object should be a correct date.", now, o);
270 removeItem(doc, appendItemName);
271 }
272
273 {
274 String someText = "some text";
275 doc.appendItemValue(appendItemName, someText);
276 DItem stringItem = (DItem) doc.getFirstItem(appendItemName);
277 Object o = stringItem.getValues().iterator().next();
278 boolean stringOK = someText.equals(o);
279 assertTrue("Received object should be String with value '" + someText + "', but is not: " + o, stringOK);
280 removeItem(doc, appendItemName);
281 }
282 doc.remove(true);
283 }
284
285 /***
286 * Tests is a document has at least one item.
287 *
288 */
289 public final void testHasItem() {
290 System.out.println("-> testHasItem");
291
292 DBaseDocument doc = createDBaseDocument();
293 assertTrue("Doc should NOT have a item named " + itemName, !doc.hasItem(itemName));
294
295 doc.appendItemValue(itemName);
296 assertTrue("Doc should have a item named " + itemName, doc.hasItem(itemName));
297
298 doc.remove(true);
299 }
300
301 /***
302 * Tests if getItems works properly.
303 */
304 public final void testGetItems() {
305 System.out.println("-> testGetItems");
306
307 DBaseDocument doc = createDBaseDocument();
308 Set itemCache = new HashSet();
309 for (Iterator it = doc.getItems(); it.hasNext();) {
310 DBaseItem dItem = (DBaseItem) it.next();
311 itemCache.add(dItem);
312 }
313
314 while (doc.hasItem(itemName)) {
315 doc.removeItem(itemName);
316 }
317
318 String someValue = "some value that's value is really unimportant";
319 doc.appendItemValue(itemName, someValue);
320
321 for (Iterator it = doc.getItems(); it.hasNext();) {
322 DItem dItem = (DItem) it.next();
323 if (!itemCache.contains(dItem)) {
324 List values = dItem.getValues();
325 if (values != null) {
326 assertEquals(
327 "The only value that was added should be someValue. (" + getClass().getName() + ")",
328 someValue,
329 values.get(values.size() - 1));
330 } else {
331 assertTrue("Item should have one value, but item list is NULL.", false);
332 }
333 }
334 }
335 }
336
337 /***
338 * Tests is getFirstItem supplies a document.
339 *
340 */
341 public final void testGetFirstItem() {
342 System.out.println("-> testGetFirstItem");
343
344 DBaseDocument doc = createDBaseDocument();
345
346 Set itemCache = new HashSet();
347 for (Iterator it = doc.getItems(); it.hasNext();) {
348 DBaseItem dItem = (DBaseItem) it.next();
349 itemCache.add(dItem);
350 }
351
352 while (doc.hasItem(itemName)) {
353 doc.removeItem(itemName);
354 }
355
356 String someValue = "some value that's value is really unimportant";
357 DItem someItem = (DItem) doc.appendItemValue(itemName, someValue);
358
359 DItem item = (DItem) doc.getFirstItem(itemName);
360 assertEquals("Both objects should be equal.", someItem.getValueString(), item.getValueString());
361 }
362
363 /***
364 * Tests removing of Documents.
365 *
366 */
367 public final void testRemove() {
368 System.out.println("-> BaseDocumentProxy.testRemove");
369 {
370 DBaseDocument doc = createDBaseDocument();
371 assertTrue("Document should be removable, because it does already exist in DB.", doc.remove(true));
372
373 assertTrue("Document should NOT be saved, because it does no longer exist in DB.", !doc.save());
374
375 }
376 {
377 DBaseDocument doc = createDBaseDocument();
378 doc.replaceItemValue("Test", "Test");
379 assertTrue("Document should have been saved. (" + getClass().getName() + ")", doc.save());
380 assertTrue("Document should be removable and be removed.", doc.remove(true));
381
382 assertTrue("Document should NOT have been saved, because it was previously removed.", !doc.save());
383
384 assertTrue("Document should again not be removable, because it does no longer exist.", !doc.remove(true));
385
386 }
387 }
388
389 /***
390 * Tests the method getItemValueString for all previously inserted types.
391 *
392 */
393 public final void testGetItemValueString() {
394 System.out.println("-> testGetItemValueString");
395 {
396
397 DBaseDocument doc = createDBaseDocument();
398 String value = doc.getItemValueString(itemName);
399 assertEquals("Value of non existent item should be empty string, but was '" + value + "'", "", value);
400 doc.remove(true);
401 }
402
403 {
404
405 DBaseDocument doc = createDBaseDocument();
406 doc.appendItemValue(itemName);
407 String value = doc.getItemValueString(itemName);
408 assertEquals("Received Text should be '', but was '" + value + "'", "", value);
409 doc.remove(true);
410 }
411
412 {
413
414 DBaseDocument doc = createDBaseDocument();
415 String itemValue = "some_item_value";
416 doc.appendItemValue(itemName, itemValue);
417 String value = doc.getItemValueString(itemName);
418 assertEquals("Received Text should be '" + itemValue + "', but was '" + value + "'", itemValue, value);
419 doc.remove(true);
420 }
421
422 {
423
424 DBaseDocument doc = createDBaseDocument();
425 int intValue = 2;
426 doc.appendItemValue(itemName, intValue);
427 String value = doc.getItemValueString(itemName);
428 assertTrue("Received Text should be '', but was '" + value + "'", "".equals(value));
429 doc.remove(true);
430 }
431
432 {
433
434 DBaseDocument doc = createDBaseDocument();
435 double doubleValue = 2.6;
436 doc.appendItemValue(itemName, doubleValue);
437 String value = doc.getItemValueString(itemName);
438 assertTrue("Received Text should be '', but was '" + value + "'", "".equals(value));
439 doc.remove(true);
440 }
441
442 {
443
444 DBaseDocument doc = createDBaseDocument();
445 Calendar now = correctNow;
446 doc.appendItemValue(itemName, now);
447 String value = doc.getItemValueString(itemName);
448 assertEquals("Received Text should be '', but was '" + value + "'", "", value);
449 doc.remove(true);
450 }
451 }
452
453 /***
454 * Tests the method getItemValueInteger for all previously inserted types.
455 */
456 public final void testGetItemValueInteger() {
457 System.out.println("-> testGetItemValueInteger");
458
459 {
460 {
461
462 DBaseDocument doc = createDBaseDocument();
463 Integer emptyValue = doc.getItemValueInteger(itemName);
464 assertNull("Value should be null, but returns: " + emptyValue, emptyValue);
465 doc.remove(true);
466 }
467
468 {
469
470 DBaseDocument doc = createDBaseDocument();
471 doc.appendItemValue(itemName);
472 Integer value = doc.getItemValueInteger(itemName);
473 assertNull("Received Text should be 0, but was '" + value + "'", value);
474 doc.remove(true);
475 }
476
477 {
478
479 DBaseDocument doc = createDBaseDocument();
480 String stringValue = "someValue";
481 doc.appendItemValue(itemName, stringValue);
482 Integer intResult = doc.getItemValueInteger(itemName);
483 assertNull("Value should be null, but is " + intResult, intResult);
484 doc.remove(true);
485 }
486
487 {
488
489 DBaseDocument doc = createDBaseDocument();
490 int itemValue = 2;
491 doc.appendItemValue(itemName, itemValue);
492 Integer value = doc.getItemValueInteger(itemName);
493 assertEquals("value should be " + itemValue + ", but was " + value, itemValue, value.intValue());
494 doc.remove(true);
495 }
496
497 {
498
499 DBaseDocument doc = createDBaseDocument();
500 double doubleValue = 3.6;
501 doc.appendItemValue(itemName, doubleValue);
502 int intResult = doc.getItemValueInteger(itemName).intValue();
503 assertTrue("Value should be 4, but is " + intResult, intResult == 4);
504 doc.remove(true);
505 }
506
507 {
508
509 DBaseDocument doc = createDBaseDocument();
510 Calendar now = correctNow;
511 doc.appendItemValue(itemName, now);
512 Integer res = doc.getItemValueInteger(itemName);
513 assertNull("Value should be null, but is " + res, res);
514 doc.remove(true);
515 }
516 }
517 }
518
519 /***
520 * Tests the method getItemValueDouble for all previously inserted types.
521 */
522 public final void testGetItemValueDouble() {
523 System.out.println("-> testGetItemValueDouble");
524
525 {
526 {
527
528 DBaseDocument doc = createDBaseDocument();
529 Double emptyValue = doc.getItemValueDouble(itemName);
530 assertNull("Value from a non existing field should return 0.0, but returns: " + emptyValue, emptyValue);
531 doc.remove(true);
532 }
533
534 {
535
536 DBaseDocument doc = createDBaseDocument();
537 doc.appendItemValue(itemName);
538 Double value = doc.getItemValueDouble(itemName);
539 assertNull("Received Double should be 0.0, but was '" + value + "'", value);
540 doc.remove(true);
541 }
542
543 {
544
545 DBaseDocument doc = createDBaseDocument();
546 String someValue = "someValue";
547 doc.appendItemValue(itemName, someValue);
548 Double doubleResult = doc.getItemValueDouble(itemName);
549 assertNull("Value of type Double should be null, but is " + doubleResult, doubleResult);
550 doc.remove(true);
551 }
552
553 {
554
555 int itemValue = 2;
556 DBaseDocument doc = createDBaseDocument();
557 doc.appendItemValue(itemName, itemValue);
558 Double doubleValue = doc.getItemValueDouble(itemName);
559 assertTrue("int (from double) should be '" + itemValue + "', but was '" + doubleValue + "'",
560 itemValue == doubleValue.doubleValue());
561 doc.remove(true);
562 }
563
564 {
565
566 double itemValue = 2.6;
567 DBaseDocument doc = createDBaseDocument();
568 doc.appendItemValue(itemName, itemValue);
569 Double doubleValue = doc.getItemValueDouble(itemName);
570 assertTrue("Received Double should be '" + itemValue + "', but was '" + doubleValue + "'",
571 itemValue == doubleValue.doubleValue());
572 doc.remove(true);
573 }
574
575 {
576
577 Calendar now = correctNow;
578 DBaseDocument doc = createDBaseDocument();
579 doc.appendItemValue(itemName, now);
580 Double doubleValue = doc.getItemValueDouble(itemName);
581 assertNull("Received Double should be null, but was '" + doubleValue + "'",
582 doubleValue);
583 doc.remove(true);
584 }
585 }
586 }
587
588 /***
589 * Tests the method getItemValueDate for all previously inserted types.
590 */
591 public final void testGetItemValueDate() {
592 System.out.println("-> testGetItemValueDate");
593
594 {
595
596 DBaseDocument doc = createDBaseDocument();
597 Calendar emptyValue = doc.getItemValueDate(itemName);
598 assertNull("Value should be null, but is " + emptyValue, emptyValue);
599 doc.remove(true);
600 }
601
602 {
603
604 DBaseDocument doc = createDBaseDocument();
605 doc.appendItemValue(itemName);
606 Calendar value = doc.getItemValueDate(itemName);
607 assertNull("Received Date should be NULL, but was '" + value + "'", value);
608 doc.remove(true);
609 }
610
611 {
612
613 DBaseDocument doc = createDBaseDocument();
614 String someValue = "someValue";
615 doc.appendItemValue(itemName, someValue);
616 Calendar dateResult = doc.getItemValueDate(itemName);
617 assertNull("Value of type Date should be null , but is " + dateResult, dateResult);
618 doc.remove(true);
619 }
620
621 {
622
623 int itemValue = 2;
624 DBaseDocument doc = createDBaseDocument();
625 doc.appendItemValue(itemName, itemValue);
626 Calendar dateValue = doc.getItemValueDate(itemName);
627 assertNull("Received Date should be '" + itemValue + "', but was '" + dateValue + "'", dateValue);
628 doc.remove(true);
629 }
630
631 {
632
633 double itemValue = 2.6;
634 DBaseDocument doc = createDBaseDocument();
635 doc.appendItemValue(itemName, itemValue);
636 Calendar dateValue = doc.getItemValueDate(itemName);
637 assertNull("Received Date should be '" + itemValue + "', but was '" + dateValue + "'", dateValue);
638 doc.remove(true);
639 }
640
641 {
642
643 Calendar now = correctNow;
644 DBaseDocument doc = createDBaseDocument();
645 doc.appendItemValue(itemName, now);
646 Calendar dateValue = doc.getItemValueDate(itemName);
647 assertEquals("Received Date should be now.", now, dateValue);
648 doc.remove(true);
649 }
650 }
651
652 /***
653 * Tests the method getItemValue for all previously inserted types.
654 */
655 public final void testGetItemValue() {
656 System.out.println("-> testGetItemValue");
657
658 {
659 DBaseDocument doc = createDBaseDocument();
660 List result = doc.getItemValue(itemName);
661 assertTrue("Document should have a list with one entry: '', but has: " + result, result.size() == 0);
662 doc.remove(true);
663 }
664
665 {
666 DBaseDocument doc = createDBaseDocument();
667 doc.appendItemValue(itemName);
668 List result = doc.getItemValue(itemName);
669 assertTrue(
670 "Document should have a list with one entry: '', but has: " + result + " with length " + result.size(),
671 result.size() == 1);
672 doc.remove(true);
673 }
674
675 {
676 DBaseDocument doc = createDBaseDocument();
677 List list = new ArrayList();
678 String itemValue1 = "itemValue1";
679 String itemValue2 = "itemValue2";
680 list.add(itemValue1);
681 list.add(itemValue2);
682 doc.appendItemValue(itemName, list);
683 List value = doc.getItemValue(itemName);
684 assertTrue("Received list should be '" + list + "', but was '" + value + "'", list.equals(value));
685 doc.remove(true);
686 }
687 }
688
689 /***
690 * Tests replacing of item values in a document.
691 */
692 public final void testReplaceItemValueXXX() {
693 System.out.println("-> testReplaceItemValueXXX");
694
695 DBaseDocument doc = createDBaseDocument();
696 doc.appendItemValue(itemName);
697
698 {
699 String value = doc.getItemValueString(itemName);
700 assertTrue("Item should have an empty String as value.", "".equals(value));
701 }
702
703 {
704 Calendar now = correctNow;
705 doc.replaceItemValue(itemName, now);
706 Calendar result = doc.getItemValueDate(itemName);
707 assertEquals("Item value should be " + now + " but is " + result, now, result);
708 }
709
710 {
711 DBaseDocument doc1 = createDBaseDocument();
712 Calendar value = new GregorianDate();
713 doc1.replaceItemValue(itemName, value);
714 doc1.replaceItemValue("Form", "DATETEST");
715 doc1.save();
716 Calendar result = doc1.getItemValueDate(itemName);
717 assertEquals("Item value should be " + value + " but is " + result, value, result);
718 }
719
720 {
721 DBaseDocument doc1 = createDBaseDocument();
722 Calendar value = new GregorianTime();
723 doc1.replaceItemValue(itemName, value);
724 doc1.replaceItemValue("Form", "DATETEST");
725 doc1.save();
726 Calendar result = doc1.getItemValueDate(itemName);
727 assertEquals("Item value should be " + value + " but is " + result, value, result);
728 }
729
730 {
731 double expected = 1.2;
732 doc.replaceItemValue(itemName, expected);
733 double result = doc.getItemValueDouble(itemName).doubleValue();
734 assertTrue("Item value should be " + expected + " but is " + result, expected == result);
735 }
736
737 {
738 int expected = 3;
739 doc.replaceItemValue(itemName, expected);
740 double result = doc.getItemValueInteger(itemName).intValue();
741 assertTrue("Item value should be " + expected + " but is " + result, expected == result);
742 }
743
744 {
745 String expected = "someValue";
746 doc.replaceItemValue(itemName, expected);
747 String result = doc.getItemValueString(itemName);
748 assertTrue("Item value should be " + expected + " but is " + result, expected.equals(result));
749 }
750
751 {
752
753 List list = new ArrayList();
754 String expected1 = "expected1";
755 String expected2 = "expected2";
756 list.add(expected1);
757 list.add(expected2);
758 doc.replaceItemValue(itemName, list);
759 List result = doc.getItemValue(itemName);
760 assertTrue("Expected result is " + list + " but is " + result, list.equals(result));
761 }
762
763 {
764
765 List list = new ArrayList();
766 Calendar expected1 = (Calendar) correctNow.clone();
767 Calendar expected2 = (Calendar) correctNow.clone();
768 list.add(expected1);
769 list.add(expected2);
770 doc.replaceItemValue(itemName, list);
771 List result = doc.getItemValue(itemName);
772 assertTrue("Expected result is " + list + " but is " + result, list.equals(result));
773 }
774 }
775
776 /***
777 * Removes a specified item out of a document and performs a test if a
778 * so named item is still in that document.
779 * @param doc this document
780 * @param pItemName the item's name
781 */
782 protected final void removeItem(DBaseDocument doc, String pItemName) {
783 doc.removeItem(pItemName);
784 DBaseItem nullItem = doc.getFirstItem(pItemName);
785 assertTrue(
786 "Document had an item named '" + pItemName + "' but that should have been removed.",
787 nullItem == null);
788 }
789
790 /***
791 * @return DBaseDocument that is used for tests in this class, but is of a type of all extending classes.
792 */
793 protected abstract DBaseDocument createDBaseDocument();
794
795 /***
796 * Sets up instance variables that are used in most of the tests.
797 */
798 public final void baseDocumentSetUp() {
799 baseSetUp();
800 itemName = "some_item_that_does_surely_not_exist";
801 correctNow = new GregorianCalendar();
802 correctNow.set(Calendar.MILLISECOND, 0);
803 }
804
805 /*** @return a unique item name. */
806 public final String getItemName() {
807 return itemName;
808 }
809 }