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 prepare;
043:
044: import java.io.IOException;
045: import java.io.PrintStream;
046:
047: import org.netbeans.jellytools.Bundle;
048: import org.netbeans.jellytools.JellyTestCase;
049: import org.netbeans.jellytools.EditorOperator;
050: import org.netbeans.jellytools.ProjectsTabOperator;
051: import org.netbeans.jellytools.TopComponentOperator;
052: import org.netbeans.jellytools.MainWindowOperator;
053:
054: import org.netbeans.jellytools.actions.Action;
055: import org.netbeans.jellytools.actions.OpenAction;
056: import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
057: import org.netbeans.jellytools.nodes.Node;
058: import org.netbeans.jellytools.nodes.ProjectRootNode;
059: import org.netbeans.jellytools.nodes.SourcePackagesNode;
060:
061: import org.netbeans.jemmy.operators.JMenuBarOperator;
062: import org.netbeans.jemmy.operators.JMenuItemOperator;
063: import org.netbeans.jemmy.operators.JCheckBoxOperator;
064: import org.netbeans.jemmy.operators.Operator;
065:
066: import junit.framework.Test;
067:
068: import org.netbeans.junit.NbTestSuite;
069:
070: import org.netbeans.performance.test.utilities.MeasureStartupTimeTestCase;
071:
072: /**
073: * Prepare user directory for complex measurements (startup time and memory consumption) of IDE with opened project and 10 files.
074: * Open 10 java files and shut down ide.
075: * Created user directory will be used to measure startup time and memory consumption of IDE with opened files.
076: *
077: * @author Marian.Mirilovic@sun.com
078: */
079: public class PrepareIDEForComplexMeasurements extends JellyTestCase {
080:
081: /** Error output from the test. */
082: protected static PrintStream err;
083:
084: /** Logging output from the test. */
085: protected static PrintStream log;
086:
087: /** If true - at least one test failed */
088: protected static boolean test_failed = false;
089:
090: /** Define testcase
091: * @param testName name of the testcase
092: */
093: public PrepareIDEForComplexMeasurements(String testName) {
094: super (testName);
095: }
096:
097: /** Testsuite
098: * @return testuite
099: */
100: public static Test suite() {
101: NbTestSuite suite = new NbTestSuite();
102: suite.addTest(new PrepareIDEForComplexMeasurements(
103: "closeWelcome"));
104: suite.addTest(new PrepareIDEForComplexMeasurements(
105: "closeAllDocuments"));
106: suite.addTest(new PrepareIDEForComplexMeasurements(
107: "closeMemoryToolbar"));
108: suite
109: .addTest(new PrepareIDEForComplexMeasurements(
110: "openFiles"));
111: suite
112: .addTest(new PrepareIDEForComplexMeasurements(
113: "saveStatus"));
114: return suite;
115: }
116:
117: public void setUp() {
118: // err = System.out;
119: err = getLog();
120: log = getRef();
121: }
122:
123: /**
124: * Close Welcome.
125: */
126: public void closeWelcome() {
127: try {
128: Bundle.getStringTrimmed(
129: "org.netbeans.modules.welcome.Bundle",
130: "LBL_Tab_Title");
131: TopComponentOperator tComponent = new TopComponentOperator(
132: "Welcome");
133: new JCheckBoxOperator(tComponent, Bundle.getStringTrimmed(
134: "org.netbeans.modules.welcome.resources.Bundle",
135: "LBL_ShowOnStartup")).changeSelection(false);
136: tComponent.close();
137: } catch (Exception exc) {
138: test_failed = true;
139: fail(exc);
140: }
141: }
142:
143: /**
144: * Close All Documents.
145: */
146: public void closeAllDocuments() {
147:
148: if (new Action("Window|Close All Documents", null).isEnabled())
149: try {
150: new CloseAllDocumentsAction().perform();
151: } catch (Exception exc) {
152: test_failed = true;
153: fail(exc);
154: }
155:
156: }
157:
158: /**
159: * Close Memory Toolbar.
160: */
161: public static void closeMemoryToolbar() {
162: closeToolbar(Bundle.getStringTrimmed(
163: "org.netbeans.core.Bundle", "Menu/View")
164: + "|"
165: + Bundle.getStringTrimmed(
166: "org.netbeans.core.windows.actions.Bundle",
167: "CTL_ToolbarsListAction")
168: + "|"
169: + Bundle.getStringTrimmed("org.netbeans.core.Bundle",
170: "Toolbars/Memory"));
171: }
172:
173: private static void closeToolbar(String menu) {
174: MainWindowOperator mainWindow = MainWindowOperator.getDefault();
175: JMenuBarOperator menuBar = new JMenuBarOperator(mainWindow
176: .getJMenuBar());
177: JMenuItemOperator menuItem = menuBar.showMenuItem(menu, "|");
178:
179: if (menuItem.isSelected())
180: menuItem.push();
181: else {
182: menuItem.pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
183: mainWindow.pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
184: }
185: }
186:
187: /**
188: * Open 10 selected files from jEdit project.
189: */
190: public void openFiles() {
191:
192: try {
193: String[][] files_path = { { "bsh", "Interpreter.java" },
194: { "bsh", "JThis.java" }, { "bsh", "Name.java" },
195: { "bsh", "Parser.java" },
196: { "bsh", "Primitive.java" },
197: { "com.microstar.xml", "XmlParser.java" },
198: { "org.gjt.sp.jedit", "BeanShell.java" },
199: { "org.gjt.sp.jedit", "Buffer.java" },
200: { "org.gjt.sp.jedit", "EditPane.java" },
201: { "org.gjt.sp.jedit", "EditPlugin.java" },
202: { "org.gjt.sp.jedit", "EditServer.java" } };
203:
204: Node[] openFileNodes = new Node[files_path.length];
205: Node node;
206:
207: // try to workarround problems with tooltip on Win2K & WinXP - issue 56825
208: ProjectRootNode projectNode = new ProjectsTabOperator()
209: .getProjectRootNode("jEdit");
210: projectNode.expand();
211:
212: SourcePackagesNode sourceNode = new SourcePackagesNode(
213: projectNode);
214: sourceNode.expand();
215:
216: // create exactly (full match) and case sensitively comparing comparator
217: Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(
218: true, true);
219: sourceNode.setComparator(comparator);
220:
221: for (int i = 0; i < files_path.length; i++) {
222: node = new Node(sourceNode, files_path[i][0]);
223: node.expand();
224:
225: openFileNodes[i] = new Node(node, files_path[i][1]);
226:
227: //try to avoid issue 56825
228: openFileNodes[i].select();
229:
230: // open file one by one, opening all files at once causes never ending loop (java+mdr)
231: //new OpenAction().performAPI(openFileNodes[i]);
232: }
233:
234: // try to come back and open all files at-once, rises another problem with refactoring, if you do open file and next expand folder,
235: // it doesn't finish in the real-time -> hard to reproduced by hand
236: try {
237: new OpenAction().performAPI(openFileNodes);
238: } catch (Exception exc) {
239: err.println("---------------------------------------");
240: err
241: .println("issue 56825 : EXCEPTION catched during OpenAction");
242: exc.printStackTrace(err);
243: err.println("---------------------------------------");
244: err.println("issue 56825 : Try it again");
245: new OpenAction().performAPI(openFileNodes);
246: err.println("issue 56825 : Success");
247: }
248:
249: // check whether files are opened in editor
250: for (int i = 0; i < files_path.length; i++) {
251: new EditorOperator(files_path[i][1]);
252: }
253: // new org.netbeans.jemmy.EventTool().waitNoEvent(60000);
254:
255: } catch (Exception exc) {
256: test_failed = true;
257: fail(exc);
258: }
259: }
260:
261: /**
262: * Save status, if one of the above defined test failed, this method creates
263: * file in predefined path and it means the complex tests will not run.
264: */
265: public void saveStatus() throws IOException {
266: if (test_failed)
267: MeasureStartupTimeTestCase.createStatusFile();
268: }
269:
270: }
|