1 19 package org.netbeans.test.cvsmodule; 20 21 import java.io.BufferedReader ; 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.FileOutputStream ; 25 import java.io.FileReader ; 26 import java.io.IOException ; 27 import java.io.InputStream ; 28 import java.io.OutputStream ; 29 import java.util.Arrays ; 30 import javax.swing.JCheckBoxMenuItem ; 31 import org.netbeans.jellytools.EditorOperator; 32 import org.netbeans.jellytools.MainWindowOperator; 33 import org.netbeans.jellytools.NbDialogOperator; 34 import org.netbeans.jellytools.NewFileNameLocationStepOperator; 35 import org.netbeans.jellytools.NewFileWizardOperator; 36 import org.netbeans.jellytools.NewProjectNameLocationStepOperator; 37 import org.netbeans.jellytools.NewProjectWizardOperator; 38 import org.netbeans.jellytools.ProjectsTabOperator; 39 import org.netbeans.jellytools.nodes.Node; 40 import org.netbeans.jemmy.JemmyProperties; 41 import org.netbeans.jemmy.operators.JCheckBoxMenuItemOperator; 42 import org.netbeans.jemmy.operators.JCheckBoxOperator; 43 import org.netbeans.jemmy.operators.JMenuBarOperator; 44 import org.netbeans.jemmy.operators.JMenuItemOperator; 45 import org.netbeans.jemmy.operators.JTextFieldOperator; 46 47 52 public class TestKit { 53 final static String MODIFIED_COLOR = "#0000FF"; 54 final static String NEW_COLOR = "#008000"; 55 final static String CONFLICT_COLOR = "#FF0000"; 56 final static String IGNORED_COLOR = "#999999"; 57 58 public static File createTmpFolder(String prefix) throws IOException { 59 String tmpDir = System.getProperty("java.io.tmpdir"); File tmpFolder = new File (tmpDir); 61 File tmp = File.createTempFile(prefix, "", tmpFolder); if (tmp.delete() == false) { 64 throw new IOException ("Can not delete " + tmp); 65 }; 66 if (tmp.mkdirs() == false) { 67 throw new IOException ("Can not create " + tmp); 68 }; 69 return tmp; 70 } 71 72 public static void deleteRecursively(File dir) { 73 if (dir.isDirectory()) { 74 String [] files = dir.list(); 75 for (int i = 0; i < files.length; i++) { 76 deleteRecursively(new File (dir, files[i])); } 78 } 79 dir.delete(); 80 } 81 82 public static void pseudoVersion(File file) throws Exception { 83 File CVSdir = new File (file, "CVS"); 84 File Entries = new File (CVSdir, "Entries"); 85 OutputStream out = new FileOutputStream (Entries); 86 String data = "D\n" + 87 "/Main.java/1.1/Wed Sep 14 08:51:41 2005//"; 88 out.write(data.getBytes("utf8")); 89 out.flush(); 90 out.close(); 91 File Root = new File (CVSdir, "Root"); 93 out = new FileOutputStream (Root); 94 data = ":local:/Projects/CVSrepo"; 95 out.write(data.getBytes("utf8")); 96 out.flush(); 97 out.close(); 98 File Repository = new File (CVSdir, "Repository"); 100 out = new FileOutputStream (Repository); 101 data = "ForImport/src/forimport"; 102 out.write(data.getBytes("utf8")); 103 out.flush(); 104 out.close(); 105 } 106 107 public static File prepareProject(String category, String project, String project_name, String edit_file) throws Exception { 108 String folder = "" + System.currentTimeMillis(); 110 File file = new File ("/tmp", folder); file.mkdirs(); 112 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke(); 114 npwo.selectCategory(category); 115 npwo.selectProject(project); 116 npwo.next(); 117 NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator(); 118 new JTextFieldOperator(npnlso, 1).setText(file.getAbsolutePath()); new JTextFieldOperator(npnlso, 0).setText(project_name); new NewProjectWizardOperator().finish(); 122 Node rootNode = new ProjectsTabOperator().getProjectRootNode(project_name); 123 return file; 125 } 126 127 public static void removeAllData(String project_name) { 128 Node rootNode = new ProjectsTabOperator().getProjectRootNode(project_name); 129 rootNode.performPopupActionNoBlock("Delete Project"); 130 NbDialogOperator ndo = new NbDialogOperator("Delete"); 131 JCheckBoxOperator cb = new JCheckBoxOperator(ndo, "Also"); 132 cb.setSelected(true); 133 ndo.yes(); 134 ndo.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 135 ndo.waitClosed(); 136 } 138 139 public static void unversionProject(File file, String project_name) throws Exception { 140 File folder_CVS = new File (file, project_name + File.separator + "src" + File.separator + project_name.toLowerCase() + File.separator + "CVS"); 141 TestKit.deleteRecursively(folder_CVS); 143 EditorOperator eo = new EditorOperator("Main.java"); 145 eo.insert("//Comment\n"); 146 eo.save(); 147 } 148 149 public static void createNewElements(String projectName) { 150 String pack = "xx"; 151 152 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 153 nfwo.selectProject(projectName); 154 nfwo.selectCategory("Java Classes"); 155 nfwo.selectFileType("Java Package"); 156 nfwo.next(); 157 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 158 nfnlso.txtObjectName().clearText(); 159 nfnlso.txtObjectName().typeText(pack); 160 nfnlso.finish(); 161 nfwo = NewFileWizardOperator.invoke(); 163 nfwo.selectProject(projectName); 164 nfwo.selectCategory("Java Classes"); 165 nfwo.selectFileType("Java Class"); 166 nfwo.next(); 167 nfnlso = new NewFileNameLocationStepOperator(); 168 nfnlso.txtObjectName().clearText(); 169 nfnlso.txtObjectName().typeText("NewClass"); 170 nfnlso.selectPackage(pack); 171 nfnlso.finish(); 172 nfwo = NewFileWizardOperator.invoke(); 174 nfwo.selectProject(projectName); 175 nfwo.selectCategory("Java GUI Forms"); 176 nfwo.selectFileType("JFrame Form"); 177 nfwo.next(); 178 nfnlso = new NewFileNameLocationStepOperator(); 179 nfnlso.txtObjectName().clearText(); 180 nfnlso.txtObjectName().typeText("NewJFrame"); 181 nfnlso.selectPackage(pack); 182 nfnlso.finish(); 183 } 184 185 public static void createNewElementsCommitCvs11(String projectName) { 186 String pack = "xx"; 187 188 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 189 nfwo.selectProject(projectName); 190 nfwo.selectCategory("Java Classes"); 191 nfwo.selectFileType("Java Package"); 192 nfwo.next(); 193 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 194 nfnlso.txtObjectName().clearText(); 195 nfnlso.txtObjectName().typeText(pack); 196 nfnlso.finish(); 197 nfwo = NewFileWizardOperator.invoke(); 199 nfwo.selectProject(projectName); 200 nfwo.selectCategory("Java Classes"); 201 nfwo.selectFileType("Java Class"); 202 nfwo.next(); 203 nfnlso = new NewFileNameLocationStepOperator(); 204 nfnlso.txtObjectName().clearText(); 205 nfnlso.txtObjectName().typeText("NewClass"); 206 nfnlso.selectPackage(pack); 207 nfnlso.finish(); 208 nfwo = NewFileWizardOperator.invoke(); 210 nfwo.selectProject(projectName); 211 nfwo.selectCategory("Java Classes"); 212 nfwo.selectFileType("Java Class"); 213 nfwo.next(); 214 nfnlso = new NewFileNameLocationStepOperator(); 215 nfnlso.txtObjectName().clearText(); 216 nfnlso.txtObjectName().typeText("NewClass2"); 217 nfnlso.selectPackage(pack); 218 nfnlso.finish(); 219 nfwo = NewFileWizardOperator.invoke(); 221 nfwo.selectProject(projectName); 222 nfwo.selectCategory("Java Classes"); 223 nfwo.selectFileType("Java Class"); 224 nfwo.next(); 225 nfnlso = new NewFileNameLocationStepOperator(); 226 nfnlso.txtObjectName().clearText(); 227 nfnlso.txtObjectName().typeText("NewClass3"); 228 nfnlso.selectPackage(pack); 229 nfnlso.finish(); 230 nfwo = NewFileWizardOperator.invoke(); 232 nfwo.selectProject(projectName); 233 nfwo.selectCategory("Java Classes"); 234 nfwo.selectFileType("Java Class"); 235 nfwo.next(); 236 nfnlso = new NewFileNameLocationStepOperator(); 237 nfnlso.txtObjectName().clearText(); 238 nfnlso.txtObjectName().typeText("NewClass4"); 239 nfnlso.selectPackage(pack); 240 nfnlso.finish(); 241 } 242 243 public static void createNewElementsCommitCvs12(String projectName) { 244 String pack = "aa"; 245 246 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 247 nfwo.selectProject(projectName); 248 nfwo.selectCategory("Java Classes"); 249 nfwo.selectFileType("Java Package"); 250 nfwo.next(); 251 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 252 nfnlso.txtObjectName().clearText(); 253 nfnlso.txtObjectName().typeText("aa"); 254 nfnlso.finish(); 255 256 nfwo = NewFileWizardOperator.invoke(); 258 nfwo.selectProject(projectName); 259 nfwo.selectCategory("Java Classes"); 260 nfwo.selectFileType("Java Package"); 261 nfwo.next(); 262 nfnlso = new NewFileNameLocationStepOperator(); 263 nfnlso.txtObjectName().clearText(); 264 nfnlso.txtObjectName().typeText("bb"); 265 nfnlso.finish(); 266 nfwo = NewFileWizardOperator.invoke(); 268 nfwo.selectProject(projectName); 269 nfwo.selectCategory("Java Classes"); 270 nfwo.selectFileType("Java Class"); 271 nfwo.next(); 272 nfnlso = new NewFileNameLocationStepOperator(); 273 nfnlso.txtObjectName().clearText(); 274 nfnlso.txtObjectName().typeText("NewClass"); 275 nfnlso.selectPackage("aa"); 276 nfnlso.finish(); 277 278 nfwo = NewFileWizardOperator.invoke(); 280 nfwo.selectProject(projectName); 281 nfwo.selectCategory("Java Classes"); 282 nfwo.selectFileType("Java Class"); 283 nfwo.next(); 284 nfnlso = new NewFileNameLocationStepOperator(); 285 nfnlso.txtObjectName().clearText(); 286 nfnlso.txtObjectName().typeText("NewClass2"); 287 nfnlso.selectPackage("aa"); 288 nfnlso.finish(); 289 nfwo = NewFileWizardOperator.invoke(); 291 nfwo.selectProject(projectName); 292 nfwo.selectCategory("Java Classes"); 293 nfwo.selectFileType("Java Class"); 294 nfwo.next(); 295 nfnlso = new NewFileNameLocationStepOperator(); 296 nfnlso.txtObjectName().clearText(); 297 nfnlso.txtObjectName().typeText("NewClass"); 298 nfnlso.selectPackage("bb"); 299 nfnlso.finish(); 300 nfwo = NewFileWizardOperator.invoke(); 302 nfwo.selectProject(projectName); 303 nfwo.selectCategory("Java Classes"); 304 nfwo.selectFileType("Java Class"); 305 nfwo.next(); 306 nfnlso = new NewFileNameLocationStepOperator(); 307 nfnlso.txtObjectName().clearText(); 308 nfnlso.txtObjectName().typeText("NewClass2"); 309 nfnlso.selectPackage("bb"); 310 nfnlso.finish(); 311 } 312 313 public static int compareThem(Object [] expected, Object [] actual, boolean sorted) { 314 int result = 0; 315 if (expected == null || actual == null) 316 return -1; 317 if (sorted) { 318 if (expected.length != actual.length) { 319 return -1; 320 } 321 for (int i = 0; i < expected.length; i++) { 322 if (((String ) expected[i]).equals((String ) actual[i])) { 323 result++; 324 } else { 325 return -1; 326 } 327 } 328 } else { 329 if (expected.length > actual.length) { 330 return -1; 331 } 332 Arrays.sort(expected); 333 Arrays.sort(actual); 334 for (int i = 0; i < expected.length; i++) { 335 if (((String ) expected[i]).equals((String ) actual[i])) { 336 result++; 337 } else { 338 return -1; 339 } 340 } 341 } 342 return result; 343 } 344 345 public static String getCVSroot(File cvsFolder) { 346 String root = new String (); 347 if (cvsFolder.isDirectory()) { 348 try { 349 BufferedReader br = new BufferedReader (new FileReader (cvsFolder + File.separator + "Root")); 350 root = br.readLine(); 351 if (root == null || root.length() == 0) 352 return ""; 353 br.close(); 354 } catch (IOException e) { 355 return ""; 356 } 357 } 358 return root; 359 } 360 361 public static String getColor(String nodeHtmlDisplayName) { 362 363 if (nodeHtmlDisplayName == null || nodeHtmlDisplayName.length() < 1) 364 return ""; 365 int hashPos = nodeHtmlDisplayName.indexOf('#'); 366 nodeHtmlDisplayName = nodeHtmlDisplayName.substring(hashPos); 367 hashPos = nodeHtmlDisplayName.indexOf('"'); 368 nodeHtmlDisplayName = nodeHtmlDisplayName.substring(0, hashPos); 369 return nodeHtmlDisplayName; 370 } 371 372 public static InputStream getStream(String dir, String protocolName) throws Exception { 373 File file = new File (dir, protocolName); 374 InputStream in = new FileInputStream (file); 375 return in; 376 } 377 378 public static void closeProject(String projectName) { 379 try { 380 Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName); 381 rootNode.performPopupActionNoBlock("Close Project"); 382 try { 383 Thread.sleep(2000); 384 } catch (InterruptedException ex) { 385 ex.printStackTrace(); 386 } 387 } catch (Exception e) { 388 389 } 390 } 391 public static String getStatus(String nodeHtmlDisplayName) { 392 if (nodeHtmlDisplayName == null || nodeHtmlDisplayName.length() < 1) 393 return ""; 394 String status; 395 int pos1 = nodeHtmlDisplayName.indexOf('['); 396 int pos2 = nodeHtmlDisplayName.indexOf(']'); 397 if ((pos1 != -1) && (pos2 != -1)) 398 status = nodeHtmlDisplayName.substring(pos1, pos2 + 1); 399 else 400 status = ""; 401 return status; 402 } 403 404 public static void showStatusLabels() { 405 JMenuBarOperator mbo = new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()); 406 JMenuItemOperator mo = mbo.showMenuItem("View|Show CVS Status Labels"); 407 JCheckBoxMenuItemOperator cbmio = new JCheckBoxMenuItemOperator((JCheckBoxMenuItem ) mo.getSource()); 408 if (!cbmio.getState()) 409 cbmio.push(); 410 } 411 } 412 | Popular Tags |