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 footprint;
043:
044: import org.netbeans.jellytools.MainWindowOperator;
045: import org.netbeans.jellytools.NbDialogOperator;
046: import org.netbeans.jellytools.ProjectsTabOperator;
047: import org.netbeans.jellytools.TopComponentOperator;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.jellytools.nodes.SourcePackagesNode;
050:
051: import org.netbeans.jemmy.operators.ComponentOperator;
052: import org.netbeans.jemmy.operators.JButtonOperator;
053: import org.netbeans.jemmy.operators.JCheckBoxOperator;
054: import org.netbeans.jemmy.operators.JTextFieldOperator;
055: import org.netbeans.jemmy.QueueTool;
056:
057: import org.netbeans.junit.ide.ProjectSupport;
058:
059: import gui.Utilities;
060:
061: /**
062: * Measure Rename Class Memory footprint
063: *
064: * @author anebuzelsky@netbeans.org, mmirilovic@netbeans.org
065: */
066: public class RefactoringRename extends
067: org.netbeans.performance.test.utilities.MemoryFootprintTestCase {
068:
069: private static final String rename = "jEdit";
070:
071: /**
072: * Creates a new instance of RefactoringRename
073: *
074: * @param testName the name of the test
075: */
076: public RefactoringRename(String testName) {
077: super (testName);
078: prefix = "Refactoring Rename |";
079: }
080:
081: /**
082: * Creates a new instance of RefactoringRename
083: *
084: * @param testName the name of the test
085: * @param performanceDataName measured values will be saved under this name
086: */
087: public RefactoringRename(String testName, String performanceDataName) {
088: super (testName, performanceDataName);
089: prefix = "Refactoring Rename |";
090: }
091:
092: public void initialize() {
093: super .initialize();
094: FootprintUtilities.closeAllDocuments();
095: FootprintUtilities.closeMemoryToolbar();
096: }
097:
098: @Override
099: public void setUp() {
100: //do nothing
101: }
102:
103: public void prepare() {
104: }
105:
106: public ComponentOperator open() {
107: String rename_to, rename_from = rename;
108:
109: // jEdit project
110: log("Opening project jEdit");
111: ProjectsTabOperator.invoke();
112: FootprintUtilities.waitProjectOpenedScanFinished(System
113: .getProperty("xtest.tmpdir")
114: + java.io.File.separator + "jEdit41");
115: FootprintUtilities.waitForPendingBackgroundTasks();
116:
117: // find existing node
118: Node packagenode = new Node(new SourcePackagesNode("jEdit"),
119: "org.gjt.sp.jedit");
120: String[] children = packagenode.getChildren();
121: for (int i = 0; i < children.length; i++) {
122: if (children[i].startsWith(rename)) {
123: rename_from = children[i];
124: break;
125: }
126: }
127:
128: log(" Trying to rename file " + rename_from);
129:
130: //generate name for new node
131: /* String number = "1";
132: if(rename_from.equalsIgnoreCase(rename+".java")) {
133: rename_to = rename + number;
134: } else {
135: number = rename_from.substring(rename.length(),rename_from.indexOf('.'));
136: rename_to = rename + (Integer.parseInt(number) + 1);
137: }
138: */
139: rename_to = rename + Utilities.getTimeIndex();
140:
141: // invoke Rename
142: Node filenode = new Node(packagenode, rename_from);
143: filenode.callPopup().pushMenuNoBlock("Refactor|Rename..."); // NOI18N
144: NbDialogOperator renamedialog = new NbDialogOperator("Rename "); // NOI18N
145: JTextFieldOperator txtfNewName = new JTextFieldOperator(
146: renamedialog);
147: JButtonOperator btnRefactor = new JButtonOperator(renamedialog,
148: "Refactor"); // NOI18N
149:
150: // if the project exists, try to generate new name
151: rename_to = rename_to + "1";
152: log(" ... rename to " + rename_to);
153: txtfNewName.clearText();
154: txtfNewName.typeText(rename_to);
155:
156: new JCheckBoxOperator(renamedialog, "Apply Rename on Comments")
157: .changeSelection(true); // NOI18N
158: btnRefactor.push();
159:
160: MainWindowOperator.getDefault().waitStatusText(
161: "Save All finished"); // NOI18N
162:
163: rename_to = rename_from;
164: return null;
165: }
166:
167: public void close() {
168: ProjectSupport.closeProject("jEdit");
169: }
170:
171: public static void main(java.lang.String[] args) {
172: junit.textui.TestRunner.run(new RefactoringRename(
173: "measureMemoryFootprint"));
174: }
175:
176: }
|