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 java.util.HashMap;
045: import org.netbeans.jellytools.EditorOperator;
046: import org.netbeans.jellytools.ProjectsTabOperator;
047: import org.netbeans.jellytools.TopComponentOperator;
048: import org.netbeans.jellytools.actions.SaveAllAction;
049: import org.netbeans.jellytools.nodes.Node;
050: import org.netbeans.jellytools.nodes.ProjectRootNode;
051:
052: import org.netbeans.jemmy.operators.ComponentOperator;
053: import org.netbeans.jemmy.operators.JPopupMenuOperator;
054: import org.netbeans.jemmy.operators.JTreeOperator;
055: import org.netbeans.jemmy.operators.Operator;
056: import org.netbeans.modules.editor.java.JavaKit;
057: import org.netbeans.modules.editor.options.BaseOptions;
058:
059: /**
060: * Test of opening files.
061: *
062: * @author lmartinek@netbeans.org
063: */
064: public class OpenJ2EEFiles extends
065: org.netbeans.performance.test.utilities.PerformanceTestCase {
066:
067: /** Node to be opened/edited */
068: public static Node openNode;
069:
070: /** Folder with data */
071: public static String fileProject;
072:
073: /** Folder with data */
074: public static String filePath;
075:
076: /** Name of file to open */
077: public static String editorTitle;
078:
079: /** Menu item name that opens the editor */
080: public static String menuItem;
081:
082: protected static String OPEN = org.netbeans.jellytools.Bundle
083: .getStringTrimmed("org/openide/actions/Bundle", "Open");
084:
085: protected static String EDIT = org.netbeans.jellytools.Bundle
086: .getStringTrimmed("org/openide/actions/Bundle", "Edit");
087:
088: /**
089: * Creates a new instance of OpenFiles
090: * @param testName the name of the test
091: */
092: public OpenJ2EEFiles(String testName) {
093: super (testName);
094: expectedTime = WINDOW_OPEN;
095: }
096:
097: /**
098: * Creates a new instance of OpenFiles
099: * @param testName the name of the test
100: * @param performanceDataName measured values will be saved under this name
101: */
102: public OpenJ2EEFiles(String testName, String performanceDataName) {
103: super (testName, performanceDataName);
104: expectedTime = WINDOW_OPEN;
105: }
106:
107: public void testOpeningJava() {
108: WAIT_AFTER_OPEN = 4000;
109: //MEASURE_PAINT_NUMBER = 1;
110: setJavaEditorCaretFilteringOn();
111: fileProject = "TestApplication-EJBModule";
112: filePath = "Source Packages|test|TestSessionRemote.java";
113: editorTitle = "TestSessionRemote.java";
114: menuItem = OPEN;
115: //repaintManager().setOnlyEditor(true);
116: repaintManager()
117: .addRegionFilter(repaintManager().EDITOR_FILTER);
118: doMeasurement();
119: }
120:
121: public void testOpeningSessionBean() {
122: WAIT_AFTER_OPEN = 4000;
123: //MEASURE_PAINT_NUMBER = 1;
124: setJavaEditorCaretFilteringOn();
125: fileProject = "TestApplication-EJBModule";
126: filePath = "Enterprise Beans|TestSessionSB";
127: editorTitle = "TestSessionBean.java";
128: menuItem = OPEN;
129: //repaintManager().setOnlyEditor(true);
130: repaintManager()
131: .addRegionFilter(repaintManager().EDITOR_FILTER);
132: doMeasurement();
133: }
134:
135: public void testOpeningEntityBean() {
136: WAIT_AFTER_OPEN = 4000;
137: //MEASURE_PAINT_NUMBER = 1;
138: setJavaEditorCaretFilteringOn();
139: fileProject = "TestApplication-EJBModule";
140: filePath = "Enterprise Beans|TestEntityEB";
141: editorTitle = "TestEntityBean.java";
142: menuItem = OPEN;
143: //repaintManager().setOnlyEditor(true);
144: repaintManager()
145: .addRegionFilter(repaintManager().EDITOR_FILTER);
146: doMeasurement();
147: }
148:
149: public void testOpeningEjbJarXml() {
150: WAIT_AFTER_OPEN = 3000;
151: //MEASURE_PAINT_NUMBER = 1;
152: setJavaEditorCaretFilteringOn();
153: fileProject = "TestApplication-EJBModule";
154: filePath = "Configuration Files|ejb-jar.xml";
155: editorTitle = "ejb-jar.xml";
156: menuItem = OPEN;
157: //repaintManager().setOnlyEditor(false);
158: repaintManager().resetRegionFilters();
159: doMeasurement();
160: }
161:
162: public void testOpeningSunEjbJarXml() {
163: WAIT_AFTER_OPEN = 3000;
164: //MEASURE_PAINT_NUMBER = 1;
165: setJavaEditorCaretFilteringOn();
166: fileProject = "TestApplication-EJBModule";
167: filePath = "Configuration Files|sun-ejb-jar.xml";
168: editorTitle = "sun-ejb-jar.xml";
169: menuItem = OPEN;
170: //repaintManager().setOnlyEditor(false);
171: repaintManager().resetRegionFilters();
172: doMeasurement();
173: }
174:
175: public void testOpeningApplicationXml() {
176: WAIT_AFTER_OPEN = 2000;
177: //MEASURE_PAINT_NUMBER = 1;
178: setJavaEditorCaretFilteringOn();
179: fileProject = "TestApplication";
180: filePath = "Configuration Files|application.xml";
181: editorTitle = "application.xml";
182: menuItem = EDIT;
183: //repaintManager().setOnlyEditor(true);
184: repaintManager()
185: .addRegionFilter(repaintManager().EDITOR_FILTER);
186: doMeasurement();
187: }
188:
189: public void testOpeningSunApplicationXml() {
190: WAIT_AFTER_OPEN = 2000;
191: //MEASURE_PAINT_NUMBER = 1;
192: setJavaEditorCaretFilteringOn();
193: fileProject = "TestApplication";
194: filePath = "Configuration Files|sun-application.xml";
195: editorTitle = "sun-application.xml";
196: menuItem = OPEN;
197: //repaintManager().setOnlyEditor(false);
198: repaintManager().resetRegionFilters();
199: doMeasurement();
200: }
201:
202: public void initialize() {
203: //repaintManager().setOnlyEditor(true);
204: EditorOperator.closeDiscardAll();
205: BaseOptions options = BaseOptions.getOptions(JavaKit.class);
206: options.setStatusBarCaretDelay(0);
207: HashMap props = new HashMap();
208: props.put(
209: org.netbeans.editor.SettingsNames.CODE_FOLDING_ENABLE,
210: Boolean.FALSE);
211: options.setCodeFoldingProps(props);
212: /* TODO doesn't work after retouche integration
213: JavaSettings java_settings = JavaSettings.getDefault();
214: java_settings.setShowOverriding(false);
215: java_settings.enableCompileStatus(false);
216: */
217: }
218:
219: public void shutdown() {
220: //repaintManager().setOnlyEditor(false);
221: repaintManager().resetRegionFilters();
222: EditorOperator.closeDiscardAll();
223: }
224:
225: public void prepare() {
226: JTreeOperator tree = new ProjectsTabOperator().tree();
227: tree.setComparator(new Operator.DefaultStringComparator(true,
228: true));
229: this .openNode = new Node(
230: new ProjectRootNode(tree, fileProject), filePath);
231:
232: if (this .openNode == null) {
233: throw new Error("Cannot find node [" + filePath
234: + "] in project [" + fileProject + "]");
235: }
236: log("========== Open file path =" + this .openNode.getPath());
237: }
238:
239: public ComponentOperator open() {
240: JPopupMenuOperator popup = this .openNode.callPopup();
241: if (popup == null) {
242: throw new Error("Cannot get context menu for node ["
243: + filePath + "] in project [" + fileProject + "]");
244: }
245: log("------------------------- after popup invocation ------------");
246: try {
247: popup.pushMenu(this .menuItem);
248: } catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
249: throw new Error("Cannot push menu item " + this .menuItem
250: + " of node [" + filePath + "] in project ["
251: + fileProject + "]");
252: }
253: log("------------------------- after open ------------");
254: return new TopComponentOperator(this .editorTitle);
255: }
256:
257: public void close() {
258: if (testedComponentOperator != null) {
259: // HACK
260: new SaveAllAction().performAPI();
261: ((TopComponentOperator) testedComponentOperator).close();
262: /*
263: if (getName().equals("testOpeningSunApplicationXml")) {
264: ((TopComponentOperator)testedComponentOperator).close();
265: } else {
266: ((TopComponentOperator)testedComponentOperator).closeDiscard();
267: }
268: */
269: } else {
270: throw new Error("no component to close");
271: }
272: }
273:
274: }
|