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.
41 package org.netbeans.test.ruby;
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;
58 import org.netbeans.jemmy.JemmyProperties;
59 import org.netbeans.jemmy.operators.JLabelOperator;
60 import org.netbeans.jemmy.operators.JTextFieldOperator;
62 import org.netbeans.junit.NbModuleSuite;
63 import org.netbeans.junit.NbTestSuite;
64 import org.netbeans.test.ide.WatchProjects;
67 * Overall validation suite for ruby cluster.
69 * @author Jiri.Skrivanek@sun.com
71 public class RubyValidation extends JellyTestCase {
73 static final String [] tests = {
74 "testCreateRubyProject",
76 "testCreateRailsProject",
81 /** Need to be defined because of JUnit */
82 public RubyValidation(String name) {
86 public static junit.framework.Test suite() {
87 return NbModuleSuite.create(
88 NbModuleSuite.createConfiguration(RubyValidation.class)
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"));
108 /** Use for execution inside IDE */
109 public static void main(java.lang.String[] args) {
111 TestRunner.run(suite());
112 // run only selected test case
113 //junit.textui.TestRunner.run(new RubyValidation("testCreateRubyProject"));
116 /** Setup before every test case. */
118 public void setUp() {
119 System.out.println("######## "+getName()+" #######");
122 /** Teardown after every test case. */
124 public void tearDown() {
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
133 * - open IRB shell window
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();
144 /** Test Ruby Application
145 * - open new project wizard
146 * - choose Ruby|Ruby Application
148 * - type name and location and finish the wizard
149 * - wait until project is in Projects view
150 * - wait classpath scanning finished
152 public void testCreateRubyProject() {
153 // create new web application project
154 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
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);
162 NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
163 npnlso.txtProjectName().setText(SAMPLE_RUBY_PROJECT_NAME);
164 npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
166 // wait project appear in projects view
168 JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N
169 new ProjectsTabOperator().getProjectRootNode(SAMPLE_RUBY_PROJECT_NAME);
170 // wait classpath scanning finished
171 WatchProjects.waitScanFinished();
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
180 public void testRunRubyFile() {
181 // wait main.rb is opened in editor
182 EditorOperator editor = new EditorOperator("main.rb"); // NOI18N
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
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
199 public void testCreateRailsProject() {
200 // create new web application project
201 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke();
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);
209 NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator();
210 npnlso.txtProjectName().setText(SAMPLE_RAILS_PROJECT_NAME);
211 npnlso.txtProjectLocation().setText(System.getProperty("netbeans.user")); // NOI18N
213 // wait project appear in projects view
215 JemmyProperties.setCurrentTimeout("JTreeOperator.WaitNextNodeTimeout", 30000); // NOI18N
216 new ProjectsTabOperator().getProjectRootNode(SAMPLE_RAILS_PROJECT_NAME);
217 // wait classpath scanning finished
218 WatchProjects.waitScanFinished();
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
230 public void testRailsGenerate() {
231 ProjectRootNode projectRootNode = new ProjectsTabOperator().getProjectRootNode(SAMPLE_RAILS_PROJECT_NAME);
234 String generateItem = Bundle.getStringTrimmed("org.netbeans.modules.ruby.railsprojects.Bundle", "rails-generator");
235 new ActionNoBlock(null, generateItem).perform(projectRootNode);
237 String generatorTitle = Bundle.getStringTrimmed("org.netbeans.modules.ruby.railsprojects.Bundle", "RailsGenerator");
238 NbDialogOperator generatorOper = new NbDialogOperator(generatorTitle);
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
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");
250 JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 180000);
252 String filename = "myapp_controller.rb"; // NOI18N
253 new EditorOperator(filename);
255 String controllersLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "app_controllers");
256 new Node(projectRootNode, controllersLabel+"|"+filename);
258 filename = "myapp_helper.rb"; // NOI18N
259 new EditorOperator(filename);
261 String helpersLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "app_helpers");
262 new Node(projectRootNode, helpersLabel+"|"+filename);
264 filename = "myview.html.erb"; // NOI18N
265 new EditorOperator(filename);
267 String viewsLabel = Bundle.getString("org.netbeans.modules.ruby.railsprojects.Bundle", "app_views");
268 new Node(projectRootNode, viewsLabel+"|myapp|"+filename);
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);