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 javax.swing.tree.TreePath;
048: import org.netbeans.jellytools.Bundle;
049: import org.netbeans.jellytools.JellyTestCase;
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.EditAction;
057: import org.netbeans.jellytools.actions.CloseAllDocumentsAction;
058: import org.netbeans.jellytools.nodes.Node;
059: import org.netbeans.jellytools.nodes.ProjectRootNode;
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.jellytools.NbDialogOperator;
069: import org.netbeans.jellytools.RuntimeTabOperator;
070: import org.netbeans.jemmy.operators.JButtonOperator;
071: import org.netbeans.jemmy.operators.JListOperator;
072: import org.netbeans.jemmy.operators.JPopupMenuOperator;
073: import org.netbeans.jemmy.operators.JTextFieldOperator;
074: import org.netbeans.jemmy.operators.JTreeOperator;
075: import org.netbeans.junit.NbTestSuite;
076: import org.netbeans.junit.ide.ProjectSupport;
077:
078: import org.netbeans.performance.test.utilities.MeasureStartupTimeTestCase;
079:
080: /**
081: * Prepare user directory for complex measurements (startup time and memory consumption) of IDE with opened project and 10 files.
082: * Open 10 java files and shut down ide.
083: * Created user directory will be used to measure startup time and memory consumption of IDE with opened files.
084: *
085: * @author mmirilovic@netbeans.org, mrkam@netbeans.org
086: */
087: public class PrepareIDEForEnterpriseComplexMeasurements extends
088: JellyTestCase {
089:
090: /** Error output from the test. */
091: protected static java.io.PrintStream err;
092:
093: /** Logging output from the test. */
094: protected static java.io.PrintStream log;
095:
096: /** If true - at least one test failed */
097: protected static boolean test_failed = false;
098:
099: /** Define testcase
100: * @param testName name of the testcase
101: */
102: public PrepareIDEForEnterpriseComplexMeasurements(String testName) {
103: super (testName);
104: }
105:
106: /** Testsuite
107: * @return testuite
108: */
109: public static Test suite() {
110: NbTestSuite suite = new NbTestSuite();
111: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
112: "closeWelcome"));
113: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
114: "closeAllDocuments"));
115: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
116: "closeMemoryToolbar"));
117: //FIXME: Remove manual addition of Application Server
118: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
119: "addApplicationServer"));
120: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
121: "openProjects"));
122: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
123: "openFiles"));
124: suite.addTest(new PrepareIDEForEnterpriseComplexMeasurements(
125: "saveStatus"));
126: return suite;
127: }
128:
129: public void setUp() {
130: // err = System.out;
131: err = getLog();
132: log = getRef();
133: }
134:
135: public void addApplicationServer() {
136: // FIXME: Make a call of the following method
137: // Utilities.addApplicationServer();
138: String appServerPath = System
139: .getProperty("com.sun.aas.installRoot");
140:
141: if (appServerPath == null) {
142: throw new Error(
143: "Can't add application server. com.sun.aas.installRoot property is not set.");
144: }
145:
146: String addServerMenuItem = Bundle
147: .getStringTrimmed(
148: "org.netbeans.modules.j2ee.deployment.impl.ui.actions.Bundle",
149: "LBL_Add_Server_Instance"); // Add Server...
150: String addServerInstanceDialogTitle = Bundle
151: .getStringTrimmed(
152: "org.netbeans.modules.j2ee.deployment.impl.ui.wizard.Bundle",
153: "LBL_ASIW_Title"); //"Add Server Instance"
154: String glassFishV2ListItem = Bundle.getStringTrimmed(
155: "org.netbeans.modules.j2ee.sun.ide.Bundle",
156: "LBL_GlassFishV2");
157: String nextButtonCaption = Bundle.getStringTrimmed(
158: "org.openide.Bundle", "CTL_NEXT");
159: String finishButtonCaption = Bundle.getStringTrimmed(
160: "org.openide.Bundle", "CTL_FINISH");
161:
162: RuntimeTabOperator rto = RuntimeTabOperator.invoke();
163: JTreeOperator runtimeTree = rto.tree();
164:
165: long oldTimeout = runtimeTree.getTimeouts().getTimeout(
166: "JTreeOperator.WaitNextNodeTimeout");
167: runtimeTree.getTimeouts().setTimeout(
168: "JTreeOperator.WaitNextNodeTimeout", 60000);
169:
170: TreePath path = runtimeTree.findPath("Servers");
171: runtimeTree.selectPath(path);
172:
173: new JPopupMenuOperator(runtimeTree.callPopupOnPath(path))
174: .pushMenuNoBlock(addServerMenuItem);
175:
176: NbDialogOperator addServerInstanceDialog = new NbDialogOperator(
177: addServerInstanceDialogTitle);
178:
179: new JListOperator(addServerInstanceDialog, 1)
180: .selectItem(glassFishV2ListItem);
181:
182: new JButtonOperator(addServerInstanceDialog, nextButtonCaption)
183: .push();
184:
185: new JTextFieldOperator(addServerInstanceDialog)
186: .enterText(appServerPath);
187:
188: new JButtonOperator(addServerInstanceDialog,
189: finishButtonCaption).push();
190:
191: runtimeTree.getTimeouts().setTimeout(
192: "JTreeOperator.WaitNextNodeTimeout", oldTimeout);
193: }
194:
195: /**
196: * Close Welcome.
197: */
198: public void closeWelcome() {
199: try {
200: TopComponentOperator tComponent = new TopComponentOperator(
201: Bundle.getStringTrimmed(
202: "org.netbeans.modules.welcome.Bundle",
203: "LBL_Tab_Title"));
204: new JCheckBoxOperator(tComponent, Bundle.getStringTrimmed(
205: "org.netbeans.modules.welcome.resources.Bundle",
206: "LBL_ShowOnStartup")).changeSelection(false);
207: tComponent.close();
208: } catch (Exception exc) {
209: test_failed = true;
210: fail(exc);
211: }
212: }
213:
214: /**
215: * Close All Documents.
216: */
217: public void closeAllDocuments() {
218:
219: if (new Action("Window|Close All Documents", null).isEnabled())
220: try {
221: new CloseAllDocumentsAction().perform();
222: } catch (Exception exc) {
223: test_failed = true;
224: fail(exc);
225: }
226:
227: }
228:
229: /**
230: * Close Memory Toolbar.
231: */
232: public static void closeMemoryToolbar() {
233: closeToolbar(Bundle.getStringTrimmed(
234: "org.netbeans.core.Bundle", "Menu/View")
235: + "|"
236: + Bundle.getStringTrimmed(
237: "org.netbeans.core.windows.actions.Bundle",
238: "CTL_ToolbarsListAction")
239: + "|"
240: + Bundle.getStringTrimmed("org.netbeans.core.Bundle",
241: "Toolbars/Memory"));
242: }
243:
244: private static void closeToolbar(String menu) {
245: MainWindowOperator mainWindow = MainWindowOperator.getDefault();
246: JMenuBarOperator menuBar = new JMenuBarOperator(mainWindow
247: .getJMenuBar());
248: JMenuItemOperator menuItem = menuBar.showMenuItem(menu, "|");
249:
250: if (menuItem.isSelected())
251: menuItem.push();
252: else {
253: menuItem.pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
254: mainWindow.pushKey(java.awt.event.KeyEvent.VK_ESCAPE);
255: }
256: }
257:
258: /**
259: * Open Travel Reservation projects
260: */
261: public void openProjects() {
262: try {
263: String projectsLocation = System
264: .getProperty("xtest.tmpdir")
265: + File.separator
266: + "TravelReservationService"
267: + File.separator;
268: ProjectSupport.openProject(projectsLocation
269: + "ReservationPartnerServices");
270: ProjectSupport.waitScanFinished();
271: ProjectSupport.openProject(projectsLocation
272: + "TravelReservationService");
273: ProjectSupport.waitScanFinished();
274: ProjectSupport.openProject(projectsLocation
275: + "TravelReservationServiceApplication");
276: ProjectSupport.waitScanFinished();
277: // TODO: Remove this workaround: closing all modals
278: closeAllModal();
279: } catch (Exception exc) {
280: test_failed = true;
281: fail(exc);
282: }
283: }
284:
285: /**
286: * Open 10 selected files from Travel Reservation projects
287: */
288: public void openFiles() {
289: String OPEN = "Open";
290: String EDIT = "Edit";
291:
292: try {
293: String[][] nodes_path = {
294: { "ReservationPartnerServices", "Enterprise Beans",
295: "ReservationCallbackProviderMDB",
296: "ReservationCallbackProviderBean.java",
297: OPEN },
298: {
299: "ReservationPartnerServices",
300: "Source Packages",
301: "partnerservices|AirlineReservationPortType_Impl.java",
302: "AirlineReservationPortType_Impl.java",
303: OPEN },
304: {
305: "ReservationPartnerServices",
306: "Source Packages",
307: "partnerservices|HotelReservationPortType_Impl.java",
308: "HotelReservationPortType_Impl.java", OPEN },
309: {
310: "ReservationPartnerServices",
311: "Source Packages",
312: "partnerservices|VehicleReservationPortType_Impl.java",
313: "VehicleReservationPortType_Impl.java",
314: OPEN },
315: { "ReservationPartnerServices",
316: "Configuration Files", "ejb-jar.xml", null,
317: OPEN },
318: { "ReservationPartnerServices",
319: "Configuration Files", "sun-ejb-jar.xml",
320: null, EDIT },
321: { "TravelReservationService", "Process Files",
322: "AirlineReservationService.wsdl", null,
323: EDIT },
324: { "TravelReservationService", "Process Files",
325: "HotelReservationService.wsdl", null, EDIT },
326: { "TravelReservationService", "Process Files",
327: "OTA_TravelItinerary.xsd", null, OPEN },
328: { "TravelReservationService", "Process Files",
329: "TravelReservationService.bpel", null, OPEN } };
330:
331: ArrayList<Node> openFileNodes = new ArrayList<Node>();
332: ArrayList<Node> editFileNodes = new ArrayList<Node>();
333: Node node, fileNode;
334:
335: // create exactly (full match) and case sensitively comparing comparator
336: Operator.DefaultStringComparator comparator = new Operator.DefaultStringComparator(
337: true, true);
338:
339: for (int i = 0; i < nodes_path.length; i++) {
340: // try to workarround problems with tooltip on Win2K & WinXP - issue 56825
341: ProjectRootNode projectNode = new ProjectsTabOperator()
342: .getProjectRootNode(nodes_path[i][0]);
343: projectNode.expand();
344:
345: node = new Node(projectNode, nodes_path[i][1]);
346: node.setComparator(comparator);
347: node.expand();
348:
349: fileNode = new Node(node, nodes_path[i][2]);
350: //try to avoid issue 56825
351: fileNode.select();
352:
353: if (nodes_path[i][4].equals(OPEN)) {
354: openFileNodes.add(fileNode);
355: } else if (nodes_path[i][4].equals(EDIT)) {
356: editFileNodes.add(fileNode);
357: } else
358: throw new Exception("Not supported operation ["
359: + nodes_path[i][4] + "] for node: "
360: + fileNode.getPath());
361:
362: // open file one by one, opening all files at once causes never ending loop (java+mdr)
363: //new OpenAction().performAPI(openFileNodes[i]);
364: }
365:
366: // try to come back and open all files at-once, rises another problem with refactoring, if you do open file and next expand folder,
367: // it doesn't finish in the real-time -> hard to reproduced by hand
368: try {
369: new OpenAction().performAPI(openFileNodes
370: .toArray(new Node[0]));
371: new EditAction().performAPI(editFileNodes
372: .toArray(new Node[0]));
373: } catch (Exception exc) {
374: err.println("---------------------------------------");
375: err
376: .println("issue 56825 : EXCEPTION catched during OpenAction");
377: exc.printStackTrace(err);
378: err.println("---------------------------------------");
379: err.println("issue 56825 : Try it again");
380: new OpenAction().performAPI(openFileNodes
381: .toArray(new Node[0]));
382: new EditAction().performAPI(editFileNodes
383: .toArray(new Node[0]));
384: err.println("issue 56825 : Success");
385: }
386:
387: // check whether files are opened in editor
388: for (int i = 0; i < nodes_path.length; i++) {
389: if (nodes_path[i][3] != null)
390: new TopComponentOperator(nodes_path[i][3]);
391: else
392: new TopComponentOperator(nodes_path[i][2]);
393: }
394: // new org.netbeans.jemmy.EventTool().waitNoEvent(60000);
395:
396: } catch (Exception exc) {
397: test_failed = true;
398: fail(exc);
399: }
400: }
401:
402: /**
403: * Save status, if one of the above defined test failed, this method creates
404: * file in predefined path and it means the complex tests will not run.
405: */
406: public void saveStatus() throws java.io.IOException {
407: if (test_failed)
408: MeasureStartupTimeTestCase.createStatusFile();
409: }
410: }
|