1 9 10 package org.netbeans.test.subversion.utils; 11 12 import java.io.BufferedInputStream ; 13 import java.io.BufferedOutputStream ; 14 import java.io.File ; 15 import java.io.FileInputStream ; 16 import java.io.FileOutputStream ; 17 import java.io.PrintStream ; 18 import java.util.Arrays ; 19 import javax.swing.JCheckBoxMenuItem ; 20 import org.netbeans.jellytools.MainWindowOperator; 21 import org.netbeans.jellytools.NbDialogOperator; 22 import org.netbeans.jellytools.NewFileNameLocationStepOperator; 23 import org.netbeans.jellytools.NewFileWizardOperator; 24 import org.netbeans.jellytools.NewProjectNameLocationStepOperator; 25 import org.netbeans.jellytools.NewProjectWizardOperator; 26 import org.netbeans.jellytools.ProjectsTabOperator; 27 import org.netbeans.jellytools.nodes.Node; 28 import org.netbeans.jemmy.operators.JCheckBoxMenuItemOperator; 29 import org.netbeans.jemmy.operators.JCheckBoxOperator; 30 import org.netbeans.jemmy.operators.JMenuBarOperator; 31 import org.netbeans.jemmy.operators.JMenuItemOperator; 32 import org.netbeans.jemmy.operators.JTextFieldOperator; 33 import org.netbeans.junit.ide.ProjectSupport; 34 35 39 public final class TestKit { 40 public final static String MODIFIED_COLOR = "#0000FF"; 41 public final static String NEW_COLOR = "#008000"; 42 public final static String CONFLICT_COLOR = "#FF0000"; 43 public final static String IGNORED_COLOR = "#999999"; 44 45 public final static String MODIFIED_STATUS = "[Modified ]"; 46 public final static String NEW_STATUS = "[New ]"; 47 public final static String CONFLICT_STATUS = "[Conflict ]"; 48 public final static String IGNORED_STATUS = "[Ignored ]"; 49 public final static String UPTODATE_STATUS = ""; 50 51 public static File prepareProject(String category, String project, String project_name) throws Exception { 52 String folder = "work" + File.separator + "w" + System.currentTimeMillis(); 54 File file = new File ("/tmp", folder); file.mkdirs(); 56 RepositoryMaintenance.deleteFolder(file); 57 file.mkdirs(); 58 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke(); 60 npwo.selectCategory(category); 61 npwo.selectProject(project); 62 npwo.next(); 63 NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator(); 64 new JTextFieldOperator(npnlso, 1).setText(file.getAbsolutePath()); new JTextFieldOperator(npnlso, 0).setText(project_name); new NewProjectWizardOperator().finish(); 68 Node rootNode = new ProjectsTabOperator().getProjectRootNode(project_name); 69 ProjectSupport.waitScanFinished(); 71 return file; 72 } 73 74 public static String getColor(String nodeHtmlDisplayName) { 75 76 if (nodeHtmlDisplayName == null || nodeHtmlDisplayName.length() < 1) 77 return ""; 78 int hashPos = nodeHtmlDisplayName.indexOf('#'); 79 nodeHtmlDisplayName = nodeHtmlDisplayName.substring(hashPos); 80 hashPos = nodeHtmlDisplayName.indexOf('"'); 81 nodeHtmlDisplayName = nodeHtmlDisplayName.substring(0, hashPos); 82 return nodeHtmlDisplayName; 83 } 84 85 public static String getStatus(String nodeHtmlDisplayName) { 86 if (nodeHtmlDisplayName == null || nodeHtmlDisplayName.length() < 1) 87 return ""; 88 String status; 89 int pos1 = nodeHtmlDisplayName.indexOf('['); 90 int pos2 = nodeHtmlDisplayName.indexOf(']'); 91 if ((pos1 != -1) && (pos2 != -1)) 92 status = nodeHtmlDisplayName.substring(pos1, pos2 + 1); 93 else 94 status = ""; 95 return status; 96 } 97 98 public static void removeAllData(String projectName) { 99 Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName); 100 rootNode.performPopupActionNoBlock("Delete Project"); 101 NbDialogOperator ndo = new NbDialogOperator("Delete"); 102 JCheckBoxOperator cb = new JCheckBoxOperator(ndo, "Also"); 103 cb.setSelected(true); 104 ndo.yes(); 105 ndo.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 106 ndo.waitClosed(); 107 } 109 110 public static void closeProject(String projectName) { 111 try { 112 Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName); 113 rootNode.performPopupActionNoBlock("Close Project"); 114 try { 115 Thread.sleep(2000); 116 } catch (InterruptedException ex) { 117 ex.printStackTrace(); 118 } 119 } 120 catch (Exception e) { 121 122 } 123 } 124 125 public static void finalRemove() throws Exception { 126 closeProject("JavaApp"); 127 closeProject("SVNApplication"); 128 RepositoryMaintenance.deleteFolder(new File ("/tmp/work")); 129 RepositoryMaintenance.deleteFolder(new File ("/tmp/repo")); 130 } 131 132 public static int compareThem(Object [] expected, Object [] actual, boolean sorted) { 133 int result = 0; 134 if (expected == null || actual == null) 135 return -1; 136 if (sorted) { 137 if (expected.length != actual.length) { 138 return -1; 139 } 140 for (int i = 0; i < expected.length; i++) { 141 if (((String ) expected[i]).equals((String ) actual[i])) { 142 result++; 143 } else { 144 return -1; 145 } 146 } 147 } else { 148 if (expected.length > actual.length) { 149 return -1; 150 } 151 Arrays.sort(expected); 152 Arrays.sort(actual); 153 boolean found = false; 154 for (int i = 0; i < expected.length; i++) { 155 if (((String ) expected[i]).equals((String ) actual[i])) { 156 result++; 157 } else { 158 return -1; 159 } 160 } 161 return result; 162 } 163 return result; 164 } 165 166 public static void createNewElements(String projectName, String packageName, String name) { 167 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 168 nfwo.selectProject(projectName); 169 nfwo.selectCategory("Java Classes"); 170 nfwo.selectFileType("Java Package"); 171 nfwo.next(); 172 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 173 nfnlso.txtObjectName().clearText(); 174 nfnlso.txtObjectName().typeText(packageName); 175 nfnlso.finish(); 176 177 nfwo = NewFileWizardOperator.invoke(); 178 nfwo.selectProject(projectName); 179 nfwo.selectCategory("Java Classes"); 180 nfwo.selectFileType("Java Class"); 181 nfwo.next(); 182 nfnlso = new NewFileNameLocationStepOperator(); 183 nfnlso.txtObjectName().clearText(); 184 nfnlso.txtObjectName().typeText(name); 185 nfnlso.selectPackage(packageName); 186 nfnlso.finish(); 187 } 188 189 public static void createNewPackage(String projectName, String packageName) { 190 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 191 nfwo.selectProject(projectName); 192 nfwo.selectCategory("Java Classes"); 193 nfwo.selectFileType("Java Package"); 194 nfwo.next(); 195 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 196 nfnlso.txtObjectName().clearText(); 197 nfnlso.txtObjectName().typeText(packageName); 198 nfnlso.finish(); 199 } 200 201 public static void createNewElement(String projectName, String packageName, String name) { 202 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 203 nfwo.selectProject(projectName); 204 nfwo.selectCategory("Java Classes"); 205 nfwo.selectFileType("Java Class"); 206 nfwo.next(); 207 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 208 nfnlso.txtObjectName().clearText(); 209 nfnlso.txtObjectName().typeText(name); 210 nfnlso.selectPackage(packageName); 211 nfnlso.finish(); 212 } 213 214 public static void copyTo(String source, String destination) { 215 try { 216 BufferedInputStream bis = new BufferedInputStream (new FileInputStream (source)); 217 BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (destination)); 218 boolean available = true; 219 byte[] buffer = new byte[1024]; 220 int size; 221 try { 222 while (available) { 223 size = bis.read(buffer); 224 if (size != -1) { 225 bos.write(buffer, 0, size); 226 } else { 227 available = false; 228 } 229 } 230 } catch (Exception e) { 231 e.printStackTrace(); 232 } finally { 233 bos.flush(); 234 bos.close(); 235 bis.close(); 236 } 237 } catch (Exception e) { 238 e.printStackTrace(); 239 } 240 } 241 242 public static void printLogStream(PrintStream stream, String message) { 243 if (stream != null) { 244 stream.println(message); 245 } 246 } 247 248 public static void showStatusLabels() { 249 JMenuBarOperator mbo = new JMenuBarOperator(MainWindowOperator.getDefault().getJMenuBar()); 250 JMenuItemOperator mo = mbo.showMenuItem("View|Show Subversion Status Labels"); 251 JCheckBoxMenuItemOperator cbmio = new JCheckBoxMenuItemOperator((JCheckBoxMenuItem ) mo.getSource()); 252 if (!cbmio.getState()) 253 cbmio.push(); 254 } 255 } 256 | Popular Tags |