1 19 20 package org.netbeans.modules.tasklist.usertasks.test; 21 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Rectangle ; 25 import javax.swing.JButton ; 26 import javax.swing.JComponent ; 27 import javax.swing.JToolBar ; 28 import javax.swing.JToolBar ; 29 import javax.swing.JTree ; 30 import javax.swing.table.TableCellRenderer ; 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 58 public class TestActions extends JellyTestCase { 59 public TestActions(java.lang.String 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 [] args) { 69 junit.textui.TestRunner.run(suite()); 70 } 71 72 private static int getLevel(JTableOperator t, int row) { 73 TableCellRenderer tcr = t.getCellRenderer(row, 2); 74 JTree tree = (JTree ) t.prepareRenderer(tcr, row, 2); 75 return tree.getPathForRow(row).getPathCount(); 76 } 77 78 private static String getSummary(JTableOperator t, int row) { 79 t.editCellAt(row, 2); 80 JTextFieldOperator op = new JTextFieldOperator(t); 81 return op.getText(); 82 } 83 84 87 public void testPasteAtTopLevel() { 88 TopComponentOperator tc = openIcsFile("testPasteAtTopLevel.ics"); 90 JTableOperator t = new JTableOperator(tc, 0); 91 92 t.clickForPopup(); 93 JPopupMenuOperator pm = new JPopupMenuOperator(); 94 pm.pushMenu("Expand All"); new EventTool().waitNoEvent(1500); 96 97 Rectangle r = t.getCellRect(2, 2, false); 98 t.clickForPopup(r.x, r.y); 99 pm = new JPopupMenuOperator(); 100 pm.pushMenu("Cut"); 102 t.clickForPopup(); 103 pm = new JPopupMenuOperator(); 104 pm.pushMenu("Paste at Top Level"); 106 t.clickForPopup(); 107 pm = new JPopupMenuOperator(); 108 pm.pushMenu("Expand All"); 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 130 public void testStartWithDeps() { 131 TopComponentOperator tc = openIcsFile("testStartWithDeps.ics"); JTableOperator t = new JTableOperator(tc, 0); 133 134 t.selectCell(0, 2); 135 Rectangle r = t.getCellRect(0, 2, false); 136 t.clickForPopup(r.x, r.y); 137 JPopupMenuOperator pm = new JPopupMenuOperator(); 138 pm.pushMenuNoBlock("Show Task"); 140 NbDialogOperator dop = new NbDialogOperator("Show Task"); JTabbedPaneOperator tpop = new JTabbedPaneOperator(dop, 0); 142 tpop.setSelectedIndex(2); 143 JComponentOperator pop = new JComponentOperator( 144 (JComponent ) tpop.getSelectedComponent()); 145 new JButtonOperator(pop, "Add").push(); 146 NbDialogOperator addop = new NbDialogOperator( 147 "Add Dependency"); JTree tree = (JTree ) ComponentOperator.findComponent( 149 (Container ) addop.getSource(), 150 new ComponentChooser() { 151 public boolean checkComponent(Component arg0) { 152 return arg0 instanceof JTree ; 153 } 154 155 public String 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 [] {"getClass"}, 165 new Object [] {JToolBar .class})); 166 167 JButtonOperator start = new JButtonOperator(tb, new ComponentChooser() { 168 public boolean checkComponent(Component c) { 169 if (c instanceof JButton ) { 170 String s = ((JButton ) c).getToolTipText(); 171 return "Start".equals(s); 172 } 173 return false; 174 } 175 176 public String 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"); 188 dop = new NbDialogOperator("Show Task"); tpop = new JTabbedPaneOperator(dop, 0); 190 tpop.setSelectedIndex(2); 191 pop = new JComponentOperator( 192 (JComponent ) tpop.getSelectedComponent()); 193 new JButtonOperator(pop, "Remove").push(); 194 addop = new NbDialogOperator("Question"); addop.yes(); 196 dop.ok(); 197 assertTrue(start.isEnabled()); 198 } 199 200 203 public void testPurgeCompleted() { 204 TopComponentOperator tc = openIcsFile("testPurgeCompleted.ics"); 206 JTableOperator t = new JTableOperator(tc, 0); 207 t.selectAll(); 208 209 t.clickForPopup(); 210 JPopupMenuOperator pm = new JPopupMenuOperator(); 211 pm.pushMenuNoBlock("Purge Completed"); 213 DialogOperator dop = new DialogOperator("Question"); JButtonOperator bo = new JButtonOperator(dop, "OK"); bo.push(); 216 217 t.clickForPopup(); 218 pm = new JPopupMenuOperator(); 219 pm.pushMenu("Expand All"); 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 235 private TopComponentOperator openIcsFile(String name) { 236 Node n = FilesTabOperator.invoke().getProjectNode("SampleApp"); 238 Node data = new Node(n, "ics|" + name); data.select(); 240 new OpenAction().perform(data); 241 242 TopComponentOperator op = new TopComponentOperator(name); 243 244 return op; 245 } 246 } 247 | Popular Tags |