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 java.io.File;
045:
046: import org.netbeans.jellytools.Bundle;
047: import org.netbeans.jellytools.NbDialogOperator;
048: import org.netbeans.jellytools.ProjectsTabOperator;
049: import org.netbeans.jellytools.actions.DeleteAction;
050: import org.netbeans.jellytools.actions.MaximizeWindowAction;
051: import org.netbeans.jellytools.actions.RestoreWindowAction;
052: import org.netbeans.jellytools.nodes.Node;
053: import org.netbeans.jellytools.nodes.SourcePackagesNode;
054:
055: import org.netbeans.jemmy.operators.ComponentOperator;
056:
057: /**
058: * Test of Delete nodes/folders in the Explorer.
059: *
060: * @author mmirilovic@netbeans.org
061: */
062: public class DeleteFolder extends
063: org.netbeans.performance.test.utilities.PerformanceTestCase {
064:
065: /** Projects tab */
066: private static ProjectsTabOperator projectTab;
067:
068: /** Name of the folder which test creates and expands */
069: private static String folderToBeDeleted;
070:
071: /** Node represantation of the folder which test creates and delete */
072: private static Node nodeToBeDeleted;
073:
074: /**
075: * Creates a new instance of DeleteFolder
076: * @param testName the name of the test
077: */
078: public DeleteFolder(String testName) {
079: super (testName);
080: expectedTime = WINDOW_OPEN;
081: }
082:
083: /**
084: * Creates a new instance of DeleteFolder
085: * @param testName the name of the test
086: * @param performanceDataName measured values will be saved under this name
087: */
088: public DeleteFolder(String testName, String performanceDataName) {
089: super (testName, performanceDataName);
090: expectedTime = WINDOW_OPEN;
091: }
092:
093: public void testDeleteFolderWith50JavaFiles() {
094: WAIT_AFTER_PREPARE = 10000;
095: WAIT_AFTER_OPEN = 10000;
096: folderToBeDeleted = "javaFolder50";
097: doMeasurement();
098: }
099:
100: public void testDeleteFolderWith100JavaFiles() {
101: WAIT_AFTER_PREPARE = 15000;
102: WAIT_AFTER_OPEN = 15000;
103: folderToBeDeleted = "javaFolder100";
104: doMeasurement();
105: }
106:
107: public void initialize() {
108: projectTab = new ProjectsTabOperator();
109: new MaximizeWindowAction().performAPI(projectTab);
110:
111: projectTab.getProjectRootNode("PerformanceTestData").collapse();
112: projectTab.getProjectRootNode("jEdit").collapse();
113:
114: repaintManager().addRegionFilter(
115: repaintManager().EXPLORER_FILTER);
116: turnBadgesOff();
117: }
118:
119: public ComponentOperator open() {
120: new DeleteAction().performPopup(nodeToBeDeleted);
121: new NbDialogOperator(Bundle.getStringTrimmed(
122: "org.openide.explorer.Bundle",
123: "MSG_ConfirmDeleteObjectTitle")).yes();
124: return null;
125: }
126:
127: public void close() {
128: //do nothing
129: }
130:
131: public void prepare() {
132: try {
133: String projectPath = System.getProperty("xtest.tmpdir")
134: + File.separator + "PerformanceTestFoldersData";
135: log("========== Projects path =" + projectPath);
136:
137: File foldersDir = new File(projectPath + File.separator
138: + "src" + File.separator + "folders");
139: log("========== Folders path =" + foldersDir.getPath());
140:
141: File originalDir = new File(foldersDir, folderToBeDeleted);
142: File copyDeleteDir = new File(foldersDir, folderToBeDeleted
143: + "_delete");
144: copyDeleteDir.mkdir();
145:
146: log("========== Original Dir path ="
147: + originalDir.getPath());
148: log("========== Copy Delete Dir path ="
149: + copyDeleteDir.getPath());
150:
151: gui.Utilities.copyFile(new File(foldersDir, "Test.java"),
152: new File(copyDeleteDir, "Test.java"));
153: waitNoEvent(1000);
154:
155: SourcePackagesNode sourcePackagesNode = new SourcePackagesNode(
156: "PerformanceTestFoldersData");
157:
158: Node foldersNode = new Node(sourcePackagesNode, "|folders");
159: foldersNode.expand();
160:
161: /* no more present after retouche merge
162: new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()).pushMenu(Bundle.getStringTrimmed("org.netbeans.core.Bundle","Menu/File")+"|"+Bundle.getStringTrimmed("org.netbeans.modules.javacore.Bundle","LBL_RescanAction"),"|"); //File|Refresh All Files
163: waitNoEvent(500);
164: */
165:
166: nodeToBeDeleted = new Node(sourcePackagesNode, "folders."
167: + folderToBeDeleted + "_delete");
168:
169: File[] files = originalDir.listFiles();
170: log("=============== There is [" + files.length
171: + "] number of files in directory = "
172: + originalDir.getPath());
173:
174: File copyFile;
175:
176: for (int i = 0; i < files.length; i++) {
177: copyFile = new File(copyDeleteDir, files[i].getName());
178: log("================== Create file ="
179: + copyFile.getPath());
180:
181: gui.Utilities.copyFile(files[i], copyFile);
182: }
183:
184: /* no more present after retouche merge
185: new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()).pushMenu(Bundle.getStringTrimmed("org.netbeans.core.Bundle","Menu/File")+"|"+Bundle.getStringTrimmed("org.netbeans.modules.javacore.Bundle","LBL_RescanAction"),"|"); //File|Refresh All Files
186: waitNoEvent(500);
187: */
188:
189: nodeToBeDeleted.expand();
190:
191: } catch (Exception exc) {
192: log("========================================= \nImpossible create files: "
193: + exc.getMessage());
194: exc.printStackTrace(getLog());
195: log("\n=========================================");
196: }
197: }
198:
199: public void shutdown() {
200: new RestoreWindowAction().performAPI(projectTab);
201: repaintManager().resetRegionFilters();
202: turnBadgesOn();
203: }
204:
205: /**
206: * turn badges off
207: */
208: protected void turnBadgesOff() {
209: System.setProperty("perf.dont.resolve.java.badges", "true");
210: }
211:
212: /**
213: * turn badges on
214: */
215: protected void turnBadgesOn() {
216: System.setProperty("perf.dont.resolve.java.badges", "false");
217: }
218:
219: /** Test could be executed internaly in IDE without XTest
220: * @param args arguments from command line
221: */
222: public static void main(String[] args) {
223: junit.textui.TestRunner.run(new DeleteFolder(
224: "testDeleteFolderWith50JavaFiles"));
225: }
226: }
|