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 gui.action;
043:
044: import gui.window.WebFormDesignerOperator;
045: import org.netbeans.jellytools.EditorOperator;
046: import org.netbeans.jellytools.ProjectsTabOperator;
047: import org.netbeans.jellytools.actions.OpenAction;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jemmy.JemmyProperties;
050: import org.netbeans.jemmy.operators.ComponentOperator;
051: import org.netbeans.jemmy.operators.JPopupMenuOperator;
052: import org.netbeans.junit.NbTestSuite;
053: import org.netbeans.progress.module.Controller;
054: import org.netbeans.progress.spi.InternalHandle;
055: import org.netbeans.progress.spi.TaskModel;
056:
057: /**
058: *
059: * @author mkhramov@netbeans.org
060: */
061: public class CleanAndBuildProject extends
062: org.netbeans.performance.test.utilities.PerformanceTestCase {
063: private String targetProject;
064: private Node proj;
065: private JPopupMenuOperator projectMenu;
066: private ProjectsTabOperator pto;
067: private String[] pagesToOpen;
068:
069: public CleanAndBuildProject(String testName) {
070: super (testName);
071: this .expectedTime = 10000;
072: }
073:
074: public CleanAndBuildProject(String testName,
075: String performanceDataName) {
076: super (testName, performanceDataName);
077: this .expectedTime = 10000;
078: }
079:
080: public void testCleanAndBuildSingleOpenedPageProject() {
081: targetProject = "UltraLargeWA";
082: pagesToOpen = new String[] { "Page1" };
083: doMeasurement();
084: }
085:
086: public void testCleanAndBuildMultipleOpenedPagesProject() {
087: targetProject = "UltraLargeWA";
088: pagesToOpen = new String[] { "Page1", "Page1_1" };
089: doMeasurement();
090:
091: }
092:
093: @Override
094: public void initialize() {
095: log("::initialize");
096: EditorOperator.closeDiscardAll();
097: pto = ProjectsTabOperator.invoke();
098: long oldTimeout = JemmyProperties
099: .getCurrentTimeout("ComponentOperator.WaitStateTimeout");
100: JemmyProperties.setCurrentTimeout(
101: "ComponentOperator.WaitStateTimeout", 120000);
102: for (String namme : pagesToOpen) {
103: System.out.println("Opening page " + namme);
104: Node docNode = new Node(pto
105: .getProjectRootNode(targetProject),
106: gui.VWPUtilities.WEB_PAGES + "|" + namme + ".jsp");
107: new OpenAction().performAPI(docNode);
108: WebFormDesignerOperator.findWebFormDesignerOperator(namme);
109: }
110: JemmyProperties.setCurrentTimeout(
111: "ComponentOperator.WaitStateTimeout", oldTimeout);
112: }
113:
114: public void prepare() {
115: log(":: prepare");
116: invokeProjectCleanAndBuild();
117: }
118:
119: public ComponentOperator open() {
120: waitForTask(targetProject + " (clean,dist)");
121: return null;
122: }
123:
124: @Override
125: public void shutdown() {
126: EditorOperator.closeDiscardAll();
127: }
128:
129: private static void waitForTask(String taskName) {
130: Controller controller = Controller.getDefault();
131: TaskModel model = controller.getModel();
132:
133: InternalHandle task = waitTaskHandle(model, taskName);
134:
135: int i = 0;
136: while (i < 12000) { // max 12000*50=600000=10 min
137: i++;
138: int state = task.getState();
139: if (state == InternalHandle.STATE_FINISHED) {
140: return;
141: }
142: try {
143: Thread.sleep(50);
144: } catch (InterruptedException exc) {
145: exc.printStackTrace(System.err);
146: return;
147: }
148: }
149: }
150:
151: private static InternalHandle waitTaskHandle(TaskModel model,
152: String taskName) {
153: for (int i = 0; i < 12000; i++) { // max 12000*50=600000=10 min
154: InternalHandle[] handles = model.getHandles();
155: InternalHandle serverTask = getTaskHandle(handles, taskName);
156: if (serverTask != null) {
157: return serverTask;
158: }
159:
160: try {
161: Thread.sleep(50);
162: } catch (InterruptedException exc) {
163: exc.printStackTrace(System.err);
164: }
165: }
166:
167: return null;
168: }
169:
170: /*
171: * This is copied from Utilities.java and just renamed to getTaskHandle()
172: */
173:
174: private static InternalHandle getTaskHandle(
175: InternalHandle[] handles, String taskName) {
176: if (handles.length == 0) {
177: return null;
178: }
179:
180: for (InternalHandle internalHandle : handles) {
181: if (internalHandle.getDisplayName().equals(taskName)) {
182: return internalHandle;
183: }
184: }
185: return null;
186: }
187:
188: private void invokeProjectCleanAndBuild() {
189: proj = null;
190: try {
191: proj = new ProjectsTabOperator()
192: .getProjectRootNode(targetProject);
193: proj.select();
194: } catch (org.netbeans.jemmy.TimeoutExpiredException ex) {
195: fail("Cannot find and select project root node");
196: }
197: projectMenu = proj.callPopup();
198: projectMenu.pushMenuNoBlock(org.netbeans.jellytools.Bundle
199: .getString(
200: "org.netbeans.modules.web.project.ui.Bundle",
201: "LBL_RebuildAction_Name"));
202:
203: }
204:
205: /** Creates suite from particular test cases. You can define order of testcases here. */
206: public static NbTestSuite suite() {
207: NbTestSuite suite = new NbTestSuite();
208: suite.addTest(new CleanAndBuildProject(
209: "testCleanAndBuildSingleOpenedPageProject"));
210: return suite;
211: }
212:
213: public static void main(String[] args) {
214: junit.textui.TestRunner.run(suite());
215: }
216:
217: }
|