001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.gui.table.model;
019:
020: import java.util.Date;
021:
022: import junit.framework.TestCase;
023:
024: import org.columba.mail.folder.headercache.MemoryHeaderList;
025: import org.columba.mail.message.ColumbaHeader;
026: import org.columba.mail.message.IHeaderList;
027: import org.frapuccino.treetable.Tree;
028: import org.frapuccino.treetable.TreeTable;
029:
030: /**
031: * @author fdietz
032: *
033: */
034: public class HeaderTableModelTest extends TestCase {
035:
036: public static String[] columns = { "Subject", "From",
037: "columba.date" };
038:
039: protected IHeaderList createHeaderList() {
040: IHeaderList list = new MemoryHeaderList();
041: ColumbaHeader h = new ColumbaHeader();
042: h.set("columba.uid", new Integer(0));
043: h.set("Subject", "Test1");
044: h.set("From", "test@test.de");
045: h.set("columba.date", new Date());
046: list.add(h, new Integer(0));
047:
048: h = new ColumbaHeader();
049: h.set("columba.uid", new Integer(1));
050: h.set("Subject", "Test2");
051: h.set("From", "test@test.de");
052: h.set("columba.date", new Date());
053: list.add(h, new Integer(1));
054:
055: return list;
056: }
057:
058: /**
059: * Test number of columns after init
060: *
061: */
062: public void testColumns() {
063: HeaderTableModel model = new HeaderTableModel(columns);
064:
065: // 3 columns table
066: assertEquals(3, model.getColumnCount());
067: }
068:
069: public void testSet() {
070: HeaderTableModel model = new HeaderTableModel(columns);
071:
072: TreeTable treetable = new TreeTable();
073: treetable.setModel(model);
074: model.setTree((Tree) treetable.getTree());
075:
076: // create sample headerlist
077: IHeaderList list = createHeaderList();
078:
079: model.set(list);
080:
081: // check number of tree nodes
082: assertEquals(2, model.getRootNode().getChildCount());
083:
084: // check number of cached MessageNodes
085: //assertEquals(2, model.getMap().size());
086:
087: // check number of JTable rows
088: assertEquals(2, model.getRowCount());
089:
090: // check number of JTree rows
091: assertEquals(2, model.getTree().getRowCount());
092:
093: }
094:
095: public void testRemove() {
096: HeaderTableModel model = new HeaderTableModel(columns);
097: Tree tree = new Tree();
098: model.setTree(tree);
099:
100: IHeaderList list = createHeaderList();
101:
102: model.set(list);
103:
104: // remove MessageNode with uid=0
105: model.remove(new Object[] { new Integer(0) });
106:
107: // check number of tree nodes
108: assertEquals(1, model.getRootNode().getChildCount());
109: // check number of cached MessageNodes
110: //assertEquals(1, model.getMap().size());
111:
112: // check number of JTable rows
113: assertEquals(1, model.getRowCount());
114:
115: // check number of JTree rows
116: assertEquals(1, model.getTree().getRowCount());
117: }
118:
119: public void testModify() {
120: HeaderTableModel model = new HeaderTableModel(columns);
121: Tree tree = new Tree();
122: model.setTree(tree);
123:
124: IHeaderList list = createHeaderList();
125:
126: model.set(list);
127: }
128: }
|