KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > test > TestTable


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.test;
21
22 import java.awt.Rectangle JavaDoc;
23 import javax.swing.DefaultCellEditor JavaDoc;
24 import javax.swing.JComboBox JavaDoc;
25 import javax.swing.table.TableCellEditor JavaDoc;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.netbeans.jellytools.FilesTabOperator;
30 import org.netbeans.jellytools.JellyTestCase;
31 import org.netbeans.jellytools.NbDialogOperator;
32 import org.netbeans.jellytools.TopComponentOperator;
33 import org.netbeans.jellytools.actions.Action;
34 import org.netbeans.jellytools.actions.OpenAction;
35 import org.netbeans.jellytools.nodes.Node;
36 import org.netbeans.jemmy.EventTool;
37 import org.netbeans.jemmy.operators.DialogOperator;
38 import org.netbeans.jemmy.operators.JButtonOperator;
39 import org.netbeans.jemmy.operators.JPopupMenuOperator;
40 import org.netbeans.jemmy.operators.JTableOperator;
41 import org.netbeans.junit.NbTestSuite;
42
43 /**
44  * Tests for the TreeTable
45  */

46 public class TestTable extends JellyTestCase {
47     public TestTable(java.lang.String JavaDoc testName) {
48         super(testName);
49     }
50     
51     public static Test suite() {
52         TestSuite suite = new NbTestSuite(TestTable.class);
53         return suite;
54     }
55     
56     public static void main(java.lang.String JavaDoc[] args) {
57         junit.textui.TestRunner.run(suite());
58     }
59
60     /**
61      * Test the "Show Task" dialog
62      */

63     public void testShowTask() {
64         Node n = FilesTabOperator.invoke().getProjectNode("SampleApp"); // NOI18N
65

66         Node buildXml = new Node(n, "build.xml"); // NOI18N
67
buildXml.select();
68         new OpenAction().perform(buildXml);
69         
70         TopComponentOperator tc = openIcsFile("test10.ics"); // NOI18N
71

72         JTableOperator t = new JTableOperator(tc, 0);
73         t.waitHasFocus();
74         assertEquals(0, t.getSelectedRow());
75         t.selectCell(1, 0);
76         
77         Action ea = new Action(null, "Expand All"); // NOI18N
78
ea.performPopup(t);
79         t.selectCell(1, 0);
80         
81         t.clickForPopup();
82         
83         new EventTool().waitNoEvent(1500);
84
85         JPopupMenuOperator pm = new JPopupMenuOperator();
86         pm.pushMenuNoBlock("Show Task"); // NOI18N
87

88         new NbDialogOperator("Show Task").close(); // NOI18N
89
}
90
91     /**
92      * see description for the test 14
93      */

94     public void testStartTaskFillsOwner() {
95         /*
96          This does not work because of #51882
97         TopComponentOperator tc = openIcsFile("test14.ics");
98         
99         JTableOperator t = new JTableOperator(tc, 0);
100         t.waitHasFocus();
101         
102         Action ea = new Action(null, "Expand All");
103         ea.performPopup(t);
104         
105         Point p = t.findCell("R",
106             new Operator.DefaultStringComparator(true, true), 1);
107         t.selectCell(p.y, p.x);
108         
109         t.clickForPopup();
110         
111         new EventTool().waitNoEvent(1500);
112
113         JPopupMenuOperator pm = new JPopupMenuOperator();
114         pm.pushMenuNoBlock("Start");
115         
116         TreeTable tt = (TreeTable) t.getSource();
117         UserTaskTreeTableNode n = (UserTaskTreeTableNode) tt.getNodeForRow(p.y);
118          
119         assertEquals(System.getProperty("user.name"), n.getUserTask().getOwner());
120          */

121     }
122     
123     /**
124      * See description in testCases.html
125      */

126     public void testDelete() {
127         TopComponentOperator tc = openIcsFile("test15.ics"); // NOI18N
128

129         JTableOperator t = new JTableOperator(tc, 0);
130         t.waitHasFocus();
131         
132         Action ea = new Action(null, "Expand All"); // NOI18N
133
ea.performPopup(t);
134         
135         t.addRowSelectionInterval(5, 7);
136         t.addRowSelectionInterval(9, 9);
137         
138         Rectangle JavaDoc r = t.getCellRect(5, 0, false);
139         t.clickForPopup(r.x, r.y);
140         
141         new EventTool().waitNoEvent(1500);
142
143         JPopupMenuOperator pm = new JPopupMenuOperator();
144         pm.pushMenuNoBlock("Delete"); // NOI18N
145

146         DialogOperator dop = new DialogOperator("Confirm Multiple Object Deletion"); // NOI18N
147
JButtonOperator bo = new JButtonOperator(dop, "Yes"); // NOI18N
148
bo.push();
149         
150         new EventTool().waitNoEvent(1500);
151         
152         assertEquals(6, t.getSelectedRow());
153     }
154     
155     /**
156      * see description for the test 13
157      */

158     public void testCategoryInplace() {
159         TopComponentOperator tc = openIcsFile("test13.ics"); // NOI18N
160

161         JTableOperator t = new JTableOperator(tc, 0);
162         t.waitHasFocus();
163         t.selectCell(1, 0);
164         
165         Action ea = new Action(null, "Expand All"); // NOI18N
166
ea.performPopup(t);
167         t.selectCell(3, 3);
168         t.editCellAt(3, 3);
169         TableCellEditor JavaDoc ed = t.getCellEditor();
170         JComboBox JavaDoc cb = ((JComboBox JavaDoc) ((DefaultCellEditor JavaDoc) ed).getComponent());
171         assertEquals(2, cb.getItemCount());
172         assertEquals(cb.getItemAt(0), "CatA"); // NOI18N
173
assertEquals(cb.getItemAt(1), "CatB"); // NOI18N
174
}
175
176     /**
177      * Opens an ICS file
178      *
179      * @param name file name under /ics
180      * @return opened TC
181      */

182     private TopComponentOperator openIcsFile(String JavaDoc name) {
183         Node n = FilesTabOperator.invoke().getProjectNode("SampleApp"); // NOI18N
184

185         Node data = new Node(n, "ics|" + name); // NOI18N
186
data.select();
187         new OpenAction().perform(data);
188         
189         TopComponentOperator op = new TopComponentOperator(name);
190
191         return op;
192     }
193 }
194
Popular Tags