ide.kit/test/qa-functional/src/org/netbeans/test/cnd/CNDValidation.java
author Ivan Sidorkin <ivansidorkin@netbeans.org>
Fri Jun 27 15:23:39 2008 +0400 (6 days ago)
changeset 86793 ff3d17b46f06
parent 86520215c5d222be5
permissions -rw-r--r--
Migrating 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.cnd;
       42 
       43 import org.netbeans.jellytools.Bundle;
       44 import org.netbeans.jellytools.JellyTestCase;
       45 import org.netbeans.jellytools.MainWindowOperator;
       46 import org.netbeans.jellytools.NbDialogOperator;
       47 import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
       48 import org.netbeans.jellytools.NewProjectWizardOperator;
       49 import org.netbeans.jellytools.ProjectsTabOperator;
       50 import org.netbeans.jellytools.TopComponentOperator;
       51 import org.netbeans.jellytools.actions.Action;
       52 import org.netbeans.jellytools.actions.ActionNoBlock;
       53 import org.netbeans.jellytools.nodes.Node;
       54 import org.netbeans.jemmy.TimeoutExpiredException;
       55 import org.netbeans.jemmy.operators.JTreeOperator;
       56 import org.netbeans.junit.NbTestSuite;
       57 import org.netbeans.junit.NbModuleSuite;
       58 
       59 /** CND commit validation suite.
       60  *
       61  * @author ap153252
       62  */
       63 public class CNDValidation extends JellyTestCase {
       64 
       65     static final String [] tests = {
       66                 "testCreateSampleProject",
       67                 "testClassView",
       68                 "testBuildProject"
       69     };
       70 
       71     /** Creates a new instance of CNDValidation */
       72     public CNDValidation(String name) {
       73         super(name);
       74     }
       75 
       76     /** Defines order of test cases.
       77      * @return NbTestSuite instance
       78      */
       79 //    public static NbTestSuite suite() {
       80 //        NbTestSuite suite = new NbTestSuite();
       81 //        suite.addTest(new CNDValidation("testCreateSampleProject"));
       82 //        suite.addTest(new CNDValidation("testClassView"));
       83 //        suite.addTest(new CNDValidation("testBuildProject"));
       84 //        return suite;
       85 //    }
       86 
       87     public static junit.framework.Test suite() {
       88         return NbModuleSuite.create(
       89                 NbModuleSuite.createConfiguration(CNDValidation.class)
       90                 .addTest(tests)
       91                 .clusters(".*")
       92                 .enableModules(".*")
       93                 .gui(true)
       94                 );
       95     }
       96 
       97     /** Setup before every test case. */
       98     public void setUp() {
       99         System.out.println("########  " + getName() + "  #######");
      100     }
      101 
      102     /** Clean up after every test case. */
      103     public void tearDown() {
      104     }
      105 
      106     private static final String SAMPLE_PROJECT_NAME = "Welcome";
      107 
      108     /** Test new project
      109      * - open new project wizard
      110      * - select Samples|C/C++ Development|C/C++ category
      111      * - select Welcome project
      112      * - wait until wizard and Opening projects dialogs are closed
      113      * - close possible error dialogs when compiler is not found
      114      * - check project node appears in project view
      115      */
      116     public void testCreateSampleProject() {
      117         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
      118         // "Samples"
      119         String samplesLabel = Bundle.getStringTrimmed("org.netbeans.modules.project.ui.Bundle", "Templates/Project/Samples");
      120         String develLabel = Bundle.getStringTrimmed("org.netbeans.modules.cnd.makeproject.ui.wizards.Bundle", "Templates/Project/Samples/Native");
      121         String ccLabel = Bundle.getStringTrimmed("org.netbeans.modules.cnd.makeproject.ui.wizards.Bundle", "Templates/Project/Samples/Native/Applications");
      122         npwo.selectCategory(samplesLabel + "|" + develLabel + "|" + ccLabel);
      123         npwo.selectProject(SAMPLE_PROJECT_NAME);
      124         npwo.next();
      125         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
      126         npnlso.txtProjectName().setText(SAMPLE_PROJECT_NAME);
      127         npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
      128         npnlso.btFinish().pushNoBlock();
      129         npnlso.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
      130         npnlso.waitClosed();
      131         // Opening Projects
      132         String openingProjectsTitle = Bundle.getString("org.netbeans.modules.project.ui.Bundle", "LBL_Opening_Projects_Progress");
      133         try {
      134             // wait at most 120 second until progress dialog dismiss
      135             NbDialogOperator openingOper = new NbDialogOperator(openingProjectsTitle);
      136             openingOper.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000);
      137             openingOper.waitClosed();
      138         } catch (TimeoutExpiredException e) {
      139             // ignore when progress dialog was closed before we started to wait for it
      140         }
      141         do {
      142             try {
      143                 // wait for error dialog if compiler is not set
      144                 NbDialogOperator errorOper = new NbDialogOperator("Error");
      145                 errorOper.close();
      146             } catch (TimeoutExpiredException e) {
      147                 // no more error dialog => we can continue
      148                 break;
      149             }
      150         } while (true);
      151         // wait project appear in projects view
      152         new ProjectsTabOperator().getProjectRootNode(SAMPLE_PROJECT_NAME);
      153     }
      154 
      155     /** Test Class View
      156      * - open Window|Class View
      157      * - check Welcome|main node is available
      158      */
      159     public void testClassView() {
      160         new Action(null, "Window|Classes").perform(); // NOI18N
      161         TopComponentOperator classView = new TopComponentOperator("Classes"); // NOI18N
      162         new Node(new JTreeOperator(classView), SAMPLE_PROJECT_NAME+"|main");
      163     }
      164 
      165     /** Test build project
      166      * - call Clean and Build on project node
      167      * - if compiler is not set, close 'Resolve Missing...' dialog
      168      * - otherwise wait for clean and build finished
      169      */
      170     public void testBuildProject() {
      171         Node projectNode = new ProjectsTabOperator().getProjectRootNode(SAMPLE_PROJECT_NAME);
      172         // "Clean and Build"
      173         String buildItem = Bundle.getString("org.netbeans.modules.cnd.makeproject.ui.Bundle", "LBL_RebuildAction_Name");
      174         // start to track Main Window status bar
      175         MainWindowOperator.StatusTextTracer stt = MainWindowOperator.getDefault().getStatusTextTracer();
      176         stt.start();
      177         new ActionNoBlock(null, buildItem).perform(projectNode);
      178         try {
      179             // wait for possible dialog when compiler are not set
      180             NbDialogOperator resolveOper = new NbDialogOperator("Resolve Missing Native Build Tools");
      181             // close and finish the test
      182             resolveOper.close();
      183             return;
      184         } catch (TimeoutExpiredException e) {
      185             // ignore when it doesn't appear
      186         }
      187         // wait message "Clean successful"
      188         stt.waitText("Clean successful", true); // NOI18N
      189         // wait message "Build successful."
      190         stt.waitText(Bundle.getString("org.netbeans.modules.cnd.builds.Bundle", "MSG_BuildFinishedOK"), true);
      191         stt.stop();
      192     }
      193 }