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 org.netbeans.jellytools.EditorOperator;
045: import org.netbeans.jellytools.ProjectsTabOperator;
046: import org.netbeans.jellytools.TopComponentOperator;
047: import org.netbeans.jellytools.nodes.Node;
048:
049: import org.netbeans.jemmy.operators.ComponentOperator;
050: import org.netbeans.jemmy.operators.JPopupMenuOperator;
051: import org.netbeans.performance.test.guitracker.LoggingRepaintManager.RegionFilter;
052:
053: /**
054: *
055: * @author mkhramov@netbeans.org, mmirilovic@netbeans.org
056: */
057: public class OpenNavigationPage extends
058: org.netbeans.performance.test.utilities.PerformanceTestCase {
059:
060: /** Node to be opened/edited */
061: private static Node openNode;
062:
063: private static String openNodeName;
064:
065: protected static String OPEN = org.netbeans.jellytools.Bundle
066: .getStringTrimmed("org.openide.actions.Bundle", "Open");
067:
068: /** Creates a new instance of OpenNavigationPage */
069: public OpenNavigationPage(String testName) {
070: super (testName);
071: expectedTime = WINDOW_OPEN;
072: WAIT_AFTER_OPEN = 20000;
073: }
074:
075: public OpenNavigationPage(String testName,
076: String performanceDataName) {
077: super (testName, performanceDataName);
078: expectedTime = WINDOW_OPEN;
079: WAIT_AFTER_OPEN = 20000;
080: }
081:
082: protected void initialize() {
083: log("::initialize::");
084: EditorOperator.closeDiscardAll();
085: repaintManager().addRegionFilter(NAVIGATION_FILTER);
086: }
087:
088: public void prepare() {
089: log("::prepare::");
090:
091: openNodeName = org.netbeans.jellytools.Bundle.getString(
092: "org.netbeans.modules.web.project.ui.Bundle",
093: "LBL_Node_Config")
094: + "|" + "faces-config.xml"; // NOI18N
095: Node projectRoot = null;
096: try {
097: projectRoot = new ProjectsTabOperator()
098: .getProjectRootNode("VisualWebProject");
099: projectRoot.select();
100: openNode = new Node(projectRoot, openNodeName);
101: openNode.select();
102:
103: } catch (org.netbeans.jemmy.TimeoutExpiredException ex) {
104: fail("Cannot find and select project node");
105: }
106:
107: if (this .openNode == null) {
108: throw new Error("Cannot find node " + openNodeName);
109: }
110: log("========== Open file path =" + this .openNode.getPath());
111: }
112:
113: public ComponentOperator open() {
114: JPopupMenuOperator popup = this .openNode.callPopup();
115: if (popup == null) {
116: throw new Error("Cannot get context menu for node "
117: + openNodeName);
118: }
119: log("------------------------- after popup invocation ------------");
120: try {
121: popup.pushMenu(OPEN);
122: } catch (org.netbeans.jemmy.TimeoutExpiredException tee) {
123: throw new Error("Cannot push menu item Open on node "
124: + openNodeName);
125: }
126: log("------------------------- after open ------------");
127: return new TopComponentOperator("faces-config.xml", 0); // NOI18N
128: }
129:
130: public void close() {
131: ((TopComponentOperator) this .testedComponentOperator).close();
132: }
133:
134: protected void shutdown() {
135: log("::shutdwown");
136: repaintManager().resetRegionFilters();
137: super .shutdown();
138: }
139:
140: public static void main(String[] args) {
141: junit.textui.TestRunner.run(new OpenNavigationPage(
142: "measureTime"));
143: }
144:
145: private static final RegionFilter NAVIGATION_FILTER = new RegionFilter() {
146:
147: public boolean accept(javax.swing.JComponent c) {
148: return c.getClass().getName().equals(
149: "org.netbeans.api.visual.widget.SceneComponent");
150: }
151:
152: public String getFilterName() {
153: return "Accept paints from org.netbeans.api.visual.widget.SceneComponent";
154: }
155: };
156:
157: }
|