|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package validation; import java.awt.Component; import java.awt.Toolkit; import java.awt.Window; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.KeyEvent; import java.io.File; import java.io.IOException; import javax.swing.JComponent; import junit.textui.TestRunner; import org.netbeans.jellytools.Bundle; import org.netbeans.jellytools.EditorOperator; import org.netbeans.jellytools.FilesTabOperator; import org.netbeans.jellytools.HelpOperator; import org.netbeans.jellytools.JellyTestCase; import org.netbeans.jellytools.MainWindowOperator; import org.netbeans.jellytools.NbDialogOperator; import org.netbeans.jellytools.NewFileNameLocationStepOperator; import org.netbeans.jellytools.NewFileWizardOperator; import org.netbeans.jellytools.NewProjectNameLocationStepOperator; import org.netbeans.jellytools.NewProjectWizardOperator; import org.netbeans.jellytools.OptionsOperator; import org.netbeans.jellytools.OutputTabOperator; import org.netbeans.jellytools.ProjectsTabOperator; import org.netbeans.jellytools.RuntimeTabOperator; import org.netbeans.jellytools.TopComponentOperator; import org.netbeans.jellytools.WizardOperator; import org.netbeans.jellytools.actions.Action; import org.netbeans.jellytools.actions.ActionNoBlock; import org.netbeans.jellytools.actions.CompileAction; import org.netbeans.jellytools.actions.CopyAction; import org.netbeans.jellytools.actions.CutAction; import org.netbeans.jellytools.actions.DeleteAction; import org.netbeans.jellytools.actions.NewFileAction; import org.netbeans.jellytools.actions.OpenAction; import org.netbeans.jellytools.actions.PasteAction; import org.netbeans.jellytools.actions.ViewAction; import org.netbeans.jellytools.modules.vcscore.VCSOutputOperator; import org.netbeans.jellytools.modules.vcscore.VersioningManagerOperator; import org.netbeans.jellytools.modules.vcsgeneric.actions.CVSUpdateAction; import org.netbeans.jellytools.modules.vcsgeneric.wizard.VCSProfileOperator; import org.netbeans.jellytools.modules.vcsgeneric.wizard.VCSProfileStepOperator; import org.netbeans.jellytools.nodes.JavaNode; import org.netbeans.jellytools.nodes.Node; import org.netbeans.jellytools.nodes.SourcePackagesNode; import org.netbeans.jellytools.properties.Property; import org.netbeans.jellytools.properties.PropertySheetOperator; import org.netbeans.jemmy.ComponentChooser; import org.netbeans.jemmy.EventTool; import org.netbeans.jemmy.JemmyException; import org.netbeans.jemmy.JemmyProperties; import org.netbeans.jemmy.TestOut; import org.netbeans.jemmy.TimeoutExpiredException; import org.netbeans.jemmy.Waitable; import org.netbeans.jemmy.Waiter; import org.netbeans.jemmy.operators.JButtonOperator; import org.netbeans.jemmy.operators.JCheckBoxOperator; import org.netbeans.jemmy.operators.JComboBoxOperator; import org.netbeans.jemmy.operators.JDialogOperator; import org.netbeans.jemmy.operators.JLabelOperator; import org.netbeans.jemmy.operators.JListOperator; import org.netbeans.jemmy.operators.JTableOperator; import org.netbeans.jemmy.operators.JTextFieldOperator; import org.netbeans.jemmy.operators.JTreeOperator; import org.netbeans.jemmy.operators.Operator; import org.netbeans.jemmy.operators.WindowOperator; import org.netbeans.jemmy.util.PNGEncoder; import org.netbeans.junit.NbTestSuite; /** * Overall validation suite for IDE. * * @author Jiri.Skrivanek@sun.com */ public class IDEValidation extends JellyTestCase { /** Need to be defined because of JUnit */ public IDEValidation(String name) { super(name); } public static NbTestSuite suite() { NbTestSuite suite = new NbTestSuite(); suite.addTest(new IDEValidation("testMainMenu")); suite.addTest(new IDEValidation("testHelp")); suite.addTest(new IDEValidation("testOptions")); suite.addTest(new IDEValidation("testNewProject")); // sample project must exist before testShortcuts suite.addTest(new IDEValidation("testShortcuts")); suite.addTest(new IDEValidation("testNewFile")); suite.addTest(new IDEValidation("testCVS")); suite.addTest(new IDEValidation("testProjectsView")); suite.addTest(new IDEValidation("testFilesView")); suite.addTest(new IDEValidation("testEditor")); suite.addTest(new IDEValidation("testBuildAndRun")); suite.addTest(new IDEValidation("testDebugging")); suite.addTest(new IDEValidation("testXML")); suite.addTest(new IDEValidation("testUpdateCenter")); suite.addTest(new IDEValidation("testDb")); return suite; } /** Use for execution inside IDE */ public static void main(java.lang.String[] args) { // run whole suite TestRunner.run(suite()); // run only selected test case //junit.textui.TestRunner.run(new IDEValidation("testMainMenu")); } public void setUp() { System.out.println("######## "+getName()+" #######"); // Close help window if any - it should not stay open between test cases. // Otherwise it can break next tests. closeHelpWindow(); } public void tearDown() { } // name of class created from template and used in tests private static final String JAVA_CLASS_NAME = "Main"; // NOI18N // name of sample frame created and used in tests private static final String SAMPLE_FRAME_NAME = "SampleFrame"; // NOI18N // name of sample project private static final String SAMPLE_PROJECT_NAME = "SampleProject"; // NOI18N // name of first sample package private static final String SAMPLE1_PACKAGE_NAME = "sample1"; //NOI18N // name of second sample package private static final String SAMPLE2_PACKAGE_NAME = "sample2"; //NOI18N // name of sample class private static final String SAMPLE1_CLASS_NAME = "SampleClass1"; // NOI18N // name of sample file private static final String SAMPLE1_FILE_NAME = SAMPLE1_CLASS_NAME+".java"; // NOI18N /** Test creation of java project. * - open New Project wizard from main menu (File|New Project) * - select Java Application project from Standard category * - in the next panel type project name and project location in * - finish the wizard * - wait until scanning of java files is finished */ public void testNewProject() { NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke(); // "Standard" String standardLabel = Bundle.getString("org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", "Templates/Project/Standard"); npwo.selectCategory(standardLabel); // "Java Application" String javaApplicationLabel = Bundle.getString("org.netbeans.modules.java.j2seproject.ui.wizards.Bundle", "Templates/Project/Standard/emptyJ2SE.xml"); npwo.selectProject(javaApplicationLabel); npwo.next(); NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator(); npnlso.txtProjectName().setText(SAMPLE_PROJECT_NAME); npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N npnlso.finish(); // "Scanning Project Classpaths" String titleScanning = Bundle.getString("org.netbeans.modules.javacore.Bundle", "TXT_ApplyingPathsTitle"); NbDialogOperator scanningDialogOper = new NbDialogOperator(titleScanning); // scanning can last for a long time => wait max. 3 minutes scanningDialogOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 180000); scanningDialogOper.waitClosed(); // wait project appear in projects view new ProjectsTabOperator().getProjectRootNode(SAMPLE_PROJECT_NAME); } /** Test new file wizard. * - open New File wizard from main menu (File|New File) * - select sample project as target * - select Java Classes|Java Package file type * - in the next panel type package name in * - finish the wizard * - open New File wizard from context menu on created package node (New|File) * - select Java Classes|Java Main Class file type * - in the next panel type class name in * - finish the wizard * - check class is open in editor and close all opened documents */ public void testNewFile() { // create a new package // "Java Classes" String javaClassesLabel = Bundle.getString("org.netbeans.modules.java.Bundle", "Templates/Classes"); // "Java Package" String packageLabel = Bundle.getString("org.netbeans.modules.java.Bundle", "Templates/Classes/Package"); NewFileWizardOperator.create(SAMPLE_PROJECT_NAME, javaClassesLabel, packageLabel, null, SAMPLE1_PACKAGE_NAME); // wait package node is created Node sample1Node = new Node(new SourcePackagesNode(SAMPLE_PROJECT_NAME), SAMPLE1_PACKAGE_NAME); // create a new class // "Java Main Class" String mainClassLabel = Bundle.getString("org.netbeans.modules.java.Bundle", "Templates/Classes/Main.java"); // NOI18N NewFileWizardOperator.invoke(sample1Node, javaClassesLabel, mainClassLabel); NewFileNameLocationStepOperator nameStepOper = new NewFileNameLocationStepOperator(); nameStepOper.setObjectName(SAMPLE1_CLASS_NAME); nameStepOper.finish(); // check class is opened in Editor and then close all documents new EditorOperator(SAMPLE1_FILE_NAME).closeAllDocuments(); } /** Test Projects view * - expand java elements hierarchy of sample class (SampleClass1.java|class SampleClass1|Methods|main) * and select main method node. * - copy sample class and paste it to the same package * - verify creation of SampleClass1_1.java node * - cut SampleClass1_1.java * - paste it to another package * - cancel refactoring dialog * - delete SampleClass1_1.java node */ public void testProjectsView() { ProjectsTabOperator projectsTabOper = ProjectsTabOperator.invoke(); // needed for slower machines JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N // "class" String classLabel = Bundle.getStringTrimmed("org.openide.src.nodes.Bundle", "SHORT_classElementFormat"); // "Methods" String methodsLabel = Bundle.getString("org.openide.src.nodes.Bundle", "Methods"); SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME); Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME); Node sampleClass1Node = new Node(sample1Node, SAMPLE1_FILE_NAME); // expand class members new Node(sampleClass1Node, classLabel+SAMPLE1_CLASS_NAME+"|"+methodsLabel+"|main").select(); // NOI18N // test pop-up menu actions // "Copy" CopyAction copyAction = new CopyAction(); copyAction.perform(sampleClass1Node); // "Paste" PasteAction pasteAction = new PasteAction(); pasteAction.perform(sample1Node); Node sampleClass1_1Node = new Node(sample1Node, "_1"); // NOI18N sampleClass1_1Node.select(); // "Cut" CutAction cutAction = new CutAction(); cutAction.perform(sampleClass1_1Node); // package created by default when the sample project was created Node sampleProjectPackage = new Node(sourcePackagesNode, SAMPLE_PROJECT_NAME.toLowerCase()); new ActionNoBlock(null, pasteAction.getPopupPath()).perform(sampleProjectPackage); // cancel refactoring // "Refactor Code for Moved Class(es)" String refactorTitle = Bundle.getString("org.netbeans.modules.refactoring.ui.Bundle", "LBL_RefactorClassAfterMove"); new NbDialogOperator(refactorTitle).cancel(); // "Delete" sampleClass1_1Node = new Node(sampleProjectPackage, "_1"); // NOI18N DeleteAction deleteAction = new DeleteAction(); deleteAction.perform(sampleClass1_1Node); // "Confirm Object Deletion" String confirmTitle = Bundle.getString("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle"); // NOI18N new NbDialogOperator(confirmTitle).yes(); } /** Test Files view * - expand java elements hierarchy of sample class (SampleClass1.java|class SampleClass1|Methods|main) * and select main method node. */ public void testFilesView() { FilesTabOperator filesTabOper = FilesTabOperator.invoke(); // needed for slower machines JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N // "class" String classLabel = Bundle.getStringTrimmed("org.openide.src.nodes.Bundle", "SHORT_classElementFormat"); // "Methods" String methodsLabel = Bundle.getString("org.openide.src.nodes.Bundle", "Methods"); Node sourcePackagesNode = new Node(filesTabOper.getProjectNode(SAMPLE_PROJECT_NAME), "src"); // NOI18N Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME); // NOI18N Node sampleClass1Node = new Node(sample1Node, SAMPLE1_FILE_NAME); // expand class members new Node(sampleClass1Node, classLabel+SAMPLE1_CLASS_NAME+"|"+methodsLabel+"|main").select(); // NOI18N // It is possible to test also pop-up menu actions as in testProjectsView, but // it is redundant IMO } /** Test of DB module. * It only tests whether the Databases node is present in Runtime view, * Add Driver action is enabled on Drivers node and Connect action is available * on default JDBC-ODBC Bridge node. * - find Databases|Drivers node in Runtime tab * - open and close Add Driver dialog from context menu on Drivers node * - open and close Connect Using dialog on JDBC-ODBC Bridge node */ public void testDb() { // "Databases" String databasesLabel = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "NDN_Databases"); // "Drivers" String driversLabel = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "NDN_Drivers"); Node driversNode = new Node(RuntimeTabOperator.invoke().getRootNode(), databasesLabel+"|"+driversLabel); // "Add Driver ..." String addDriverItem = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "AddNewDriver"); // open a dialog to add a new JDBC driver new ActionNoBlock(null, addDriverItem).perform(driversNode); String addDriverTitle = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "AddDriverDialogTitle"); new NbDialogOperator(addDriverTitle).cancel(); // node JDBC-ODBC Bridge should be present always Node jdbcOdbcNode = new Node(driversNode, "JDBC-ODBC Bridge"); // NOI18N // "Connect Using ..." String connectUsingItem = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "ConnectUsing"); // open a dialog to create a new connection new ActionNoBlock(null, connectUsingItem).perform(jdbcOdbcNode); String newDatabaseConnectionTitle = Bundle.getString("org.netbeans.modules.db.resources.Bundle", "NewConnectionDialogTitle"); new NbDialogOperator(newDatabaseConnectionTitle).cancel(); } /** Test Help * - open Help window from main menu (Help|Help Contents) */ public void testHelp() { // increasing time because opening of help window can last longer on slower machines JemmyProperties.setCurrentTimeout("JMenuOperator.PushMenuTimeout", 60000); // open "Help|Contents" HelpOperator helpOper = HelpOperator.invoke(); // check help window opened // title is "Help - All" helpOper.close(); } /** Test Main Menu * - open and close About dialog (main menu item Help|About) * - open and close Javadoc Index Search top component (main menu item View|Javadoc Index Search) */ public void testMainMenu() { // open About dialog String helpItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Help"); String aboutItem = Bundle.getStringTrimmed("org.netbeans.core.actions.Bundle", "About"); new ActionNoBlock(helpItem+"|"+aboutItem, null).perform(); String aboutTitle = Bundle.getString("org.netbeans.core.Bundle", "CTL_About_Title"); new NbDialogOperator(aboutTitle).close(); // open Window|Javadoc Index Search String viewItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // NOI18N String javadocItem = Bundle.getStringTrimmed("org.netbeans.modules.javadoc.search.Bundle", "CTL_SEARCH_MenuItem"); new Action(viewItem+"|"+javadocItem, null).perform(); // "Javadoc Index Search" String javadocTitle = Bundle.getString("org.netbeans.modules.javadoc.search.Bundle", "CTL_SEARCH_WindowTitle"); new TopComponentOperator(javadocTitle).close(); } /** Test global shortcuts. * - open and close new file wizard (CTRL+N) * - open and close Javadoc Index Search top component (Shift+F1) * - open and close new breakpoint dialog (Ctrl+Shift+F8) */ public void testShortcuts() { // "Javadoc Index Search" String javadocTitle = Bundle.getString("org.netbeans.modules.javadoc.search.Bundle", "CTL_SEARCH_WindowTitle"); // test global shortcuts // open new wizard (Ctrl+N) Node node = new SourcePackagesNode(SAMPLE_PROJECT_NAME); // push Escape key to ensure there is no thing blocking shortcut execution MainWindowOperator.getDefault().pushKey(KeyEvent.VK_ESCAPE); NewFileAction newFileAction = new NewFileAction(); try { newFileAction.performShortcut(node); new NewFileWizardOperator().close(); } catch (TimeoutExpiredException e) { // need to be realiable test => repeat action once more to be sure it is problem in IDE // this time use events instead of Robot node.select(); MainWindowOperator.getDefault().pushKey(KeyEvent.VK_N, KeyEvent.CTRL_MASK); new NewFileWizardOperator().close(); } // open Javadoc Index Search (Shift+F1) Action searchAction = new Action(null, null, new Action.Shortcut(KeyEvent.VK_F1, KeyEvent.SHIFT_MASK)); try { searchAction.perform(MainWindowOperator.getDefault()); new TopComponentOperator(javadocTitle).close(); } catch (TimeoutExpiredException e) { // need to be realiable test => repeat action once more to be sure it is problem in IDE // this time use events instead of Robot MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F1, KeyEvent.SHIFT_MASK); new TopComponentOperator(javadocTitle).close(); } // open new breakpoint dialog (Ctrl+Shift+F8) String newBreakpointTitle = Bundle.getString("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Breakpoint_Title"); ActionNoBlock breakpointAction = new ActionNoBlock(null, null, new Action.Shortcut(KeyEvent.VK_F8, KeyEvent.SHIFT_MASK|KeyEvent.CTRL_MASK)); try { breakpointAction.perform(MainWindowOperator.getDefault()); new NbDialogOperator(newBreakpointTitle).close(); } catch (TimeoutExpiredException e) { // need to be realiable test => repeat action once more to be sure it is problem in IDE // this time use events instead of Robot MainWindowOperator.getDefault().pushKey(KeyEvent.VK_F8, KeyEvent.SHIFT_MASK|KeyEvent.CTRL_MASK); new NbDialogOperator(newBreakpointTitle).close(); } } /** Test Source Editor * - opens sample class in Editor (context menu Open on the node) * - type abbreviation 'sout' at line 23 and then 'Hello' * - verify it is written 'System.out.println("Hello");' * - select the text and call copy from editor's context menu * - insert dummy text at line 24 , select it and paste the text in the clipboard * - select second 'Hello' and delete it by context menu * - insert 'Good bye' instead * - select fourth line, cut it and paste it at line 3 */ public void testEditor() { // open sample file in Editor SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME); Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME); JavaNode sampleClass1Node = new JavaNode(sample1Node, SAMPLE1_FILE_NAME); sampleClass1Node.open(); // find open file in editor EditorOperator eo = new EditorOperator(SAMPLE1_FILE_NAME); eo.insert("\n", 23, 1); // NOI18N // Need to disable verification because shortcut "sout" is replaced // by "System.out.println("");" and "sout" is not found in Editor eo.setCaretPositionToLine(23); eo.txtEditorPane().setVerification(false); eo.txtEditorPane().typeText("sout "); // NOI18N eo.txtEditorPane().setVerification(true); eo.insert("Hello"); // NOI18N //eo.insert("System.out.println(\"Hello\");\n", 24, 1); // NOI18N final String textToCopy = "System.out.println(\"Hello\");"; // NOI18N eo.select(textToCopy); int oldDispatchingModel = JemmyProperties.getCurrentDispatchingModel(); // "Copy" CopyAction copyAction = new CopyAction(); try { copyAction.perform(eo); } catch (TimeoutExpiredException e) { // if not succed try it second time in Robot mode JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK); copyAction.perform(eo); } finally { // set previous dispatching model JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel); } // wait until clipboard contains text to copy try { new Waiter(new Waitable() { public Object actionProduced(Object obj) { try { String text = Toolkit.getDefaultToolkit().getSystemClipboard(). getContents(null).getTransferData(DataFlavor.stringFlavor).toString(); return textToCopy.equals(text) ? Boolean.TRUE:null; } catch (UnsupportedFlavorException e) { // The following exception can be thrown when clipboard is empty. // java.awt.datatransfer.UnsupportedFlavorException: Unicode String // at org.openide.util.datatransfer.ExTransferable$Empty.getTransferData(ExTransferable.java:461) // Ignore this exception. return null; } catch (IOException ioe) { throw new JemmyException("Failed getting clipboard content.", ioe); } } public String getDescription() { return("Clipboard contains "+textToCopy); // NOI18N } }).waitAction(null); } catch (Exception ie) { throw new JemmyException("Interrupted.", ie); } eo.insert("int xxxx;\n", 24, 1); // NOI18N eo.select("int xxxx;"); // NOI18N PasteAction pasteAction = new PasteAction(); try { pasteAction.perform(eo); } catch (TimeoutExpiredException e) { // if not succed try it second time in Robot mode JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK); pasteAction.perform(eo); } finally { // set previous dispatching model JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel); } eo.select("Hello", 1); // NOI18N // "Delete" DeleteAction deleteAction = new DeleteAction(); deleteAction.performShortcut(eo); // wait Hello is deleted eo.txtEditorPane().waitText("System.out.println(\"\");"); // NOI18N eo.insert("Good bye"); // NOI18N // test cut action eo.select(4); // "Cut" CutAction cutAction = new CutAction(); try { cutAction.perform(eo); } catch (TimeoutExpiredException e) { // if not succed try it second time in Robot mode JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK); cutAction.perform(eo); } finally { // set previous dispatching model JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel); } // need to wait a little until editor content is refreshed after cut action new EventTool().waitNoEvent(500); // select from column 1 to 2 at line 3 eo.select(3, 1, 2); try { pasteAction.perform(eo); } catch (TimeoutExpiredException e) { // if not succed try it second time in Robot mode JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK); pasteAction.perform(eo); } finally { // set previous dispatching model JemmyProperties.setCurrentDispatchingModel(oldDispatchingModel); } } /** Test build and run. * - select sample class node and call "Build|Compile "SampleClass1.java"" main menu item * - wait until compilation finishes (track status bar) * - select sample class node and call "Run|Run Other|Run "SampleClass1.java"" main menu item * - wait until run finishes * - from context menu set sample project as main project * - call "Build|Build Main Project" main menu item * - wait until build finishes * - call "Run|Run Main Project" main menu item * - wait until run finishes */ public void testBuildAndRun() { SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME); Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME); JavaNode sampleClass1Node = new JavaNode(sample1Node, SAMPLE1_FILE_NAME); // increase timeout to 60 seconds MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 60000); // start to track Main Window status bar MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer(); stt.start(); // call Build|Compile main menu item new CompileAction().perform(sampleClass1Node); /* We cannot get this bundle - ti is probably loaded by a different classLoader // "Finished building SampleProject (run)" String finishedLabel = Bundle.getString("org.apache.tools.ant.module.bridge.impl.Bundle", "FMT_finished_target_status", new String[] {SAMPLE_PROJECT_NAME}); */ // wait message "Building SampleProject (compile-single)..." stt.waitText("compile-single", true); // NOI18N // wait message "Finished building SampleProject (compile-single)" stt.waitText("compile-single", true); // NOI18N // "Run" String runItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject"); // "Run Other" String runOtherItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject/RunOther"); // "Run File" String runFileItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_RunSingleAction_Name", new Object[] {new Integer(1), SAMPLE1_FILE_NAME}); // call "Run|Run Other|Run "SampleClass1.java"" new Action(runItem+"|"+runOtherItem+"|"+runFileItem, null).perform(sampleClass1Node); // wait message "Building SampleProject (run-single)..." stt.waitText("run-single", true); // NOI18N // wait message "Finished building SampleProject (run-single)" stt.waitText("run-single", true); // NOI18N // check Hello and Good bye was printed out to the output window OutputTabOperator outputOper = new OutputTabOperator("run-single"); //NOI18N outputOper.waitText("Hello"); //NOI18N outputOper.waitText("Good bye"); //NOI18N // "Set as Main Project" String setAsMainProjectItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_SetAsMainProjectAction_Name"); new Action(null, setAsMainProjectItem).perform(new ProjectsTabOperator().getProjectRootNode(SAMPLE_PROJECT_NAME)); // "Build" String buildItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Build"); // "Build Main Project" String buildMainProjectItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_BuildMainProjectAction_Name"); // call "Build|Build Main Project" main menu item new Action(buildItem+"|"+buildMainProjectItem, null).perform(); // wait message "Building SampleProject (jar)..." stt.waitText("jar", true); // NOI18N // wait message "Finished building SampleProject (jar)" stt.waitText("jar", true); // NOI18N // Run Main Project String runMainProjectItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_RunMainProjectAction_Name"); // call "Run|Run Main Project" main menu item new Action(runItem+"|"+runMainProjectItem, null).perform(); // wait message "Building SampleProject (run)..." stt.waitText("run", true); // NOI18N // wait message "Finished building SampleProject (run)" stt.waitText("run", true); // NOI18N stt.stop(); } /** Test Debugging * - find sample class in editor * - select text 'System.out.println("Hello");' and push Shift+F8 to toggle breakpoint * - select text 'System.out.println("Good bye");' and call 'Toggle Breakpoint" context menu item * - run debugger from main menu ("Run "SampleClass1.java" in Debugger") * - wait until first breakpoint is reached and call Continue from main menu * - wait until second breakpoint is reached and check 'Hello' is printed to output * - finish debugger by main menu action (Finish Debugger Session) * - delete sample class */ public void testDebugging() throws Throwable { // "Run" String runItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject"); try { // find sample file in Editor EditorOperator eo = new EditorOperator(SAMPLE1_FILE_NAME); // if file not contains brpText from previous test cases, insert it String brpText = "System.out.println(\"Hello\");"; // NOI18N if(!eo.contains(brpText)) { eo.insert(brpText+"\n", 23, 1); } eo.select(brpText); // toggle breakpoint via Shift+F8 eo.pushKey(KeyEvent.VK_F8, KeyEvent.CTRL_MASK); // wait breakpoint established new Waiter(new Waitable() { public Object actionProduced(Object editorOper) { return ((EditorOperator)editorOper).getAnnotations(23).length == 1 ? Boolean.TRUE : null; } public String getDescription() { return("Wait breakpoint established on line 23"); // NOI18N } }).waitAction(eo); // if file not contains second brpText from previous test cases, insert it brpText = "System.out.println(\"Good bye\");"; // NOI18N if(!eo.contains(brpText)) { eo.insert(brpText+"\n", 24, 1); } eo.select(brpText); // toggle breakpoint via pop-up menu // "Toggle Breakpoint" String toggleBrakpointItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Toggle_breakpoint"); // clickForPopup(0, 0) used in the past sometimes caused that menu // was opened outside editor area because editor roll up after // text was selected new Action(null, toggleBrakpointItem).perform(eo.txtEditorPane()); // wait second breakpoint established new Waiter(new Waitable() { public Object actionProduced(Object editorOper) { return ((EditorOperator)editorOper).getAnnotations(24).length == 1 ? Boolean.TRUE : null; } public String getDescription() { return("Wait breakpoint established on line 24"); // NOI18N } }).waitAction(eo); // start to track Main Window status bar MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer(); stt.start(); // start debugging // "Run Other" String runOtherItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Menu/RunProject/RunOther"); // "Debug "SampleClass1.java"" String debugItem = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.actions.Bundle", "LBL_DebugSingleAction_Name", new Object[] {new Integer(1), SAMPLE1_FILE_NAME}); new Action(runItem+"|"+runOtherItem+"|"+debugItem, null).perform(); // check the first breakpoint reached // wait status text "Thread main stopped at SampleClass1.java:23" // increase timeout to 60 seconds MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 60000); stt.waitText("23"); // NOI18N // continue debugging // "Continue" String continueItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_Continue_action_name"); new Action(runItem+"|"+continueItem, null).perform(); // check the second breakpoint reached // wait status text "Thread main stopped at SampleClass1.java:24" stt.waitText("24"); // NOI18N stt.stop(); // check "Hello" was printed out in Output OutputTabOperator oto = new OutputTabOperator("debug-single"); // NOI18N // wait until text Hello is not written in to the Output oto.waitText("Hello"); // NOI18N } catch (Throwable th) { try { // capture screen before cleanup in finally clause is completed PNGEncoder.captureScreen(getWorkDir().getAbsolutePath()+File.separator+"screenBeforeCleanup.png"); } catch (Exception e1) { // ignore it } throw th; } finally { // finish debugging // "Finish Debugger Session" String finishItem = Bundle.getStringTrimmed("org.netbeans.modules.debugger.ui.actions.Bundle", "CTL_KillAction_name"); new Action(runItem+"|"+finishItem, null).perform(); // check status line // "Debugger finished" String finishedLabel = Bundle.getString("org.netbeans.modules.debugger.jpda.ui.Bundle", "CTL_Debugger_finished");; MainWindowOperator.getDefault().waitStatusText(finishedLabel); // delete sample class SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(SAMPLE_PROJECT_NAME); Node sample1Node = new Node(sourcePackagesNode, SAMPLE1_PACKAGE_NAME); JavaNode sampleClass1Node = new JavaNode(sample1Node, SAMPLE1_FILE_NAME); sampleClass1Node.delete(); String confirmTitle = Bundle.getString("org.openide.explorer.Bundle", "MSG_ConfirmDeleteObjectTitle"); // NOI18N // "Confirm Object Deletion" new NbDialogOperator(confirmTitle).yes(); } } /** Test Options * - open Options window from main menu Tools|Options * - select IDE Configuration|System|System Settings node * - set Web Browser to "Swing HTML Browser" * - set Proxy Host to webcache * - set Proxy Port to 8080 * - set Use Proxy to true * - close Options window */ public void testOptions() { OptionsOperator optionsOper = OptionsOperator.invoke(); // set exact comparator because in Japanese there is conflict with Filesystem settings optionsOper.treeTable().tree().setComparator(new Operator.DefaultStringComparator(true, true)); // "IDE Configuration|System|System Settings" String systemSettings = Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration") + "|" + Bundle.getString("org.netbeans.core.Bundle", "UI/Services/IDEConfiguration/System") + "|" + Bundle.getString("org.netbeans.core.Bundle", "Services/org-netbeans-core-IDESettings.settings"); optionsOper.selectOption(systemSettings); PropertySheetOperator pso = new PropertySheetOperator(optionsOper); // "Web Browser" String webBrowserLabel = Bundle.getString("org.netbeans.core.Bundle", "PROP_WWW_BROWSER"); // "Swing HTML Browser" String swingBrowserLabel = Bundle.getString("org.netbeans.core.ui.Bundle", "Services/Browsers/SwingBrowser.ser"); new Property(pso, webBrowserLabel).setValue(swingBrowserLabel); // "Proxy Host" String proxyHostLabel = Bundle.getString("org.netbeans.core.Bundle", "PROP_PROXY_HOST"); new Property(pso, proxyHostLabel).setValue("webcache"); // NOI18N // "Proxy Port" String proxyPortLabel = Bundle.getString("org.netbeans.core.Bundle", "PROP_PROXY_PORT"); new Property(pso, proxyPortLabel).setValue("8080"); // NOI18N // "Use Proxy" String useProxyLabel = Bundle.getString("org.netbeans.core.Bundle", "PROP_USE_PROXY"); new Property(pso, useProxyLabel).setValue("true"); // NOI18N optionsOper.close(); } /** Test Update Center * - open Update Center Wizard from main menu Tools|Update Center * - set proxy and go next * - wait until connection dialog dismiss * - in modules tree select "Development Update Center|Web|Applet" node * - click right arrow button and go next * - accept license dialog * - wait until download is finished and finish the wizard */ public void testUpdateCenter() { // "Tools" String toolsItem = Bundle.getStringTrimmed("org.netbeans.core.Bundle", "Menu/Tools"); // NOI18N WizardOperator updateCenterWizardOper = null; long oldWaitStateTime = JemmyProperties.getCurrentTimeout("ComponentOperator.WaitStateTimeout"); try { // "Update Center" String updateCenterItem = Bundle.getStringTrimmed("org.netbeans.modules.autoupdate.Bundle", "CTL_Update"); new Action(toolsItem+"|"+updateCenterItem, null).perform(); // "Update Center Wizard" String updateCenterTitle = Bundle.getString("org.netbeans.modules.autoupdate.Bundle", "CTL_Wizard"); updateCenterWizardOper = new WizardOperator(updateCenterTitle); // disable Forte for Java Update Center if any JTableOperator oper = new JTableOperator(updateCenterWizardOper); // check each row for(int i=0;i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.