001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package gui.action;
042:
043: import gui.Utilities;
044: import org.netbeans.jellytools.NbDialogOperator;
045: import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
046: import org.netbeans.jellytools.NewProjectWizardOperator;
047: import org.netbeans.jellytools.TopComponentOperator;
048: import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
049: import org.netbeans.jemmy.JemmyProperties;
050: import org.netbeans.jemmy.TimeoutExpiredException;
051: import org.netbeans.jemmy.operators.ComponentOperator;
052:
053: /**
054: *
055: * @author mkhramov@netbeans.org
056: */
057: public class CreateRubyProject extends
058: org.netbeans.performance.test.utilities.PerformanceTestCase {
059:
060: private NewProjectNameLocationStepOperator wizard_location;
061:
062: public String category, project, project_name, project_type,
063: editor_name;
064:
065: public CreateRubyProject(String testName) {
066: super (testName);
067: expectedTime = 10000;
068: WAIT_AFTER_OPEN = 20000;
069: }
070:
071: public CreateRubyProject(String testName, String performanceDataName) {
072: super (testName, performanceDataName);
073: expectedTime = 10000;
074: WAIT_AFTER_OPEN = 20000;
075: }
076:
077: @Override
078: public void initialize() {
079: log("::initialize::");
080:
081: }
082:
083: @Override
084: public void prepare() {
085: log("::prepare");
086: System.out.println("::prepare");
087: createProject();
088: }
089:
090: private void createProject() {
091: NewProjectWizardOperator wizard = NewProjectWizardOperator
092: .invoke();
093: wizard.selectCategory(category);
094: wizard.selectProject(project);
095: wizard.next();
096: wizard_location = new NewProjectNameLocationStepOperator();
097:
098: String directory = System.getProperty("xtest.tmpdir");
099: System.out.println(directory);
100:
101: wizard_location.txtProjectLocation().setText("");
102:
103: waitNoEvent(1000);
104: wizard_location.txtProjectLocation().setText(directory);
105: System.out.println(wizard_location.txtProjectLocation()
106: .getText());
107:
108: project_name = project_type + "_" + System.currentTimeMillis();
109: log("================= Project name=" + project_name + "}");
110: wizard_location.txtProjectName().setText("");
111: waitNoEvent(1000);
112: wizard_location.txtProjectName().typeText(project_name);
113:
114: }
115:
116: public ComponentOperator open() {
117: log("::open");
118: wizard_location.finish();
119:
120: long oldTimeout = JemmyProperties.getCurrentTimeouts()
121: .getTimeout("ComponentOperator.WaitStateTimeout");
122: JemmyProperties.getCurrentTimeouts().setTimeout(
123: "ComponentOperator.WaitStateTimeout", 120000);
124: System.out.println("wait wizard closed...");
125: wizard_location.waitClosed();
126: System.out.println("done1...");
127: System.out.println("project creation dialog closed");
128: waitProjectCreatingDialogClosed();
129: System.out.println("done2....");
130:
131: JemmyProperties.getCurrentTimeouts().setTimeout(
132: "ComponentOperator.WaitStateTimeout", oldTimeout);
133:
134: TopComponentOperator.findTopComponent(editor_name, 0);
135: return null;
136: }
137:
138: @Override
139: public void close() {
140: log("::close");
141:
142: try {
143: new CloseAllDocumentsAction().performAPI(); //avoid issue 68671 - editors are not closed after closing project by ProjectSupport
144: } catch (Exception ex) {
145: log("Exception catched on CloseAllDocuments action: "
146: + ex.getMessage());
147: }
148: try {
149: Utilities.deleteProject(project_name);
150: } catch (Exception ee) {
151: log("Exception during project deletion: " + ee.getMessage());
152: }
153: }
154:
155: private void waitProjectCreatingDialogClosed() {
156: String dlgName = org.netbeans.jellytools.Bundle.getString(
157: "org.netbeans.modules.visualweb.project.jsf.ui.Bundle",
158: "CAP_Opening_Projects");
159: try {
160: NbDialogOperator dlg = new NbDialogOperator(dlgName);
161: dlg.waitClosed();
162: } catch (TimeoutExpiredException tex) {
163: //
164: }
165:
166: }
167:
168: public void testCreateRubyProject() {
169: category = "Ruby";
170: project = org.netbeans.jellytools.Bundle
171: .getString(
172: "org.netbeans.modules.ruby.rubyproject.ui.wizards.Bundle",
173: "Templates/Project/Ruby/emptyRuby.xml");
174: project_type = "RubyProject";
175: editor_name = "main.rb";
176: doMeasurement();
177: }
178:
179: public void testCreateRubyOnRailsProject() {
180: category = "Ruby";
181: project = "Ruby on Rails Application";
182: project_type = "RailsProject";
183: editor_name = "database.yml";
184: doMeasurement();
185: }
186:
187: public static void main(java.lang.String[] args) {
188: junit.textui.TestRunner.run(new CreateRubyProject(
189: "testCreateRubyProject"));
190: }
191: }
|