1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.test.unit.widget;
9
10 import com.tirsen.angkor.table.*;
11 import com.tirsen.angkor.event.Action;
12 import com.tirsen.angkor.widget.TextLabel;
13 import com.tirsen.angkor.test.unit.MockPipeline;
14 import junit.framework.TestCase;
15
16 import java.text.Format;
17
18 /***
19 * TODO document TableTest.
20 *
21 * <!-- $Id: TableTest.java,v 1.1 2002/10/07 19:49:23 tirsen Exp $ -->
22 * <!-- $Author: tirsen $ -->
23 *
24 * @author Jon Tirs´n (tirsen@users.sourceforge.net)
25 * @version $Revision: 1.1 $
26 */
27 public class TableTest extends TestCase
28 {
29 private int rowCount = 10;
30 private MockPipeline pipeline = new MockPipeline();
31
32 public TableTest(String s)
33 {
34 super(s);
35 }
36
37 protected void setUp() throws Exception
38 {
39 pipeline.start();
40 pipeline.getRenderContext().getEventQueue().setPostponeEvents(false);
41 }
42
43 protected void tearDown() throws Exception
44 {
45 pipeline.end();
46 }
47
48 private void load(DefaultTableModel model) throws Exception
49 {
50 for(int i = model.getStart(); i <= model.getEnd(); i++)
51 {
52 model.setRow(i, new Object[] { new Integer(i), "Text " + i });
53 }
54 model.setRowCount(rowCount);
55 }
56
57 public void testScroller() throws Exception
58 {
59 Table table = new Table();
60 DefaultTableModel model = (DefaultTableModel) table.getTableModel();
61 table.setReadOnly(true);
62 model.addColumn("Row Number");
63 model.addColumn("Row Text");
64 model.setRowCount(rowCount);
65 table.setModel(model);
66
67 load(model);
68 assertTrue("incorrect number of rows loaded", model.getRowCount() == rowCount);
69
70 TableScroller scroller = new TableScroller();
71 table.setNumberOfScrollRows(4);
72 scroller.setTable(table);
73
74 Action next = scroller.getNextAction();
75 Action previous = scroller.getPreviousAction();
76
77 assertTrue("previous enabled at beginning of table", !previous.isEnabled());
78 assertTrue("next disabled at beginning of table", next.isEnabled());
79
80 load(model);
81
82 assertTrue("incorrect number of rows loaded", model.getEnd() - model.getStart() + 1 == 4);
83
84 while(next.isEnabled())
85 {
86 System.out.println("forward");
87 next.actionPerformed(null);
88 System.out.println("table.getStartRow() = " + table.getStartRow());
89 System.out.println("table.getEndRow() = " + table.getEndRow());
90
91 assertTrue("previous still disabled after forward scroll", previous.isEnabled());
92
93 load(model);
94
95 int rowToCheck = table.getStartRow();
96 int number = Integer.parseInt(((TextLabel) table.getCellView(rowToCheck, 0)).getFormattedText());
97 //int number = ((Integer) model.getValueAt(rowToCheck, 0).getValue()).intValue();
98 assertTrue("wrong number is displayed at (" + rowToCheck + ",0) cell", number == rowToCheck);
99 }
100
101 while(previous.isEnabled())
102 {
103 System.out.println("backward");
104 previous.actionPerformed(null);
105 System.out.println("table.getStartRow() = " + table.getStartRow());
106 System.out.println("table.getEndRow() = " + table.getEndRow());
107
108 assertTrue("next still disabled after backward scroll", next.isEnabled());
109
110 load(model);
111
112 int rowToCheck = table.getStartRow();
113 int number = ((Integer) model.getValueAt(rowToCheck, 0).getValue()).intValue();
114 assertTrue("wrong number is displayed at (" + rowToCheck + ",0) cell", number == rowToCheck);
115 }
116 }
117
118 public void testModelChange() throws Exception
119 {
120 DefaultTableModel model = new DefaultTableModel();
121 model.addColumn("Number");
122 Integer firstvalue = new Integer(1);
123 model.addRow(new Object[] { firstvalue });
124
125 Table table = new Table();
126 table.setReadOnly(true);
127 table.setModel(model);
128
129 TextLabel firstview = (TextLabel) table.getCellView(0, 0);
130 assertSame("views are reinstantiated", firstview, table.getCellView(0, 0));
131
132 Format format = firstview.getFormat();
133 assertTrue("view didn't display correct value before change", format.format(new Object[] { firstvalue }).equals(firstview.getFormattedText()));
134
135 Integer newvalue = new Integer(4711);
136 model.setRow(0, new Object[] { newvalue });
137
138 TextLabel newview = (TextLabel) table.getCellView(0, 0);
139 format = newview.getFormat();
140 assertTrue("views were not recreated", firstview != newview);
141 assertTrue("view didn't display correct value after change", format.format(new Object[] { newvalue }).equals(newview.getFormattedText()));
142 }
143 }
This page was automatically generated by Maven