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:
042: package gui.action;
043:
044: import org.netbeans.jellytools.EditorOperator;
045: import org.netbeans.jellytools.ProjectsTabOperator;
046: import org.netbeans.jellytools.nodes.Node;
047:
048: import org.netbeans.jemmy.operators.ComponentOperator;
049: import org.netbeans.jemmy.operators.JPopupMenuOperator;
050: import org.netbeans.test.web.performance.WebPerformanceTestCase;
051:
052: /**
053: * Test of opening files.
054: *
055: * @author mmirilovic@netbeans.org
056: */
057: public class OpenWebFiles extends WebPerformanceTestCase {
058:
059: /** Node to be opened/edited */
060: public static Node openNode;
061:
062: /** Folder with data */
063: public static String fileProject;
064:
065: /** Folder with data */
066: public static String fileFolder;
067:
068: /** Name of file to open */
069: public static String fileName;
070:
071: /** Menu item name that opens the editor */
072: public static String menuItem;
073:
074: protected static String OPEN = "Open"; //NOI18N
075:
076: protected static String EDIT = "Edit"; //NOI18N
077:
078: protected static String WEB_PAGES = "Web Pages"; //NOI18N
079:
080: private boolean wrappedEditorOperator = false;
081:
082: /**
083: * Creates a new instance of OpenFiles
084: * @param testName the name of the test
085: */
086: public OpenWebFiles(String testName) {
087: super (testName);
088: expectedTime = WINDOW_OPEN;
089: }
090:
091: /**
092: * Creates a new instance of OpenFiles
093: * @param testName the name of the test
094: * @param performanceDataName measured values will be saved under this name
095: */
096: public OpenWebFiles(String testName, String performanceDataName) {
097: super (testName, performanceDataName);
098: expectedTime = WINDOW_OPEN;
099: }
100:
101: public void testOpeningWebXmlFile() {
102: WAIT_AFTER_OPEN = 3000;
103: //repaintManager().setOnlyEditor(false);
104: repaintManager().resetRegionFilters();
105: setXMLEditorCaretFilteringOn();
106: fileProject = "TestWebProject";
107: fileFolder = "WEB-INF";
108: fileName = "web.xml";
109: menuItem = EDIT;
110: setWrappedClonableEditor(true);
111: doMeasurement();
112: setWrappedClonableEditor(false);
113: }
114:
115: public void testOpeningContextXmlFile() {
116: WAIT_AFTER_OPEN = 3000;
117: //repaintManager().setOnlyEditor(true);
118: repaintManager()
119: .addRegionFilter(repaintManager().EDITOR_FILTER);
120: setXMLEditorCaretFilteringOn();
121: fileProject = "TestWebProject";
122: fileFolder = "META-INF";
123: fileName = "context.xml";
124: menuItem = EDIT;
125: doMeasurement();
126: }
127:
128: public void testOpeningJSPFile() {
129: WAIT_AFTER_OPEN = 3000;
130: //repaintManager().setOnlyEditor(true);
131: repaintManager()
132: .addRegionFilter(repaintManager().EDITOR_FILTER);
133: setXMLEditorCaretFilteringOn();
134: fileProject = "TestWebProject";
135: fileFolder = "";
136: fileName = "Test.jsp";
137: menuItem = OPEN;
138: doMeasurement();
139: }
140:
141: public void testOpeningBigJSPFile() {
142: WAIT_AFTER_OPEN = 3000;
143: //repaintManager().setOnlyEditor(true);
144: repaintManager()
145: .addRegionFilter(repaintManager().EDITOR_FILTER);
146: setXMLEditorCaretFilteringOn();
147: fileProject = "TestWebProject";
148: fileFolder = "";
149: fileName = "BigJSP.jsp";
150: menuItem = OPEN;
151: doMeasurement();
152: }
153:
154: public void testOpeningHTMLFile() {
155: WAIT_AFTER_OPEN = 3000;
156: //repaintManager().setOnlyEditor(true);
157: repaintManager()
158: .addRegionFilter(repaintManager().EDITOR_FILTER);
159: setXMLEditorCaretFilteringOn();
160: fileProject = "TestWebProject";
161: fileFolder = "";
162: fileName = "HTML.html";
163: menuItem = OPEN;
164: doMeasurement();
165: }
166:
167: public void testOpeningTagFile() {
168: WAIT_AFTER_OPEN = 3000;
169: //repaintManager().setOnlyEditor(true);
170: repaintManager()
171: .addRegionFilter(repaintManager().EDITOR_FILTER);
172: setXMLEditorCaretFilteringOn();
173: fileProject = "TestWebProject";
174: fileFolder = "WEB-INF|tags";
175: fileName = "mytag.tag";
176: menuItem = OPEN;
177: doMeasurement();
178: }
179:
180: public void testOpeningTldFile() {
181: WAIT_AFTER_OPEN = 3000;
182: //repaintManager().setOnlyEditor(true);
183: repaintManager()
184: .addRegionFilter(repaintManager().EDITOR_FILTER);
185: setXMLEditorCaretFilteringOn();
186: fileProject = "TestWebProject";
187: fileFolder = "WEB-INF";
188: fileName = "MyTLD.tld";
189: menuItem = OPEN;
190: doMeasurement();
191: }
192:
193: public void initialize() {
194: EditorOperator.closeDiscardAll();
195: }
196:
197: public void shutdown() {
198: EditorOperator.closeDiscardAll();
199: //repaintManager().setOnlyEditor(false);
200: repaintManager().resetRegionFilters();
201:
202: }
203:
204: public void prepare() {
205: System.out.println("PREPARE: " + WEB_PAGES
206: + (fileFolder.equals("") ? "" : "|") + fileFolder + '|'
207: + fileName);
208: this .openNode = new Node(new ProjectsTabOperator()
209: .getProjectRootNode(fileProject), WEB_PAGES
210: + (fileFolder.equals("") ? "" : "|") + fileFolder + '|'
211: + fileName);
212:
213: if (this .openNode == null) {
214: fail("Cannot find node [" + WEB_PAGES
215: + (fileFolder.equals("") ? "" : "|") + fileFolder
216: + '|' + fileName + "] in project [" + fileProject
217: + "]");
218: }
219: log("========== Open file path =" + this .openNode.getPath());
220: }
221:
222: public ComponentOperator open() {
223: JPopupMenuOperator popup = this .openNode.callPopup();
224: if (popup == null) {
225: fail("Cannot get context menu for node [" + WEB_PAGES
226: + (fileFolder.equals("") ? "" : "|") + fileFolder
227: + '|' + fileName + "] in project [" + fileProject
228: + "]");
229: }
230: log("------------------------- after popup invocation ------------");
231: try {
232: popup.pushMenu(this .menuItem);
233: } catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
234: fail("Cannot push menu item " + this .menuItem
235: + " of node [" + WEB_PAGES
236: + (fileFolder.equals("") ? "" : "|") + fileFolder
237: + '|' + fileName + "] in project [" + fileProject
238: + "]");
239: }
240: log("------------------------- after open ------------");
241: // // XXX wrappedEditorOperator hack for web.xml editor
242: // if (wrappedEditorOperator) {
243: // return new TopComponentOperator(this.fileName);
244: // } else {
245: return null;
246: // }
247: }
248:
249: public void close() {
250: EditorOperator edior = new EditorOperator(this .fileName);
251: if (edior == null) {
252: edior.closeDiscard();
253: }
254: // else {
255: // fail ("no component to close");
256: // }
257: //repaintManager().setOnlyEditor(false);
258: repaintManager().resetRegionFilters();
259:
260: }
261:
262: private void setWrappedClonableEditor(boolean value) {
263: wrappedEditorOperator = value;
264: }
265:
266: }
|