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