1 19 20 package org.netbeans.test.utilities.testcase; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.netbeans.jellytools.Bundle; 25 import org.netbeans.jellytools.NbDialogOperator; 26 import org.netbeans.jellytools.ProjectsTabOperator; 27 import org.netbeans.jellytools.actions.OpenAction; 28 import org.netbeans.jellytools.nodes.Node; 29 import org.netbeans.jemmy.EventTool; 30 import org.netbeans.jemmy.operators.JCheckBoxOperator; 31 import org.netbeans.jemmy.operators.JPopupMenuOperator; 32 import org.openide.loaders.DataObject; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.actions.SaveAllAction; 35 36 40 public class Utilities { 41 42 43 public static final String FIND_DIALOG = Bundle.getString( 44 "org.netbeans.modules.search.Bundle", "TEXT_TITLE_CUSTOMIZE"); 45 46 47 48 public static final String TEST_PROJECT_NAME = "UtilitiesTestProject"; 49 50 51 public static final String CONFIRM_OBJECT_DELETION = 52 Bundle.getString("org.openide.explorer.Bundle", 53 "MSG_ConfirmDeleteObjectTitle"); 54 55 56 public static final String UTILITIES_BUNDLE = "org.netbeans.modules.search.Bundle"; 57 58 59 public static final String TEST_PACKAGES_PATH = 60 Bundle.getString("org.netbeans.modules.java.j2seproject.Bundle", 61 "NAME_test.src.dir"); 62 63 64 public static final String RUN_FILE = 65 Bundle.getString("org.netbeans.modules.java.j2seproject.Bundle", 66 "ACTION_run.single"); 67 68 69 public static final String TEST_PROJECT = 70 Bundle.getString("org.netbeans.modules.java.j2seproject.ui.Bundle", 71 "LBL_TestAction_Name"); 72 73 74 public static final String SRC_PACKAGES_PATH = 75 Bundle.getString("org.netbeans.modules.java.j2seproject.Bundle", 76 "NAME_src.dir"); 77 78 public static final int ACTION_TIMEOUT = 1000; 80 81 82 85 public static void saveAll() { 86 ((SaveAllAction) SaveAllAction.findObject(SaveAllAction.class, true)).performAction(); 87 } 88 89 93 public static void delete(File file) { 94 try { 95 DataObject.find(FileUtil.toFileObject(file)).delete(); 96 } catch (IOException e) { 97 } 98 } 99 100 104 public static void deleteNode(String path) { 105 Node pn = new ProjectsTabOperator().getProjectRootNode( 106 Utilities.TEST_PROJECT_NAME); 107 if(pn != null && pn.isPresent()) { 108 pn.select(); 109 Node n = new Node(pn, path); 110 n.select(); 111 JPopupMenuOperator jpmo = n.callPopup(); 112 jpmo.pushMenu("Delete"); 113 new NbDialogOperator(CONFIRM_OBJECT_DELETION).btYes().push(); takeANap(500); 115 } 116 } 117 118 121 public static void deleteDirectory(File path) { 122 if(path.exists()) { 123 File [] f = path.listFiles(); 124 for(int i = 0; i < f.length ; i++) { 125 if (f[i].isDirectory()) 126 deleteDirectory(f[i]); 127 else 128 f[i].delete(); 129 } 130 } 131 path.delete(); 132 } 133 134 138 public static Node openFile(String path) { 139 Node pn = new ProjectsTabOperator().getProjectRootNode( 140 Utilities.TEST_PROJECT_NAME); 141 pn.select(); 142 Node n = new Node(pn, path); 143 n.select(); 144 new OpenAction().perform(); 145 new EventTool().waitNoEvent(ACTION_TIMEOUT); 146 return n; 147 } 148 149 152 public static void testWholeProject() { 153 Node n = new ProjectsTabOperator().getProjectRootNode( 154 Utilities.TEST_PROJECT_NAME); 155 n.callPopup().pushMenu(TEST_PROJECT); 156 } 157 158 162 public static void pushFindPopup(Node n) { 163 JPopupMenuOperator jpmo = n.callPopup(); 164 jpmo.pushMenuNoBlock(Bundle.getString(UTILITIES_BUNDLE, 165 "TEXT_TITLE_CUSTOMIZE")); 166 } 167 168 171 public static void checkAllCheckboxes(NbDialogOperator ndo) { 172 for(int i = 0; i < 7; i++) { 173 new JCheckBoxOperator(ndo, i).setSelected(true); 174 } 175 } 176 177 public static NbDialogOperator getFindDialog() { 178 Node pn = new ProjectsTabOperator().getProjectRootNode( 179 Utilities.TEST_PROJECT_NAME); 180 pn.select(); 181 Node n = new Node(pn, Utilities.SRC_PACKAGES_PATH); 182 n.select(); 183 Utilities.takeANap(1000); 184 Utilities.pushFindPopup(n); 185 186 return new NbDialogOperator(FIND_DIALOG); 187 } 188 189 192 public static void takeANap(long waitTimeout) { 193 new org.netbeans.jemmy.EventTool().waitNoEvent(waitTimeout); 194 } 195 } 196 | Popular Tags |