KickJava   Java API By Example, From Geeks To Geeks.

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


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.Component JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Rectangle JavaDoc;
25 import javax.swing.JButton JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JToolBar JavaDoc;
28 import javax.swing.JToolBar JavaDoc;
29 import javax.swing.JTree JavaDoc;
30 import javax.swing.table.TableCellRenderer JavaDoc;
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33 import org.netbeans.jellytools.FilesTabOperator;
34 import org.netbeans.jellytools.JellyTestCase;
35 import org.netbeans.jellytools.NbDialogOperator;
36 import org.netbeans.jellytools.TopComponentOperator;
37 import org.netbeans.jellytools.actions.OpenAction;
38 import org.netbeans.jellytools.nodes.Node;
39 import org.netbeans.jemmy.ComponentChooser;
40 import org.netbeans.jemmy.EventTool;
41 import org.netbeans.jemmy.operators.ComponentOperator;
42 import org.netbeans.jemmy.operators.DialogOperator;
43 import org.netbeans.jemmy.operators.JButtonOperator;
44 import org.netbeans.jemmy.operators.JComponentOperator;
45 import org.netbeans.jemmy.operators.JPopupMenuOperator;
46 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
47 import org.netbeans.jemmy.operators.JTableOperator;
48 import org.netbeans.jemmy.operators.JTextFieldOperator;
49 import org.netbeans.jemmy.util.NameComponentChooser;
50 import org.netbeans.jemmy.util.PropChooser;
51 import org.netbeans.junit.NbTestSuite;
52
53 /**
54  * Tests for the actions.
55  *
56  * @author tl
57  */

58 public class TestActions extends JellyTestCase {
59     public TestActions(java.lang.String JavaDoc testName) {
60         super(testName);
61     }
62     
63     public static Test suite() {
64         TestSuite suite = new NbTestSuite(TestActions.class);
65         return suite;
66     }
67     
68     public static void main(java.lang.String JavaDoc[] args) {
69         junit.textui.TestRunner.run(suite());
70     }
71
72     private static int getLevel(JTableOperator t, int row) {
73         TableCellRenderer JavaDoc tcr = t.getCellRenderer(row, 2);
74         JTree JavaDoc tree = (JTree JavaDoc) t.prepareRenderer(tcr, row, 2);
75         return tree.getPathForRow(row).getPathCount();
76     }
77     
78     private static String JavaDoc getSummary(JTableOperator t, int row) {
79         t.editCellAt(row, 2);
80         JTextFieldOperator op = new JTextFieldOperator(t);
81         return op.getText();
82     }
83     
84     /**
85      * Test the "Paste at top level".
86      */

87     public void testPasteAtTopLevel() {
88         TopComponentOperator tc = openIcsFile("testPasteAtTopLevel.ics"); // NOI18N
89

90         JTableOperator t = new JTableOperator(tc, 0);
91
92         t.clickForPopup();
93         JPopupMenuOperator pm = new JPopupMenuOperator();
94         pm.pushMenu("Expand All"); // NOI18N
95
new EventTool().waitNoEvent(1500);
96         
97         Rectangle JavaDoc r = t.getCellRect(2, 2, false);
98         t.clickForPopup(r.x, r.y);
99         pm = new JPopupMenuOperator();
100         pm.pushMenu("Cut"); // NOI18N
101

102         t.clickForPopup();
103         pm = new JPopupMenuOperator();
104         pm.pushMenu("Paste at Top Level"); // NOI18N
105

106         t.clickForPopup();
107         pm = new JPopupMenuOperator();
108         pm.pushMenu("Expand All"); // NOI18N
109
new EventTool().waitNoEvent(1500);
110         
111         assertEquals(9, t.getRowCount());
112         assertEquals("H", getSummary(t, 0));
113         assertEquals("I", getSummary(t, 1));
114         assertEquals("D", getSummary(t, 2));
115         assertEquals("E", getSummary(t, 3));
116         assertEquals("F", getSummary(t, 4));
117         assertEquals("G", getSummary(t, 5));
118         assertEquals("C", getSummary(t, 6));
119         assertEquals("A", getSummary(t, 7));
120         assertEquals("B", getSummary(t, 8));
121
122         assertEquals(2, getLevel(t, 7));
123         assertEquals(3, getLevel(t, 8));
124     }
125     
126     /**
127      * Test for the "Start" action. It should be disabled if a dependancy on
128      * another task is added and re-enabled if this dependancy is removed.
129      */

130     public void testStartWithDeps() {
131         TopComponentOperator tc = openIcsFile("testStartWithDeps.ics"); // NOI18N
132
JTableOperator t = new JTableOperator(tc, 0);
133         
134         t.selectCell(0, 2);
135         Rectangle JavaDoc r = t.getCellRect(0, 2, false);
136         t.clickForPopup(r.x, r.y);
137         JPopupMenuOperator pm = new JPopupMenuOperator();
138         pm.pushMenuNoBlock("Show Task"); // NOI18N
139

140         NbDialogOperator dop = new NbDialogOperator("Show Task"); // NOI18N
141
JTabbedPaneOperator tpop = new JTabbedPaneOperator(dop, 0);
142         tpop.setSelectedIndex(2);
143         JComponentOperator pop = new JComponentOperator(
144                 (JComponent JavaDoc) tpop.getSelectedComponent());
145         new JButtonOperator(pop, "Add").push();
146         NbDialogOperator addop = new NbDialogOperator(
147                 "Add Dependency"); // NOI18N
148
JTree JavaDoc tree = (JTree JavaDoc) ComponentOperator.findComponent(
149                 (Container JavaDoc) addop.getSource(),
150                 new ComponentChooser() {
151             public boolean checkComponent(Component JavaDoc arg0) {
152                 return arg0 instanceof JTree JavaDoc;
153             }
154
155             public String JavaDoc getDescription() {
156                 return "";
157             }
158         });
159         tree.setSelectionRow(1);
160         addop.ok();
161         dop.ok();
162         
163         JComponentOperator tb = new JComponentOperator(
164                 tc, new PropChooser(new String JavaDoc[] {"getClass"},
165                 new Object JavaDoc[] {JToolBar JavaDoc.class}));
166
167         JButtonOperator start = new JButtonOperator(tb, new ComponentChooser() {
168             public boolean checkComponent(Component JavaDoc c) {
169                 if (c instanceof JButton JavaDoc) {
170                    String JavaDoc s = ((JButton JavaDoc) c).getToolTipText();
171                    return "Start".equals(s);
172                 }
173                 return false;
174             }
175
176             public String JavaDoc getDescription() {
177                 return "";
178             }
179         });
180         assertTrue(!start.isEnabled());
181
182         t.selectCell(0, 2);
183         r = t.getCellRect(0, 2, false);
184         t.clickForPopup(r.x, r.y);
185         pm = new JPopupMenuOperator();
186         pm.pushMenuNoBlock("Show Task"); // NOI18N
187

188         dop = new NbDialogOperator("Show Task"); // NOI18N
189
tpop = new JTabbedPaneOperator(dop, 0);
190         tpop.setSelectedIndex(2);
191         pop = new JComponentOperator(
192                 (JComponent JavaDoc) tpop.getSelectedComponent());
193         new JButtonOperator(pop, "Remove").push();
194         addop = new NbDialogOperator("Question"); // NOI18N
195
addop.yes();
196         dop.ok();
197         assertTrue(start.isEnabled());
198     }
199     
200     /**
201      * Test the "Purge Completed".
202      */

203     public void testPurgeCompleted() {
204         TopComponentOperator tc = openIcsFile("testPurgeCompleted.ics"); // NOI18N
205

206         JTableOperator t = new JTableOperator(tc, 0);
207         t.selectAll();
208                 
209         t.clickForPopup();
210         JPopupMenuOperator pm = new JPopupMenuOperator();
211         pm.pushMenuNoBlock("Purge Completed"); // NOI18N
212

213         DialogOperator dop = new DialogOperator("Question"); // NOI18N
214
JButtonOperator bo = new JButtonOperator(dop, "OK"); // NOI18N
215
bo.push();
216         
217         t.clickForPopup();
218         pm = new JPopupMenuOperator();
219         pm.pushMenu("Expand All"); // NOI18N
220

221         assertEquals(5, t.getRowCount());
222         assertEquals("D", getSummary(t, 0));
223         assertEquals("E", getSummary(t, 1));
224         assertEquals("H", getSummary(t, 2));
225         assertEquals("I", getSummary(t, 3));
226         assertEquals("A", getSummary(t, 4));
227     }
228
229     /**
230      * Opens an ICS file
231      *
232      * @param name file name under /ics
233      * @return opened TC
234      */

235     private TopComponentOperator openIcsFile(String JavaDoc name) {
236         Node n = FilesTabOperator.invoke().getProjectNode("SampleApp"); // NOI18N
237

238         Node data = new Node(n, "ics|" + name); // NOI18N
239
data.select();
240         new OpenAction().perform(data);
241         
242         TopComponentOperator op = new TopComponentOperator(name);
243
244         return op;
245     }
246 }
247
Popular Tags