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 OpenServletFile 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 filePackage;
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: /**
079: * Creates a new instance of OpenFiles
080: * @param testName the name of the test
081: */
082: public OpenServletFile(String testName) {
083: super (testName);
084: expectedTime = WINDOW_OPEN;
085: }
086:
087: /**
088: * Creates a new instance of OpenFiles
089: * @param testName the name of the test
090: * @param performanceDataName measured values will be saved under this name
091: */
092: public OpenServletFile(String testName, String performanceDataName) {
093: super (testName, performanceDataName);
094: expectedTime = WINDOW_OPEN;
095: }
096:
097: public void testOpeningServletFile() {
098: WAIT_AFTER_OPEN = 6000;
099: //repaintManager().setOnlyEditor(true);
100: repaintManager()
101: .addRegionFilter(repaintManager().EDITOR_FILTER);
102: setJavaEditorCaretFilteringOn();
103: fileProject = "TestWebProject";
104: filePackage = "test";
105: fileName = "TestServlet.java";
106: menuItem = OPEN;
107: doMeasurement();
108: }
109:
110: public void testOpeningJavaFile() {
111: WAIT_AFTER_OPEN = 6000;
112: //repaintManager().setOnlyEditor(true);
113: repaintManager()
114: .addRegionFilter(repaintManager().EDITOR_FILTER);
115: setJavaEditorCaretFilteringOn();
116: fileProject = "TestWebProject";
117: filePackage = "test";
118: fileName = "Main.java";
119: menuItem = OPEN;
120: doMeasurement();
121: }
122:
123: public void initialize() {
124: EditorOperator.closeDiscardAll();
125: }
126:
127: public void shutdown() {
128: EditorOperator.closeDiscardAll();
129: }
130:
131: public void prepare() {
132: this .openNode = new Node(new ProjectsTabOperator()
133: .getProjectRootNode(fileProject), "Source Packages"
134: + '|' + filePackage + '|' + fileName);
135:
136: if (this .openNode == null) {
137: fail("Cannot find node [" + "Source Packages" + '|'
138: + filePackage + '|' + fileName + "] in project ["
139: + fileProject + "]");
140: }
141: log("========== Open file path =" + this .openNode.getPath());
142: }
143:
144: public ComponentOperator open() {
145: JPopupMenuOperator popup = this .openNode.callPopup();
146: if (popup == null) {
147: fail("Cannot get context menu for node ["
148: + "Source Packages" + '|' + filePackage + '|'
149: + fileName + "] in project [" + fileProject + "]");
150: }
151: log("------------------------- after popup invocation ------------");
152: try {
153: popup.pushMenu(this .menuItem);
154: } catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
155: fail("Cannot push menu item " + this .menuItem
156: + " of node [" + "Source Packages" + '|'
157: + filePackage + '|' + fileName + "] in project ["
158: + fileProject + "]");
159: }
160: log("------------------------- after open ------------");
161: return new EditorOperator(this .fileName);
162: }
163:
164: public void close() {
165: //repaintManager().setOnlyEditor(false);
166: repaintManager().resetRegionFilters(); // added - was missing
167: if (testedComponentOperator != null) {
168: ((EditorOperator) testedComponentOperator).closeDiscard();
169: } else {
170: fail("no component to close");
171: }
172: }
173:
174: }
|