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 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.EditAction;
056: import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
057: import org.netbeans.jellytools.nodes.Node;
058: import org.netbeans.jellytools.nodes.ProjectRootNode;
059:
060: import org.netbeans.jemmy.operators.JMenuBarOperator;
061: import org.netbeans.jemmy.operators.JMenuItemOperator;
062: import org.netbeans.jemmy.operators.JCheckBoxOperator;
063: import org.netbeans.jemmy.operators.Operator;
064:
065: import junit.framework.Test;
066:
067: import org.netbeans.junit.NbTestSuite;
068: import org.netbeans.junit.ide.ProjectSupport;
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 mmirilovic@netbeans.org
078: */
079: public class PrepareIDEForMobilityComplexMeasurements extends
080: JellyTestCase {
081:
082: /** Error output from the test. */
083: protected static java.io.PrintStream err;
084:
085: /** Logging output from the test. */
086: protected static java.io.PrintStream log;
087:
088: /** If true - at least one test failed */
089: protected static boolean test_failed = false;
090:
091: /** Define testcase
092: * @param testName name of the testcase
093: */
094: public PrepareIDEForMobilityComplexMeasurements(String testName) {
095: super (testName);
096: }
097:
098: /** Testsuite
099: * @return testuite
100: */
101: public static Test suite() {
102: NbTestSuite suite = new NbTestSuite();
103: suite.addTest(new PrepareIDEForMobilityComplexMeasurements(
104: "closeWelcome"));
105: suite.addTest(new PrepareIDEForMobilityComplexMeasurements(
106: "closeAllDocuments"));
107: suite.addTest(new PrepareIDEForMobilityComplexMeasurements(
108: "closeMemoryToolbar"));
109: suite.addTest(new PrepareIDEForMobilityComplexMeasurements(
110: "openProjects"));
111: suite.addTest(new PrepareIDEForMobilityComplexMeasurements(
112: "openFiles"));
113: suite.addTest(new PrepareIDEForMobilityComplexMeasurements(
114: "saveStatus"));
115: return suite;
116: }
117:
118: public void setUp() {
119: // err = System.out;
120: err = getLog();
121: log = getRef();
122: }
123:
124: /**
125: * Close Welcome.
126: */
127: public void closeWelcome() {
128: try {
129: Bundle.getStringTrimmed(
130: "org.netbeans.modules.welcome.Bundle",
131: "LBL_Tab_Title");
132: TopComponentOperator tComponent = new TopComponentOperator(
133: "Welcome");
134: new JCheckBoxOperator(tComponent, Bundle.getStringTrimmed(
135: "org.netbeans.modules.welcome.resources.Bundle",
136: "LBL_ShowOnStartup")).changeSelection(false);
137: tComponent.close();
138: } catch (Exception exc) {
139: test_failed = true;
140: fail(exc);
141: }
142: }
143:
144: /**
145: * Close All Documents.
146: */
147: public void closeAllDocuments() {
148:
149: if (new Action("Window|Close All Documents", null).isEnabled())
150: try {
151: new CloseAllDocumentsAction().perform();
152: } catch (Exception exc) {
153: test_failed = true;
154: fail(exc);
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 Mobility projects
189: */
190: public void openProjects() {
191: try {
192: String projectsLocation = System
193: .getProperty("xtest.tmpdir")
194: + File.separator;
195: ProjectSupport.openProject(projectsLocation
196: + "MobileApplicationSwitchConfiguration");
197: ProjectSupport.waitScanFinished();
198: ProjectSupport.openProject(projectsLocation
199: + "MobileApplicationVisualMIDlet");
200: ProjectSupport.waitScanFinished();
201: } catch (Exception exc) {
202: test_failed = true;
203: fail(exc);
204: }
205: }
206:
207: /**
208: * Open 3 selected files from Mobile projects
209: */
210: public void openFiles() {
211: String OPEN = "Open";
212: String EDIT = "Edit";
213:
214: try {
215: String[][] nodes_path = {
216: { "MobileApplicationSwitchConfiguration",
217: "Source Packages|switchit", "Midlet.java",
218: null, OPEN },
219: { "MobileApplicationVisualMIDlet",
220: "Source Packages|allComponents",
221: "VisualMIDletMIDP20.java", null, OPEN },
222: { "MobileApplicationVisualMIDlet",
223: "Source Packages|simple",
224: "VisualMIDlet.java", null, OPEN } };
225:
226: ArrayList<Node> openFileNodes = new ArrayList<Node>();
227: ArrayList<Node> editFileNodes = new ArrayList<Node>();
228: Node node, fileNode;
229:
230: // create exactly (full match) and case sensitively comparing comparator
231: Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(
232: true, true);
233:
234: for (int i = 0; i < nodes_path.length; i++) {
235: // try to workarround problems with tooltip on Win2K & WinXP - issue 56825
236: ProjectRootNode projectNode = new ProjectsTabOperator()
237: .getProjectRootNode(nodes_path[i][0]);
238: projectNode.expand();
239:
240: node = new Node(projectNode, nodes_path[i][1]);
241: node.setComparator(comparator);
242: node.expand();
243:
244: fileNode = new Node(node, nodes_path[i][2]);
245: //try to avoid issue 56825
246: fileNode.select();
247:
248: if (nodes_path[i][4].equals(OPEN)) {
249: openFileNodes.add(fileNode);
250: } else if (nodes_path[i][4].equals(EDIT)) {
251: editFileNodes.add(fileNode);
252: } else
253: throw new Exception("Not supported operation ["
254: + nodes_path[i][4] + "] for node: "
255: + fileNode.getPath());
256:
257: // open file one by one, opening all files at once causes never ending loop (java+mdr)
258: //new OpenAction().performAPI(openFileNodes[i]);
259: }
260:
261: // try to come back and open all files at-once, rises another problem with refactoring, if you do open file and next expand folder,
262: // it doesn't finish in the real-time -> hard to reproduced by hand
263: try {
264: new OpenAction().performAPI(openFileNodes
265: .toArray(new Node[0]));
266: //new EditAction().performAPI(editFileNodes.toArray(new Node[0]));
267: } catch (Exception exc) {
268: err.println("---------------------------------------");
269: err
270: .println("issue 56825 : EXCEPTION catched during OpenAction");
271: exc.printStackTrace(err);
272: err.println("---------------------------------------");
273: err.println("issue 56825 : Try it again");
274: new OpenAction().performAPI(openFileNodes
275: .toArray(new Node[0]));
276: //new EditAction().performAPI(editFileNodes.toArray(new Node[0]));
277: err.println("issue 56825 : Success");
278: }
279:
280: // check whether files are opened in editor
281: for (int i = 0; i < nodes_path.length; i++) {
282: if (nodes_path[i][3] != null)
283: new TopComponentOperator(nodes_path[i][3]);
284: else
285: new TopComponentOperator(nodes_path[i][2]);
286: }
287: // new org.netbeans.jemmy.EventTool().waitNoEvent(60000);
288:
289: } catch (Exception exc) {
290: test_failed = true;
291: fail(exc);
292: }
293: }
294:
295: /**
296: * Save status, if one of the above defined test failed, this method creates
297: * file in predefined path and it means the complex tests will not run.
298: */
299: public void saveStatus() throws java.io.IOException {
300: if (test_failed)
301: MeasureStartupTimeTestCase.createStatusFile();
302: }
303: }
|