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-2007 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:
042: package gui.action;
043:
044: import gui.VWPUtilities;
045:
046: import org.netbeans.jellytools.NbDialogOperator;
047: import org.netbeans.jellytools.NewFileNameLocationStepOperator;
048: import org.netbeans.jellytools.NewFileWizardOperator;
049: import org.netbeans.jellytools.ProjectsTabOperator;
050: import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
051: import org.netbeans.jellytools.actions.DeleteAction;
052: import org.netbeans.jellytools.nodes.Node;
053: import org.netbeans.jemmy.JemmyProperties;
054: import org.netbeans.jemmy.TimeoutExpiredException;
055:
056: import org.netbeans.jemmy.operators.ComponentOperator;
057: import org.netbeans.jemmy.operators.JTextFieldOperator;
058: import org.netbeans.jemmy.operators.Operator;
059: import org.netbeans.junit.NbTestSuite;
060:
061: /**
062: * Test create Web Pack projects
063: *
064: * @author mkhramov@netbeans.org, mmirilovic@netbeans.org
065: */
066: public class CreateWebPackFiles extends
067: org.netbeans.performance.test.utilities.PerformanceTestCase {
068:
069: private String doccategory, doctype, docname, docfolder, suffix,
070: projectfolder, buildedname;
071: private NewFileNameLocationStepOperator location;
072:
073: private static final String project_name = "VisualWebProject";
074: private ProjectsTabOperator pto;
075:
076: /**
077: * Creates a new instance of CreateWebPackFiles
078: * @param testName the name of the test
079: */
080: public CreateWebPackFiles(String testName) {
081: super (testName);
082: }
083:
084: /**
085: * Creates a new instance of CreateWebPackFiles
086: * @param testName the name of the test
087: * @param performanceDataName measured values will be saved under this name
088: */
089: public CreateWebPackFiles(String testName,
090: String performanceDataName) {
091: super (testName, performanceDataName);
092: }
093:
094: public static NbTestSuite suite() {
095: NbTestSuite suite = new NbTestSuite();
096: suite.addTest(new CreateWebPackFiles("testCreateJSPPage",
097: "Create JSF Page"));
098: suite.addTest(new CreateWebPackFiles("testCreateJSPFragment",
099: "Create JSF fragment"));
100: suite.addTest(new CreateWebPackFiles("testCreateCSSTable",
101: "Create CSS Table"));
102: return suite;
103: }
104:
105: public void testCreateJSPPage() {
106: expectedTime = WINDOW_OPEN;
107: WAIT_AFTER_OPEN = 15000;
108: docname = "JSFPage"; //NOI18N
109: doccategory = "JavaServer Faces"; //NOI18N
110: doctype = "Visual Web JSF Page"; //NOI18N
111: docfolder = "web";
112: suffix = ".jsp";
113: projectfolder = VWPUtilities.WEB_PAGES;
114: doMeasurement();
115: }
116:
117: public void testCreateJSPFragment() {
118: expectedTime = WINDOW_OPEN;
119: WAIT_AFTER_OPEN = 15000;
120: docname = "JSFFragment"; //NOI18N
121: doccategory = "JavaServer Faces"; //NOI18N
122: doctype = "Visual Web JSF Page Fragment"; //NOI18N
123: docfolder = "web";
124: suffix = ".jspf";
125: projectfolder = VWPUtilities.WEB_PAGES;
126: doMeasurement();
127: }
128:
129: public void testCreateCSSTable() {
130: expectedTime = 1000;
131: WAIT_AFTER_OPEN = 5000;
132: docname = "CSSTable"; //NOI18N
133: doccategory = "Web"; //NOI18N
134: doctype = "Cascading Style Sheet"; //NOI18N
135: docfolder = "web" + java.io.File.separatorChar + "resources"; // NOI18N
136: suffix = ".css";
137: projectfolder = VWPUtilities.WEB_PAGES + "|" + "resources"; // NOI18N
138: doMeasurement();
139: }
140:
141: public ComponentOperator open() {
142: log("::open::");
143: location.finish();
144:
145: return null; //new EditorOperator(docname+"_"+(index)+suffix);
146: }
147:
148: public void initialize() {
149: log("::initialize::");
150: pto = ProjectsTabOperator.invoke();
151:
152: Node projectRoot = null;
153: try {
154: projectRoot = pto.getProjectRootNode(project_name);
155: projectRoot.select();
156:
157: } catch (org.netbeans.jemmy.TimeoutExpiredException ex) {
158: fail("Cannot find and select project root node");
159: }
160: }
161:
162: public void prepare() {
163: log("::prepare::");
164:
165: NewFileWizardOperator wizard = NewFileWizardOperator.invoke();
166:
167: // create exactly (full match) and case sensitively comparing comparator
168: Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(
169: true, true);
170: wizard.lstFileTypes().setComparator(comparator);
171: log("Selected Project: " + wizard.getSelectedProject());
172: wizard.selectProject(project_name);
173: log("Selected Project: " + wizard.getSelectedProject());
174: wizard.selectCategory(doccategory);
175: wizard.selectFileType(doctype);
176:
177: wizard.next();
178:
179: waitNoEvent(1000);
180: location = new NewFileNameLocationStepOperator();
181: buildedname = docname + "_" + System.currentTimeMillis();
182: location.txtObjectName().setText(buildedname);
183:
184: JTextFieldOperator pathField = new JTextFieldOperator(wizard, 2);
185: pathField.setText(docfolder);
186: waitNoEvent(1000);
187: }
188:
189: public void close() {
190: log("::close");
191: try {
192: new CloseAllDocumentsAction().performAPI(); //avoid issue 68671 - editors are not closed after closing project by ProjectSupport
193: } catch (Exception ex) {
194: log("Exception catched on CloseAllDocuments action: "
195: + ex.getMessage());
196: }
197: cleanupTest();
198: }
199:
200: private void cleanupTest() {
201: log(":: do cleanup.....");
202: long nodeTimeout = pto.getTimeouts().getTimeout(
203: "ComponentOperator.WaitStateTimeout");
204: long dialogTimeout = JemmyProperties.getCurrentTimeouts()
205: .getTimeout("DialogWaiter.WaitDialogTimeout");
206:
207: pto.getTimeouts().setTimeout(
208: "ComponentOperator.WaitStateTimeout", 60000);
209: JemmyProperties.getCurrentTimeouts().setTimeout(
210: "DialogWaiter.WaitDialogTimeout", 60000);
211:
212: waitNoEvent(2000);
213:
214: try {
215: Node projectRootNode = pto.getProjectRootNode(project_name);
216: projectRootNode.select();
217: //waitNoEvent(2000);
218: Node objNode;
219: objNode = new Node(projectRootNode, projectfolder);
220: objNode.select();
221: objNode = new Node(projectRootNode, projectfolder + "|"
222: + buildedname + suffix);
223: objNode.select();
224: new DeleteAction().performPopup(objNode);
225: String dialogCaption = org.netbeans.jellytools.Bundle
226: .getString(
227: "org.netbeans.modules.visualweb.navigation.Bundle",
228: "MSG_ConfirmDeleteObjectTitle");
229: new NbDialogOperator(dialogCaption).yes();
230:
231: } catch (TimeoutExpiredException timeoutExpiredException) {
232:
233: log("Cleanup failed because of: "
234: + timeoutExpiredException.getMessage());
235: pto.getTimeouts().setTimeout(
236: "ComponentOperator.WaitStateTimeout", nodeTimeout);
237: JemmyProperties.getCurrentTimeouts().setTimeout(
238: "DialogWaiter.WaitDialogTimeout", dialogTimeout);
239: return;
240: }
241: pto.getTimeouts().setTimeout(
242: "ComponentOperator.WaitStateTimeout", nodeTimeout);
243: JemmyProperties.getCurrentTimeouts().setTimeout(
244: "DialogWaiter.WaitDialogTimeout", dialogTimeout);
245: log(":: cleanup passed");
246: }
247:
248: public void shutdown() {
249: log("::shutdown");
250: super .shutdown();
251: }
252:
253: public static void main(String[] args) {
254: junit.textui.TestRunner.run(suite());
255: }
256:
257: }
|