ide.kit/test/qa-functional/src/org/netbeans/test/ruby/RubyValidation.java
author Ivan Sidorkin <ivansidorkin@netbeans.org>
Fri Jun 27 15:23:39 2008 +0400 (6 days ago)
changeset 86793 ff3d17b46f06
parent 861035b4cc9cc5693
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-2008 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.ruby;
       42 
       43 import javax.swing.JTextField;
       44 import junit.textui.TestRunner;
       45 import org.netbeans.jellytools.Bundle;
       46 import org.netbeans.jellytools.EditorOperator;
       47 import org.netbeans.jellytools.JellyTestCase;
       48 import org.netbeans.jellytools.NbDialogOperator;
       49 import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
       50 import org.netbeans.jellytools.NewProjectWizardOperator;
       51 import org.netbeans.jellytools.OutputTabOperator;
       52 import org.netbeans.jellytools.ProjectsTabOperator;
       53 import org.netbeans.jellytools.actions.Action;
       54 import org.netbeans.jellytools.actions.ActionNoBlock;
       55 import org.netbeans.jellytools.nodes.Node;
       56 import org.netbeans.jellytools.nodes.ProjectRootNode;
       57 
       58 import org.netbeans.jemmy.JemmyProperties;
       59 import org.netbeans.jemmy.operators.JLabelOperator;
       60 import org.netbeans.jemmy.operators.JTextFieldOperator;
       61 
       62 import org.netbeans.junit.NbModuleSuite;
       63 import org.netbeans.junit.NbTestSuite;
       64 import org.netbeans.test.ide.WatchProjects;
       65 
       66 /**
       67  * Overall validation suite for ruby cluster.
       68  *
       69  * @author Jiri.Skrivanek@sun.com
       70  */
       71 public class RubyValidation extends JellyTestCase {
       72 
       73      static final String [] tests = {
       74                 "testCreateRubyProject",
       75                 "testRunRubyFile",
       76                 "testCreateRailsProject",
       77                 "testRailsGenerate",
       78                 "testIrbShell",
       79     };
       80 
       81     /** Need to be defined because of JUnit */
       82     public RubyValidation(String name) {
       83         super(name);
       84     }
       85 
       86     public static junit.framework.Test suite() {
       87         return NbModuleSuite.create(
       88                 NbModuleSuite.createConfiguration(RubyValidation.class)
       89                 .addTest(tests)
       90                 .clusters(".*")
       91                 .enableModules(".*")
       92                 .gui(true)
       93                 );
       94     }
       95 
       96 //    public static NbTestSuite suite() {
       97 //        NbTestSuite suite = new NbTestSuite();
       98 //        suite.addTest(new RubyValidation("testCreateRubyProject"));
       99 //        suite.addTest(new RubyValidation("testRunRubyFile"));
      100 //        suite.addTest(new RubyValidation("testCreateRailsProject"));
      101 //        suite.addTest(new RubyValidation("testRailsGenerate"));
      102 //        suite.addTest(new RubyValidation("testIrbShell"));
      103 //        return suite;
      104 //    }
      105 
      106 
      107 
      108     /** Use for execution inside IDE */
      109     public static void main(java.lang.String[] args) {
      110         // run whole suite
      111         TestRunner.run(suite());
      112         // run only selected test case
      113         //junit.textui.TestRunner.run(new RubyValidation("testCreateRubyProject"));
      114     }
      115     
      116     /** Setup before every test case. */
      117     @Override
      118     public void setUp() {
      119         System.out.println("########  "+getName()+"  #######");
      120     }
      121     
      122     /** Teardown after every test case. */
      123     @Override
      124     public void tearDown() {
      125     }
      126     
      127     // name of sample projects
      128     private static final String SAMPLE_RUBY_PROJECT_NAME = "SampleRubyApplication";  //NOI18N
      129     private static final String SAMPLE_RAILS_PROJECT_NAME = "SampleRailsApplication";  //NOI18N
      130 
      131     
      132     /** Test IRB shell
      133      * - open IRB shell window 
      134      * - close it
      135      */
      136     public void testIrbShell() {
      137         String irbItem = Bundle.getStringTrimmed("org.netbeans.modules.ruby.rubyproject.Bundle", "CTL_IrbAction");
      138         String irbTitle = Bundle.getString("org.netbeans.modules.ruby.rubyproject.Bundle", "CTL_IrbTopComponent");
      139         new Action("Window|Other|" + irbItem, null).perform();
      140         new OutputTabOperator(irbTitle).close();
      141     }   
      142 
      143 
      144     /** Test Ruby Application
      145      * - open new project wizard
      146      * - choose Ruby|Ruby Application
      147      * - click Next
      148      * - type name and location and finish the wizard
      149      * - wait until project is in Projects view
      150      * - wait classpath scanning finished
      151      */
      152     public void testCreateRubyProject() {
      153         // create new web application project
      154         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
      155         // "Ruby"
      156         String rubyLabel = Bundle.getString("org.netbeans.modules.ruby.rubyproject.ui.wizards.Bundle", "Templates/Project/Ruby");
      157         npwo.selectCategory(rubyLabel);
      158         // "Ruby Application"
      159         String rubyApplicationLabel = Bundle.getString("org.netbeans.modules.ruby.rubyproject.ui.wizards.Bundle", "TXT_NewJavaApp");
      160         npwo.selectProject(rubyApplicationLabel);
      161         npwo.next();
      162         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
      163         npnlso.txtProjectName().setText(SAMPLE_RUBY_PROJECT_NAME);
      164         npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
      165         npnlso.finish();
      166         // wait project appear in projects view
      167         // wait 30 second
      168         JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N
      169         new ProjectsTabOperator().getProjectRootNode(SAMPLE_RUBY_PROJECT_NAME);
      170         // wait classpath scanning finished
      171         WatchProjects.waitScanFinished();
      172     }
      173     
      174     /** Test run Ruby file
      175      * - find main.rb in editor
      176      * - call "Run "main.rb"" popup action in editor
      177      * - wait for main.rb output tab
      178      * - check "Hello World" is printed out
      179      */
      180     public void testRunRubyFile() {
      181         // wait main.rb is opened in editor
      182         EditorOperator editor = new EditorOperator("main.rb"); // NOI18N
      183         // "Run "main.rb""
      184         String runFileItem = Bundle.getStringTrimmed(
      185                 "org.netbeans.modules.project.ui.actions.Bundle",
      186                 "LBL_RunSingleAction_Name",
      187                 new Object[]{new Integer(1), "main.rb"});
      188         // call "Run "main.rb"" in editor
      189         new Action(null, runFileItem).perform(editor);
      190         // check message in output tab
      191         new OutputTabOperator("main.rb").waitText("Hello World"); // NOI18N
      192     }
      193     
      194     /** Test Ruby on Rails Application
      195      * - create new Ruby on Rails Application project
      196      * - wait until project is in Projects view
      197      * - wait classpath scanning finished
      198      */
      199     public void testCreateRailsProject() {
      200         // create new web application project
      201         NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
      202         // "Ruby"
      203         String rubyLabel = Bundle.getString("org.netbeans.modules.ruby.rubyproject.ui.wizards.Bundle", "Templates/Project/Ruby");
      204         npwo.selectCategory(rubyLabel);
      205         // "Ruby on Rails Application"
      206         String railsApplicationLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.ui.wizards.Bundle", "Templates/Project/Ruby/railsApp.xml");
      207         npwo.selectProject(railsApplicationLabel);
      208         npwo.next();
      209         NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
      210         npnlso.txtProjectName().setText(SAMPLE_RAILS_PROJECT_NAME);
      211         npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
      212         npnlso.finish();
      213         // wait project appear in projects view
      214         // wait 30 second
      215         JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N
      216         new ProjectsTabOperator().getProjectRootNode(SAMPLE_RAILS_PROJECT_NAME);
      217         // wait classpath scanning finished
      218         WatchProjects.waitScanFinished();
      219     }
      220     
      221     /** Test Rails Generator
      222      * - call "Generate..." action on project node
      223      * - wait for Rails Generator dialog
      224      * - type "myapp" in Name text field
      225      * - type "myview" in Views: text field
      226      * - click OK button in dialog
      227      * - check files myapp_controller.rb, myapp_helper.rb, myview.rhtml, 
      228      * myapp_controller_test.rb are opened in editor and available in Projects view
      229      */
      230     public void testRailsGenerate() {
      231         ProjectRootNode projectRootNode = new ProjectsTabOperator().getProjectRootNode(SAMPLE_RAILS_PROJECT_NAME);
      232 
      233         // "Generate..."
      234         String generateItem = Bundle.getStringTrimmed("org.netbeans.modules.ruby.railsprojects.Bundle", "rails-generator");
      235         new ActionNoBlock(null, generateItem).perform(projectRootNode);
      236         // "Rails Generator"
      237         String generatorTitle = Bundle.getStringTrimmed("org.netbeans.modules.ruby.railsprojects.Bundle", "RailsGenerator");
      238         NbDialogOperator generatorOper = new NbDialogOperator(generatorTitle);
      239         // "Name:"
      240         String nameLabel = Bundle.getStringTrimmed("org.netbeans.modules.ruby.railsprojects.Bundle", "Name");
      241         JTextFieldOperator nameOper = new JTextFieldOperator((JTextField)new JLabelOperator(generatorOper, nameLabel).getLabelFor());
      242         nameOper.setText("myapp");  // NOI18N
      243         // "Views:"
      244         String viewsTextFieldLabel = Bundle.getStringTrimmed("org.netbeans.modules.ruby.railsprojects.Bundle", "Views");
      245         JTextFieldOperator viewsOper = new JTextFieldOperator((JTextField)new JLabelOperator(generatorOper, viewsTextFieldLabel).getLabelFor());
      246         viewsOper.setText("myview");
      247         generatorOper.ok();
      248         
      249         // wait 180 second
      250         JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 180000);
      251         
      252         String filename = "myapp_controller.rb"; // NOI18N
      253         new EditorOperator(filename);
      254         // "Controllers"
      255         String controllersLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "app_controllers");
      256         new Node(projectRootNode, controllersLabel+"|"+filename);
      257         
      258         filename = "myapp_helper.rb"; // NOI18N
      259         new EditorOperator(filename);
      260         // "Helpers"
      261         String helpersLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "app_helpers");
      262         new Node(projectRootNode, helpersLabel+"|"+filename);
      263         
      264         filename = "myview.html.erb"; // NOI18N
      265         new EditorOperator(filename);
      266         // "Views"
      267         String viewsLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "app_views");
      268         new Node(projectRootNode, viewsLabel+"|myapp|"+filename);
      269         
      270         filename = "myapp_controller_test.rb"; // NOI18N
      271         new EditorOperator(filename);
      272         // "Functional Tests"
      273         String functionalTestsLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "test_functional");
      274         new Node(projectRootNode, functionalTestsLabel+"|"+filename);
      275     }
      276 }