2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28 * Microsystems, Inc. All Rights Reserved.
30 * If you wish your version of this file to be governed by only the CDDL
31 * or only the GPL Version 2, indicate your decision by adding
32 * "[Contributor] elects to include this software in this distribution
33 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34 * single choice of license, a recipient has the option to distribute
35 * your version of this file under either the CDDL, the GPL Version 2 or
36 * to extend the choice of license to its licensees as provided above.
37 * However, if you add GPL Version 2 code and therefore, elected the GPL
38 * Version 2 license, then the option applies only if the new code is
39 * made subject to such option by the copyright holder.
42 package org.netbeans.test.ide;
44 import java.awt.Component;
45 import java.awt.Toolkit;
46 import java.awt.Window;
47 import java.awt.datatransfer.DataFlavor;
48 import java.awt.datatransfer.UnsupportedFlavorException;
49 import java.awt.event.KeyEvent;
51 import java.io.IOException;
52 import javax.swing.JTextField;
53 import javax.swing.KeyStroke;
54 import javax.swing.UIManager;
55 import org.netbeans.jellytools.Bundle;
56 import org.netbeans.jellytools.EditorOperator;
57 import org.netbeans.jellytools.FavoritesOperator;
58 import org.netbeans.jellytools.FilesTabOperator;
59 import org.netbeans.jellytools.HelpOperator;
60 import org.netbeans.jellytools.JellyTestCase;
61 import org.netbeans.jellytools.MainWindowOperator;
62 import org.netbeans.jellytools.NbDialogOperator;
63 import org.netbeans.jellytools.NewFileNameLocationStepOperator;
64 import org.netbeans.jellytools.NewFileWizardOperator;
65 import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
66 import org.netbeans.jellytools.NewProjectWizardOperator;
67 import org.netbeans.jellytools.OptionsOperator;
68 import org.netbeans.jellytools.OutputOperator;
69 import org.netbeans.jellytools.OutputTabOperator;
70 import org.netbeans.jellytools.PluginsOperator;
71 import org.netbeans.jellytools.ProjectsTabOperator;
72 import org.netbeans.jellytools.RuntimeTabOperator;
73 import org.netbeans.jellytools.TopComponentOperator;
74 import org.netbeans.jellytools.actions.Action;
75 import org.netbeans.jellytools.actions.ActionNoBlock;
76 import org.netbeans.jellytools.actions.AttachWindowAction;
77 import org.netbeans.jellytools.actions.CompileAction;
78 import org.netbeans.jellytools.actions.CopyAction;
79 import org.netbeans.jellytools.actions.CutAction;
80 import org.netbeans.jellytools.actions.DeleteAction;
81 import org.netbeans.jellytools.actions.NewFileAction;
82 import org.netbeans.jellytools.actions.PasteAction;
83 import org.netbeans.jellytools.actions.ViewAction;
84 import org.netbeans.jellytools.modules.debugger.actions.ContinueAction;
85 import org.netbeans.jellytools.modules.debugger.actions.DebugAction;
86 import org.netbeans.jellytools.modules.debugger.actions.FinishDebuggerAction;
87 import org.netbeans.jellytools.modules.debugger.actions.NewBreakpointAction;
88 import org.netbeans.jellytools.modules.debugger.actions.ToggleBreakpointAction;
89 import org.netbeans.jellytools.nodes.JavaNode;
90 import org.netbeans.jellytools.nodes.Node;
91 import org.netbeans.jellytools.nodes.SourcePackagesNode;
92 import org.netbeans.jellytools.properties.Property;
93 import org.netbeans.jellytools.properties.PropertySheetOperator;
95 import org.netbeans.jemmy.ComponentChooser;
96 import org.netbeans.jemmy.EventTool;
97 import org.netbeans.jemmy.JemmyException;
98 import org.netbeans.jemmy.JemmyProperties;
99 import org.netbeans.jemmy.QueueTool;
100 import org.netbeans.jemmy.TestOut;
101 import org.netbeans.jemmy.TimeoutExpiredException;
102 import org.netbeans.jemmy.Waitable;
103 import org.netbeans.jemmy.Waiter;
104 import org.netbeans.jemmy.operators.JButtonOperator;
105 import org.netbeans.jemmy.operators.JDialogOperator;
106 import org.netbeans.jemmy.operators.JLabelOperator;
107 import org.netbeans.jemmy.operators.JRadioButtonOperator;
108 import org.netbeans.jemmy.operators.JTextFieldOperator;
109 import org.netbeans.jemmy.operators.JTreeOperator;
110 import org.netbeans.jemmy.operators.Operator;
111 import org.netbeans.jemmy.operators.WindowOperator;
112 import org.netbeans.jemmy.util.PNGEncoder;
114 import org.netbeans.junit.NbTestSuite;
115 import org.openide.windows.Mode;
116 import org.openide.windows.TopComponent;
117 import org.openide.windows.WindowManager;
121 * Overall validation suite for IDE.
123 * @author Jiri.Skrivanek@sun.com
125 public class IDEValidation extends JellyTestCase {
127 /** Need to be defined because of JUnit */
128 public IDEValidation(String name) {
132 public static NbTestSuite suite() {
133 NbTestSuite suite = new NbTestSuite();
134 suite.addTest(new IDEValidation("testInitGCProjects"));
135 suite.addTest(new IDEValidation("testMainMenu"));
136 suite.addTest(new IDEValidation("testHelp"));
137 suite.addTest(new IDEValidation("testOptions"));
138 suite.addTest(new IDEValidation("testOptionsClassicView"));
139 suite.addTest(new IDEValidation("testNewProject"));
140 // sample project must exist before testShortcuts
141 suite.addTest(new IDEValidation("testShortcuts"));
142 suite.addTest(new IDEValidation("testNewFile"));
143 suite.addTest(new IDEValidation("testCVSLite"));
144 suite.addTest(new IDEValidation("testProjectsView"));
145 suite.addTest(new IDEValidation("testFilesView"));
146 suite.addTest(new IDEValidation("testEditor"));
147 suite.addTest(new IDEValidation("testBuildAndRun"));
148 suite.addTest(new IDEValidation("testDebugging"));
149 suite.addTest(new IDEValidation("testJUnit"));
150 suite.addTest(new IDEValidation("testXML"));
151 suite.addTest(new IDEValidation("testDb"));
152 suite.addTest(new IDEValidation("testWindowSystem"));
153 suite.addTest(new IDEValidation("testPlugins"));
157 /** Setup called before every test case. */
159 public void setUp() {
160 System.out.println("######## "+getName()+" #######");
161 // Close help window if any - it should not stay open between test cases.
162 // Otherwise it can break next tests.
166 /** Tear down called after every test case. */
168 public void tearDown() {
171 // name of sample project
172 private static final String SAMPLE_PROJECT_NAME = "SampleProject"; // NOI18N
173 // name of first sample package
174 private static final String SAMPLE1_PACKAGE_NAME = "sample1"; //NOI18N
175 // name of sample class
176 private static final String SAMPLE1_CLASS_NAME = "SampleClass1"; // NOI18N
177 // name of sample file
178 private static final String SAMPLE1_FILE_NAME = SAMPLE1_CLASS_NAME+".java"; // NOI18N
179 // name of sample class 2
180 private static final String SAMPLE2_CLASS_NAME = "SampleClass2"; // NOI18N
181 // name of sample file 2
182 private static final String SAMPLE2_FILE_NAME = SAMPLE2_CLASS_NAME+".java"; // NOI18N
184 /** Test creation of java project.
185 * - open New Project wizard from main menu (File|New Project)
186 * - select Java Application project from Standard category
187 * - in the next panel type project name and project location in
188 * - finish the wizard
189 * - wait until project appears in projects view
190 * - wait classpath scanning finished
192 public void testNewProject() {
193 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
195 String standardLabel = Bundle.getStringTrimmed("org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", "Templates/Project/Standard");
196 npwo.selectCategory(standardLabel);
197 // "Java Application"
198 String javaApplicationLabel = Bundle.getStringTrimmed("org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", "Templates/Project/Standard/emptyJ2SE.xml");
199 npwo.selectProject(javaApplicationLabel);
201 NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
202 npnlso.txtProjectName().setText(SAMPLE_PROJECT_NAME);
203 npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
204 npnlso.btFinish().pushNoBlock();
205 npnlso.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
208 String openingProjectsTitle = Bundle.getString("org.netbeans.modules.project.ui.Bundle", "LBL_Opening_Projects_Progress");
210 // wait at most 120 second until progress dialog dismiss
211 NbDialogOperator openingOper = new NbDialogOperator(openingProjectsTitle);
212 openingOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
213 openingOper.waitClosed();
214 } catch (TimeoutExpiredException e) {
215 // ignore when progress dialog was closed before we started to wait for it
217 // wait project appear in projects view
218 new ProjectsTabOperator().getProjectRootNode(SAMPLE_PROJECT_NAME);
219 // wait classpath scanning finished
220 WatchProjects.waitScanFinished();
223 /** Test new file wizard.
224 * - open New File wizard from main menu (File|New File)
225 * - select sample project as target
226 * - select Java Classes|Java Package file type
227 * - in the next panel type package name in
228 * - finish the wizard
229 * - open New File wizard from context menu on created package node (New|File)
230 * - select Java Classes|Java Main Class file type
231 * - in the next panel type class name in
232 * - finish the wizard
233 * - check class is open in editor and close all opened documents
235 public void testNewFile() {
236 // create a new package
238 String javaClassesLabel = Bundle.getString("org.netbeans.modules.java.project.Bundle", "Templates/Classes");
240 String packageLabel = Bundle.getString("org.netbeans.modules.java.project.Bundle", "Templates/Classes/Package");
241 NewFileWizardOperator.create(SAMPLE_PROJECT_NAME, javaClassesLabel, packageLabel, null, SAMPLE1_PACKAGE_NAME);
242 // wait package node is created
243 Node sample1Node = new Node(new SourcePackagesNode(SAMPLE_PROJECT_NAME), SAMPLE1_PACKAGE_NAME);
245 // create a new classes
248 String mainClassLabel = Bundle.getString("org.netbeans.modules.java.project.Bundle", "Templates/Classes/Main.java"); // NOI18N
249 NewFileWizardOperator.invoke(sample1Node, javaClassesLabel, mainClassLabel);
250 NewFileNameLocationStepOperator nameStepOper = new NewFileNameLocationStepOperator();
251 nameStepOper.setObjectName(SAMPLE1_CLASS_NAME);
252 nameStepOper.finish();
253 // check class is opened in Editor
254 new EditorOperator(SAMPLE1_FILE_NAME);
255 NewFileWizardOperator.invoke(sample1Node, javaClassesLabel, mainClassLabel);
256 nameStepOper = new NewFileNameLocationStepOperator();
257 nameStepOper.setObjectName(SAMPLE2_CLASS_NAME);
258 nameStepOper.finish();
259 // check class is opened in Editor and then close all documents
260 new EditorOperator(SAMPLE2_FILE_NAME).closeAllDocuments();
263 /** Test Projects view
264 * - expand source hierarchy and find sample class (SampleClass1.java)
265 * - copy sample class and paste it to the same package
266 * - confirm refactoring dialog
267 * - verify creation of NewClass.java node
268 * - cut NewClass.java
269 * - paste it to another package
270 * - confirm refactoring dialog
271 * - delete NewClass.java node
273 public void testProjectsView() {
274 ProjectsTabOperator.invoke();
275 // needed for slower machines
276 JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N
277 SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME);
278 Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME);
279 Node sampleClass1Node = new Node(sample1Node, SAMPLE1_FILE_NAME);
280 // test pop-up menu actions
282 CopyAction copyAction = new CopyAction();
283 copyAction.perform(sampleClass1Node);
285 PasteAction pasteAction = new PasteAction();
287 String refactorItem = Bundle.getStringTrimmed("org.netbeans.modules.refactoring.spi.impl.Bundle", "LBL_Action");
289 String copyItem = Bundle.getStringTrimmed("org.netbeans.modules.refactoring.spi.impl.Bundle", "LBL_CopyAction");
290 new ActionNoBlock(null, pasteAction.getPopupPath()+"|"+refactorItem+" "+copyItem).perform(sample1Node);
292 String copyClassTitle = Bundle.getString("org.netbeans.modules.refactoring.java.ui.Bundle", "LBL_CopyClass");
293 NbDialogOperator copyClassDialog = new NbDialogOperator(copyClassTitle);
295 String refactorLabel = Bundle.getStringTrimmed("org.netbeans.modules.refactoring.spi.impl.Bundle", "CTL_Finish");
296 new JButtonOperator(copyClassDialog, refactorLabel).push();
297 // refactoring is done asynchronously => need to wait until dialog dismisses
298 copyClassDialog.waitClosed();
300 Node newClassNode = new Node(sample1Node, "SampleClass11"); // NOI18N
301 newClassNode.select();
303 CutAction cutAction = new CutAction();
304 cutAction.perform(newClassNode);
305 // package created by default when the sample project was created
306 Node sampleProjectPackage = new Node(sourcePackagesNode, SAMPLE_PROJECT_NAME.toLowerCase());
308 String moveItem = Bundle.getStringTrimmed("org.netbeans.modules.refactoring.spi.impl.Bundle", "LBL_MoveAction");
309 new ActionNoBlock(null, pasteAction.getPopupPath()+"|"+refactorItem+" "+moveItem).perform(sampleProjectPackage);
310 // confirm refactoring
312 String moveClassTitle = Bundle.getString("org.netbeans.modules.refactoring.java.ui.Bundle", "LBL_MoveClass");
313 NbDialogOperator moveClassDialog = new NbDialogOperator(moveClassTitle);
314 new JButtonOperator(moveClassDialog, refactorLabel).push();
315 // refactoring is done asynchronously => need to wait until dialog dismisses
316 moveClassDialog.waitClosed();
318 newClassNode = new Node(sampleProjectPackage, "SampleClass11"); // NOI18N
319 new DeleteAction().perform(newClassNode);
321 String safeDeleteTitle = Bundle.getString("org.netbeans.modules.refactoring.spi.impl.Bundle", "LBL_SafeDel"); // NOI18N
322 NbDialogOperator safeDeleteOper = new NbDialogOperator(safeDeleteTitle);
325 } catch (TimeoutExpiredException e) {
326 // It is "classpath scanning in progress" dialog, wait until it dismiss,
327 // and then wait for regular Safe Delete dialog
328 safeDeleteOper.waitClosed();
329 safeDeleteOper = new NbDialogOperator(safeDeleteTitle);
332 safeDeleteOper.waitClosed();
336 * - expand files hierarchy and find sample class (SampleClass1.java)
337 * and select main method node.
339 public void testFilesView() {
340 FilesTabOperator filesTabOper = FilesTabOperator.invoke();
341 // needed for slower machines
342 JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N
343 Node sourcePackagesNode = new Node(filesTabOper.getProjectNode(SAMPLE_PROJECT_NAME), "src"); // NOI18N
344 Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME); // NOI18N
345 Node sampleClass1Node = new Node(sample1Node, SAMPLE1_FILE_NAME);
346 // It is possible to test also pop-up menu actions as in testProjectsView, but
347 // it is redundant IMO
351 /** Test of DB module.
352 * It only tests whether the Databases node is present in Runtime view,
353 * Add Driver action is enabled on Drivers node and Connect action is available
354 * on default JDBC-ODBC Bridge node.
355 * - find Databases|Drivers node in Runtime tab
356 * - open and close Add Driver dialog from context menu on Drivers node
357 * - open and close Connect Using dialog on JDBC-ODBC Bridge node
359 public void testDb() {
361 String databasesLabel = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "NDN_Databases");
362 Node databasesNode = new Node(RuntimeTabOperator.invoke().getRootNode(), databasesLabel);
364 String waitNodeLabel = Bundle.getString("org.openide.nodes.Bundle", "LBL_WAIT");
365 // wait until the wait node dismiss and after that start waiting for Drivers node
366 // (see issue http://www.netbeans.org/issues/show_bug.cgi?id=43910 - Creation of
367 // children under Databases node is not properly synchronized)
369 databasesNode.waitChildNotPresent(waitNodeLabel);
370 } catch (JemmyException e) {
371 // Ignore and try to continue. Sometimes it happens "Please, wait" node
372 // is still available (maybe some threading issue).
373 log("Timeout expired: "+e.getMessage());
376 String driversLabel = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "NDN_Drivers");
377 Node driversNode = new Node(RuntimeTabOperator.invoke().getRootNode(), databasesLabel+"|"+driversLabel);
379 String addDriverItem = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "AddNewDriver");
380 // open a dialog to add a new JDBC driver
381 new ActionNoBlock(null, addDriverItem).perform(driversNode);
382 String addDriverTitle = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "AddDriverDialogTitle");
383 new NbDialogOperator(addDriverTitle).cancel();
385 // wait until the wait node dismiss and after that start waiting for JDBC_ODBC Bridge node
386 // (see issue http://www.netbeans.org/issues/show_bug.cgi?id=43910 - Creation of
387 // children under Databases node is not properly synchronized)
389 driversNode.waitChildNotPresent(waitNodeLabel);
390 } catch (JemmyException e) {
391 // Ignore and try to continue. Sometimes it happens "Please, wait" node
392 // is still available (maybe some threading issue).
393 log("Timeout expired: "+e.getMessage());
395 if(System.getProperty("os.name").toLowerCase().indexOf("mac") == -1) { // NOI18N
396 // node JDBC-ODBC Bridge should be present always but not on mac
397 Node jdbcOdbcNode = new Node(driversNode, "JDBC-ODBC Bridge"); // NOI18N
398 // "Connect Using ..."
399 String connectUsingItem = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "ConnectUsing");
400 // open a dialog to create a new connection
401 new ActionNoBlock(null, connectUsingItem).perform(jdbcOdbcNode);
402 String newDatabaseConnectionTitle = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "NewConnectionDialogTitle");
403 new NbDialogOperator(newDatabaseConnectionTitle).cancel();
408 * - open Help window from main menu (Help|Help Contents)
410 public void testHelp() {
411 // increasing time because opening of help window can last longer on slower machines
412 JemmyProperties.setCurrentTimeout("JMenuOperator.PushMenuTimeout", 60000);
413 // open "Help|Contents"
414 HelpOperator helpOper = HelpOperator.invoke();
415 // check help window opened
416 // title is "Help - All"
421 * - close Welcome screen to not harm menu actions
422 * - open and close New Project wizard (main menu item File|New Project...)
423 * - open and close Javadoc Index Search top component (main menu item Tools|Javadoc Index Search)
425 public void testMainMenu() {
426 // close Welcome screen to not harm menu actions
428 String welcomeTitle = Bundle.getString("org.netbeans.modules.welcome.Bundle", "LBL_Tab_Title");
429 new TopComponentOperator(welcomeTitle).close();
430 // open and close New Project wizard
431 int oldDispatchingModel = JemmyProperties.getCurrentDispatchingModel();
433 NewProjectWizardOperator.invoke().close();
434 } catch (TimeoutExpiredException e) {
435 // if not succed try it second time in Robot mode
436 // push Escape key to ensure there is no open menu
437 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_ESCAPE);
438 JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
439 NewProjectWizardOperator.invoke().close();
441 // set previous dispatching model
442 JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel);
445 // open Tools|Javadoc Index Search
446 String toolsItem = Bundle.getStringTrimmed("org.netbeans.core.ui.resources.Bundle", "Menu/Tools"); // NOI18N
447 String javadocItem = Bundle.getStringTrimmed("org.netbeans.modules.javadoc.search.Bundle", "CTL_SEARCH_MenuItem");
448 new Action(toolsItem+"|"+javadocItem, null).perform();
449 // "Javadoc Index Search"
450 String javadocTitle = Bundle.getString("org.netbeans.modules.javadoc.search.Bundle", "CTL_SEARCH_WindowTitle");
451 new TopComponentOperator(javadocTitle).close();
455 /** Test global shortcuts.
456 * - open and close new file wizard (CTRL+N)
457 * - open and close Javadoc Index Search top component (Shift+F1)
458 * - open and close new breakpoint dialog (Ctrl+Shift+F8)
460 public void testShortcuts() {
461 // test global shortcuts
462 // open new wizard (Ctrl+N)
463 Node node = new SourcePackagesNode(SAMPLE_PROJECT_NAME);
464 // push Escape key to ensure there is no thing blocking shortcut execution
465 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_ESCAPE);
466 NewFileAction newFileAction = new NewFileAction();
468 newFileAction.performShortcut(node);
469 new NewFileWizardOperator().close();
470 // On some linux it may happen autorepeat is activated and it
471 // opens dialog multiple times. So, we need to close all modal dialogs.
472 // See issue http://www.netbeans.org/issues/show_bug.cgi?id=56672.
474 } catch (TimeoutExpiredException e) {
475 // need to be realiable test => repeat action once more to be sure it is problem in IDE
476 // this time use events instead of Robot
478 MainWindowOperator.getDefault().pushKey(
479 newFileAction.getKeyStrokes()[0].getKeyCode(),
480 newFileAction.getKeyStrokes()[0].getModifiers());
481 new NewFileWizardOperator().close();
483 // open Javadoc Index Search (Shift+F1)
484 // "Javadoc Index Search"
485 String javadocTitle = Bundle.getString("org.netbeans.modules.javadoc.search.Bundle",
486 "CTL_SEARCH_WindowTitle");
487 Action searchAction = new Action(null, null, KeyStroke.getKeyStroke(KeyEvent.VK_F1, KeyEvent.SHIFT_MASK));
489 searchAction.perform(MainWindowOperator.getDefault());
490 new TopComponentOperator(javadocTitle).close();
491 } catch (TimeoutExpiredException e) {
492 // need to be realiable test => repeat action once more to be sure it is problem in IDE
493 // this time use events instead of Robot
494 MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F1, KeyEvent.SHIFT_MASK);
495 new TopComponentOperator(javadocTitle).close();
497 // open new breakpoint dialog (Ctrl+Shift+F8)
498 String newBreakpointTitle = Bundle.getString("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Breakpoint_Title");
499 NewBreakpointAction newBreakpointAction = new NewBreakpointAction();
501 newBreakpointAction.performShortcut(MainWindowOperator.getDefault());
502 new NbDialogOperator(newBreakpointTitle).close();
503 // On some linux it may happen autorepeat is activated and it
504 // opens dialog multiple times. So, we need to close all modal dialogs.
505 // See issue http://www.netbeans.org/issues/show_bug.cgi?id=56672.
507 } catch (TimeoutExpiredException e) {
508 // need to be realiable test => repeat action once more to be sure it is problem in IDE
509 // this time use events instead of Robot
510 MainWindowOperator.getDefault().pushKey(
511 newBreakpointAction.getKeyStrokes()[0].getKeyCode(),
512 newBreakpointAction.getKeyStrokes()[0].getModifiers());
513 new NbDialogOperator(newBreakpointTitle).close();
517 /** Test Source Editor
518 * - opens sample class in Editor (context menu Open on the node)
519 * - type abbreviation 'sout' into main method and then 'Hello'
520 * - verify it is written 'System.out.println("Hello");'
521 * - select the text and call copy from editor's context menu
522 * - insert dummy text at next line , select it and paste the text in the clipboard
523 * - select second 'Hello' and delete it by context menu
524 * - insert 'Good bye' instead
525 * - select fourth line, cut it and paste it at line 3
527 public void testEditor() {
528 // open sample file in Editor
529 SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME);
530 Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME);
531 JavaNode sampleClass1Node = new JavaNode(sample1Node, SAMPLE1_FILE_NAME);
532 sampleClass1Node.open();
533 // find open file in editor
534 EditorOperator eo = new EditorOperator(SAMPLE1_FILE_NAME);
535 eo.setCaretPosition("public static void main", true);
536 int insertLine = eo.getLineNumber()+2;
537 eo.insert("\n", insertLine, 1); // NOI18N
538 // Need to disable verification because shortcut "sout" is replaced
539 // by "System.out.println("");" and "sout" is not found in Editor
540 eo.setCaretPositionToLine(insertLine);
541 eo.txtEditorPane().setVerification(false);
542 eo.txtEditorPane().typeText("sout"); // NOI18N
543 eo.txtEditorPane().typeKey('\t');
544 eo.txtEditorPane().setVerification(true);
545 eo.insert("Hello"); // NOI18N
546 //eo.insert("System.out.println(\"Hello\");\n", insertLine+1, 1); // NOI18N
547 final String textToCopy = "System.out.println(\"Hello\");"; // NOI18N
548 eo.select(textToCopy);
549 int oldDispatchingModel = JemmyProperties.getCurrentDispatchingModel();
551 CopyAction copyAction = new CopyAction();
553 copyAction.perform(eo);
554 } catch (TimeoutExpiredException e) {
555 // if not succed try it second time in Robot mode
556 JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
557 copyAction.perform(eo);
559 // set previous dispatching model
560 JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel);
562 // wait until clipboard contains text to copy
564 new Waiter(new Waitable() {
565 public Object actionProduced(Object obj) {
567 String text = Toolkit.getDefaultToolkit().getSystemClipboard().
568 getContents(null).getTransferData(DataFlavor.stringFlavor).toString();
569 return textToCopy.equals(text) ? Boolean.TRUE:null;
570 } catch (UnsupportedFlavorException e) {
571 // The following exception can be thrown when clipboard is empty.
572 // java.awt.datatransfer.UnsupportedFlavorException: Unicode String
573 // at org.openide.util.datatransfer.ExTransferable$Empty.getTransferData(ExTransferable.java:461)
574 // Ignore this exception.
576 } catch (IOException ioe) {
577 throw new JemmyException("Failed getting clipboard content.", ioe);
580 public String getDescription() {
581 return("Clipboard contains "+textToCopy); // NOI18N
584 } catch (Exception ie) {
585 throw new JemmyException("Interrupted.", ie);
587 eo.insert("int xxxx;\n", insertLine+1, 1); // NOI18N
588 eo.select("int xxxx;"); // NOI18N
589 PasteAction pasteAction = new PasteAction();
591 pasteAction.perform(eo);
592 } catch (TimeoutExpiredException e) {
593 // if not succed try it second time in Robot mode
594 JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
595 pasteAction.perform(eo);
597 // set previous dispatching model
598 JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel);
600 eo.select("Hello", 1); // NOI18N
602 DeleteAction deleteAction = new DeleteAction();
603 deleteAction.performMenu(eo);
604 // wait Hello is deleted
605 eo.txtEditorPane().waitText("System.out.println(\"\");"); // NOI18N
606 eo.insert("Good bye"); // NOI18N
610 CutAction cutAction = new CutAction();
612 cutAction.perform(eo);
613 } catch (TimeoutExpiredException e) {
614 // if not succed try it second time in Robot mode
615 JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
616 cutAction.perform(eo);
618 // set previous dispatching model
619 JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel);
621 // need to wait a little until editor content is refreshed after cut action
622 new EventTool().waitNoEvent(500);
623 // select from column 1 to 2 at line 3
626 pasteAction.perform(eo);
627 } catch (TimeoutExpiredException e) {
628 // if not succed try it second time in Robot mode
629 JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
630 pasteAction.perform(eo);
632 // set previous dispatching model
633 JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel);
637 /** Test build and run.
638 * - select sample class node and call "Build|Compile "SampleClass1.java"" main menu item
639 * - wait until compilation finishes (track status bar)
640 * - select sample class node and call "Run|Run File|Run "SampleClass1.java"" main menu item
641 * - wait until run finishes
642 * - from context menu set sample project as main project
643 * - call "Build|Build Main Project" main menu item
644 * - wait until build finishes
645 * - call "Run|Run Main Project" main menu item
646 * - wait until run finishes
648 public void testBuildAndRun() {
649 SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME);
650 Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME);
651 JavaNode sampleClass1Node = new JavaNode(sample1Node, SAMPLE1_FILE_NAME);
652 // increase timeout to 60 seconds
653 MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 60000);
654 // start to track Main Window status bar
655 MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer();
657 // call Build|Compile main menu item
658 new CompileAction().perform(sampleClass1Node);
659 // "SampleProject (compile-single)"
660 String compileSingleTarget = Bundle.getString(
661 "org.apache.tools.ant.module.run.Bundle",
662 "TITLE_output_target",
663 new Object[] {SAMPLE_PROJECT_NAME, null, "compile-single"}); // NOI18N
664 // "Finished building SampleProject (compile-single)"
665 String finishedCompileSingleLabel = Bundle.getString(
666 "org.apache.tools.ant.module.run.Bundle",
667 "FMT_finished_target_status",
668 new String[] {compileSingleTarget});
669 // wait message "Finished building SampleProject (compile-single)"
670 stt.waitText(finishedCompileSingleLabel);
673 String runItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject");
675 String runOtherItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject/RunOther");
677 String runFileItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle",
678 "LBL_RunSingleAction_Name",
679 new Object[] {new Integer(1), SAMPLE1_FILE_NAME});
680 // call "Run|Run File|Run "SampleClass1.java""
681 new Action(runItem+"|"+runOtherItem+"|"+runFileItem, null).perform(sampleClass1Node);
682 // "SampleProject (run-single)"
683 String runSingleTarget = Bundle.getString(