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 gui.actions;
043:
044: import gui.MPUtilities;
045: import gui.window.MIDletEditorOperator;
046: import org.netbeans.jellytools.EditorOperator;
047: import org.netbeans.jellytools.ProjectsTabOperator;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jemmy.TimeoutExpiredException;
050: import org.netbeans.jemmy.operators.ComponentOperator;
051: import org.netbeans.jemmy.operators.JPopupMenuOperator;
052:
053: /**
054: *
055: * @author mkhramov@netbeans.org
056: */
057: public class OpenMIDletEditor extends
058: org.netbeans.performance.test.utilities.PerformanceTestCase {
059:
060: private Node openNode;
061: private String targetProject;
062: private String midletName;
063: private ProjectsTabOperator pto;
064:
065: protected static String OPEN = org.netbeans.jellytools.Bundle
066: .getStringTrimmed("org.openide.actions.Bundle", "Open");
067:
068: /**
069: * Creates a new instance of OpenMIDletEditor
070: * @param testName the name of the test
071: */
072: public OpenMIDletEditor(String testName) {
073: super (testName);
074: targetProject = "MobileApplicationVisualMIDlet";
075: midletName = "VisualMIDletMIDP20.java";
076: expectedTime = WINDOW_OPEN;
077: WAIT_AFTER_OPEN = 20000;
078: }
079:
080: /**
081: * Creates a new instance of OpenMIDletEditor
082: * @param testName the name of the test
083: * @param performanceDataName measured values will be saved under this name
084: */
085: public OpenMIDletEditor(String testName, String performanceDataName) {
086: super (testName, performanceDataName);
087: targetProject = "MobileApplicationVisualMIDlet";
088: midletName = "VisualMIDletMIDP20.java";
089: expectedTime = WINDOW_OPEN;
090: WAIT_AFTER_OPEN = 20000;
091: }
092:
093: public void initialize() {
094: log(":: initialize");
095: EditorOperator.closeDiscardAll();
096: pto = ProjectsTabOperator.invoke();
097: }
098:
099: public void prepare() {
100: log(":: prepare");
101: String documentPath = MPUtilities.SOURCE_PACKAGES + "|"
102: + "allComponents" + "|" + midletName;
103:
104: long nodeTimeout = pto.getTimeouts().getTimeout(
105: "ComponentOperator.WaitStateTimeout");
106: pto.getTimeouts().setTimeout(
107: "ComponentOperator.WaitStateTimeout", 60000);
108:
109: try {
110: openNode = new Node(pto.getProjectRootNode(targetProject),
111: documentPath);
112: } catch (TimeoutExpiredException ex) {
113: pto.getTimeouts().setTimeout(
114: "ComponentOperator.WaitStateTimeout", nodeTimeout);
115: throw new Error(
116: "Cannot find expected node because of Timeout");
117: }
118: pto.getTimeouts().setTimeout(
119: "ComponentOperator.WaitStateTimeout", nodeTimeout);
120:
121: if (this .openNode == null) {
122: throw new Error("Cannot find expected node ");
123: }
124: openNode.select();
125: }
126:
127: public ComponentOperator open() {
128: log(":: open");
129: JPopupMenuOperator popup = this .openNode.callPopup();
130: if (popup == null) {
131: throw new Error("Cannot get context menu for node ");
132: }
133: log("------------------------- after popup invocation ------------");
134: popup.getTimeouts().setTimeout("JMenuOperator.PushMenuTimeout",
135: 90000);
136: try {
137: popup.pushMenu(OPEN);
138: } catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
139: throw new Error("Cannot push menu item ");
140: }
141:
142: return MIDletEditorOperator
143: .findMIDletEditorOperator(midletName);
144: }
145:
146: public void close() {
147: log(":: close");
148: ((MIDletEditorOperator) testedComponentOperator).close();
149: }
150:
151: public void shutdown() {
152: log("::shutdown");
153: }
154:
155: }
|