ide.kit/test/qa-functional/src/org/netbeans/test/profiler/ProfilerValidation.java
author Ivan Sidorkin <ivansidorkin@netbeans.org>
Thu Jun 26 21:42:27 2008 +0400 (7 days ago)
changeset 86700 7a3070230b8b
parent 861035b4cc9cc5693
permissions -rw-r--r--
Migrating profiler commit validation tests
        1 /*
        2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
        3  *
        4  * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
        5  *
        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]"
       23  *
       24  * Contributor(s):
       25  *
       26  * The Original Software is NetBeans. The Initial Developer of the Original
       27  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
       28  * Microsystems, Inc. All Rights Reserved.
       29  *
       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.
       40  */
       41 package org.netbeans.test.profiler;
       42 
       43 import junit.textui.TestRunner;
       44 import org.netbeans.jellytools.Bundle;
       45 import org.netbeans.jellytools.JellyTestCase;
       46 import org.netbeans.jellytools.MainWindowOperator;
       47 import org.netbeans.jellytools.NbDialogOperator;
       48 import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
       49 import org.netbeans.jellytools.NewProjectWizardOperator;
       50 import org.netbeans.jellytools.OptionsOperator;
       51 import org.netbeans.jellytools.OutputTabOperator;
       52 import org.netbeans.jellytools.ProjectsTabOperator;
       53 import org.netbeans.jellytools.TopComponentOperator;
       54 import org.netbeans.jellytools.actions.Action;
       55 import org.netbeans.jellytools.actions.ActionNoBlock;
       56 import org.netbeans.jellytools.nodes.ProjectRootNode;
       57 import org.netbeans.jemmy.JemmyProperties;
       58 import org.netbeans.jemmy.TimeoutExpiredException;
       59 import org.netbeans.jemmy.Waitable;
       60 import org.netbeans.jemmy.Waiter;
       61 import org.netbeans.jemmy.operators.JButtonOperator;
       62 import org.netbeans.jemmy.operators.JCheckBoxOperator;
       63 import org.netbeans.jemmy.operators.JComboBoxOperator;
       64 import org.netbeans.jemmy.operators.JLabelOperator;
       65 import org.netbeans.jemmy.operators.JTabbedPaneOperator;
       66 import org.netbeans.junit.NbTestSuite;
       67 import org.netbeans.junit.NbModuleSuite;
       68 import org.netbeans.test.ide.WatchProjects;
       69 
       70 /** Validation test of profiler.
       71  *
       72  * @author Alexandr Scherbatiy, Jiri Skrivanek
       73  */
       74 public class ProfilerValidation extends JellyTestCase {
       75     
       76     private static final String SAMPLE_PROJECT_NAME = "AnagramGame";
       77     
       78     protected static final String  MENU_ITEM_PROFILE_MAIN_PROJECT   = "Profile Main Project...";
       79     protected static final String  MENU_ITEM_ATTACH_PROFILE         = "Attach Profiler...";
       80     protected static final String  MENU_ITEM_TAKE_SNAPSHOT          = "Take Snapshot of Collected Results";
       81     protected static final String  MENU_ITEM_STOP_PROFILING_SESSION = "Stop Profiling Session";
       82     
       83     
       84     protected static final String  LABEL_JAVA_PLATFORM = "Profiler Java Platform";
       85     protected static final String  LABEL_COMMUNICATION_PORT = "Communication Port";
       86     
       87     
       88     protected static final String  LABEL_OPEN_THREADS_VIEW = "Open Threads View";
       89     protected static final String  LABEL_CPU = "CPU";
       90     protected static final String  LABEL_MEMORY = "Memory";
       91     
       92     
       93     
       94     protected static final String  LABEL_OPEN_NEW_SNAPSHOT = "Open New Snapshot";
       95     
       96     protected static final String  LABEL_SAVE_HEAP_DUMP = "Save heap dump to";
       97     protected static final String  LABEL_ENABLE_HEAP_ANALYSIS = "Enable Rule-Based Heap Analysis";
       98     
       99     
      100     protected static final String  BUTTON_RUN = "Run";
      101     protected static final String  BUTTON_RESET = "Reset";
      102     
      103     
      104     protected static final String  TEXT_OUTPUT = "Established local connection with the tool";
      105     
      106     static String[] tests = new String[]{
      107             "testProfilerMenus",
      108             "testProfilerProperties",
      109 //            "testCreateProject",
      110 //            "testProfiler"
      111     };
      112     /** Default constructor.
      113      * @param name test case name
      114      */
      115     public ProfilerValidation(String name){
      116         super(name);
      117     }
      118     
      119     /** Defaine order of test cases.
      120      * @return NbTestSuite instance
      121      */
      122 //    public static NbTestSuite suite() {
      123 //        NbTestSuite suite = new NbTestSuite();
      124 //        suite.addTest(new ProfilerValidation("testProfilerMenus"));
      125 //        suite.addTest(new ProfilerValidation("testProfilerProperties"));
      126 //        //suite.addTest(new ProfilerValidation("testCreateProject"));
      127 //        //suite.addTest(new ProfilerValidation("testProfiler"));
      128 //        return suite;
      129 //    }
      130 
      131     public static junit.framework.Test suite() {
      132         return NbModuleSuite.create(
      133                 NbModuleSuite.createConfiguration(ProfilerValidation.class)
      134                 .addTest(tests)
      135                 .clusters(".*")
      136                 .enableModules(".*")
      137                 .gui(true)
      138                 );
      139     }
      140     /** Use for execution inside IDE */
      141     public static void main(java.lang.String[] args) {
      142         // run whole suite
      143         TestRunner.run(suite());
      144         // run only selected test case
      145         //TestRunner.run(new ProfilerValidation("testProfiler"));
      146     }
      147 
      148     /** Setup before every test case. */
      149     public void setUp() {
      150         System.out.println("########  "+getName()+"  #######");
      151     }
      152 
      153     /** Test Profiler Menus. */
      154     public void testProfilerMenus(){
      155 
      156         new ActionNoBlock("Profile|" + MENU_ITEM_PROFILE_MAIN_PROJECT, null).isEnabled();
      157         new ActionNoBlock("Profile|" + MENU_ITEM_ATTACH_PROFILE, null).isEnabled();
      158         new ActionNoBlock("Profile|" + MENU_ITEM_TAKE_SNAPSHOT, null).isEnabled();
      159         new ActionNoBlock("Profile|" + MENU_ITEM_STOP_PROFILING_SESSION, null).isEnabled();
      160         
      161     }
      162     
      163     /** Test Profiler Properties. */
      164     public void testProfilerProperties(){
      165         new ActionNoBlock("Tools|Options", null).perform();
      166         
      167         OptionsOperator options = new OptionsOperator();
      168         options.selectCategory("Miscellaneous");        
      169         
      170         JTabbedPaneOperator tabbedPane = new JTabbedPaneOperator(options);
      171         tabbedPane.selectPage("Profiler");
      172                 
      173         JLabelOperator javaPlatform = new JLabelOperator(options, LABEL_JAVA_PLATFORM);
      174         
      175         JLabelOperator communicationPort = new JLabelOperator(options, LABEL_COMMUNICATION_PORT);
      176         
      177         JLabelOperator openThreads = new JLabelOperator(options, LABEL_OPEN_THREADS_VIEW);
      178         JCheckBoxOperator cpu    = new JCheckBoxOperator(options, LABEL_CPU);
      179         JCheckBoxOperator memory = new JCheckBoxOperator(options, LABEL_MEMORY);
      180         
      181         
      182         JComboBoxOperator openNewSnapshot= new JComboBoxOperator(options, LABEL_OPEN_NEW_SNAPSHOT);
      183         
      184         
      185         
      186         JCheckBoxOperator enableHeapAnalisys = new JCheckBoxOperator(options, LABEL_ENABLE_HEAP_ANALYSIS);
      187         
      188         JButtonOperator reset = new JButtonOperator(options, BUTTON_RESET);
      189         
      190         new JButtonOperator(options, "OK").push();
      191         
      192     }    
      193     
      194     /** Create project to be tested. */
      195     public void testCreateProject() {
      196         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
      197         npwo.selectCategory("Samples|Java");
      198         npwo.selectProject("Anagram Game");
      199         npwo.next();
      200         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
      201         npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
      202         npnlso.btFinish().pushNoBlock();
      203         npnlso.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
      204         npnlso.waitClosed();
      205         // Opening Projects
      206         String openingProjectsTitle = Bundle.getString("org.netbeans.modules.project.ui.Bundle", "LBL_Opening_Projects_Progress");
      207         waitProgressDialog(openingProjectsTitle, 120000);
      208         // wait project appear in projects view
      209         ProjectRootNode projectNode = new ProjectsTabOperator().getProjectRootNode(SAMPLE_PROJECT_NAME);
      210         // wait classpath scanning finished
      211         WatchProjects.waitScanFinished();
      212         projectNode.buildProject();
      213         MainWindowOperator.getDefault().waitStatusText("Finished Building");
      214         
      215     }
      216     
      217     /** Test profiler
      218      * - run profiler calibration Profile|Advanced Commands|Run Profiler Calibration
      219      * - wait for calibration results and confirm information dialog
      220      * - call Profile|Profile Main Project
      221      * - confirm changes in project when profiled for the first time
      222      * - click Run in Profile AnagramGame dialog
      223      * - wait for Profiler view
      224      * - wait until text "Established local connection with the tool" appears in output window
      225      * - wait until "Profile|Take Snapshot of Collected Results" is enabled
      226      * - call Profile|Take Snapshot of Collected Results
      227      * - maximaze results view
      228      * - save collected results
      229      * - call "Profile|Stop Profiling Session"
      230      */
      231     public void testProfiler() throws Exception {
      232         new ActionNoBlock("Profile|Advanced Commands|Run Profiler Calibration", null).perform();
      233         new NbDialogOperator("Select Java Platform to calibrate").ok();
      234         // increase timeout for calibration
      235         JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 120000); // NOI18N
      236         new NbDialogOperator("Information").ok();
      237         new ActionNoBlock("Profile|Profile Main Project", null).perform();
      238         new NbDialogOperator("Question").ok();
      239         NbDialogOperator profileOper = new NbDialogOperator("Profile "+SAMPLE_PROJECT_NAME);
      240         new JButtonOperator(profileOper, "Run").push();
      241         profileOper.waitClosed();
      242         waitProgressDialog("Progress", 5000);
      243         new TopComponentOperator("Profiler");        
      244         new OutputTabOperator(SAMPLE_PROJECT_NAME).waitText("Established local connection with the tool");
      245         Action takeSnapshotAction = new Action("Profile|Take Snapshot of Collected Results", null);
      246         new Waiter(new Waitable() {
      247             public Object actionProduced(Object takeSnapshotAction) {
      248                 return ((Action)takeSnapshotAction).isEnabled() ? Boolean.TRUE : null;
      249             }
      250             public String getDescription() {
      251                 return("Wait menu item enabled."); // NOI18N
      252             }
      253         }).waitAction(takeSnapshotAction);
      254         takeSnapshotAction.perform();
      255         TopComponentOperator collectedResults = new TopComponentOperator("CPU");
      256         //collectedResults.maximize();
      257         collectedResults.saveDocument();
      258         new Action("Profile|Stop Profiling Session", null).perform();
      259     }
      260     
      261     
      262     public void waitProgressDialog(String title, int milliseconds){
      263         try {
      264             // wait at most 120 second until progress dialog dismiss
      265             NbDialogOperator openingOper = new NbDialogOperator(title);
      266             openingOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", milliseconds);
      267             openingOper.waitClosed();
      268         } catch (TimeoutExpiredException e) {
      269             // ignore when progress dialog was closed before we started to wait for it
      270         }        
      271     }
      272 }