1 19 27 28 package org.netbeans.test.localhistory.utils; 29 30 31 import java.io.BufferedInputStream ; 32 import java.io.BufferedOutputStream ; 33 import java.io.File ; 34 import java.io.FileInputStream ; 35 import java.io.FileOutputStream ; 36 import java.io.PrintStream ; 37 import java.util.Arrays ; 38 import org.netbeans.jellytools.NbDialogOperator; 39 import org.netbeans.jellytools.NewFileNameLocationStepOperator; 40 import org.netbeans.jellytools.NewFileWizardOperator; 41 import org.netbeans.jellytools.NewProjectNameLocationStepOperator; 42 import org.netbeans.jellytools.NewProjectWizardOperator; 43 import org.netbeans.jellytools.ProjectsTabOperator; 44 import org.netbeans.jellytools.nodes.Node; 45 import org.netbeans.jemmy.operators.JCheckBoxOperator; 46 import org.netbeans.jemmy.operators.JTextFieldOperator; 47 import org.netbeans.junit.ide.ProjectSupport; 48 49 53 public final class TestKit { 54 55 public static File prepareProject(String category, String project, String project_name) throws Exception { 56 String folder = "work" + File.separator + "w" + System.currentTimeMillis(); 58 File file = new File ("/tmp", folder); file.mkdirs(); 60 file.mkdirs(); 61 NewProjectWizardOperator npwo = NewProjectWizardOperator.invoke(); 63 npwo.selectCategory(category); 64 npwo.selectProject(project); 65 npwo.next(); 66 NewProjectNameLocationStepOperator npnlso = new NewProjectNameLocationStepOperator(); 67 new JTextFieldOperator(npnlso, 1).setText(file.getAbsolutePath()); new JTextFieldOperator(npnlso, 0).setText(project_name); new NewProjectWizardOperator().finish(); 71 Node rootNode = new ProjectsTabOperator().getProjectRootNode(project_name); 72 ProjectSupport.waitScanFinished(); 74 return file; 75 } 76 77 public static void removeAllData(String projectName) { 78 Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName); 79 rootNode.performPopupActionNoBlock("Delete Project"); 80 NbDialogOperator ndo = new NbDialogOperator("Delete"); 81 JCheckBoxOperator cb = new JCheckBoxOperator(ndo, "Also"); 82 cb.setSelected(true); 83 ndo.yes(); 84 ndo.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 85 ndo.waitClosed(); 86 } 88 89 public static void closeProject(String projectName) { 90 try { 91 Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName); 92 rootNode.performPopupActionNoBlock("Close Project"); 93 try { 94 Thread.sleep(2000); 95 } catch (InterruptedException ex) { 96 ex.printStackTrace(); 97 } 98 } 99 catch (Exception e) { 100 101 } 102 } 103 104 public static int compareThem(Object [] expected, Object [] actual, boolean sorted) { 105 int result = 0; 106 if (expected == null || actual == null) 107 return -1; 108 if (sorted) { 109 if (expected.length != actual.length) { 110 return -1; 111 } 112 for (int i = 0; i < expected.length; i++) { 113 if (((String ) expected[i]).equals((String ) actual[i])) { 114 result++; 115 } else { 116 return -1; 117 } 118 } 119 } else { 120 if (expected.length > actual.length) { 121 return -1; 122 } 123 Arrays.sort(expected); 124 Arrays.sort(actual); 125 boolean found = false; 126 for (int i = 0; i < expected.length; i++) { 127 if (((String ) expected[i]).equals((String ) actual[i])) { 128 result++; 129 } else { 130 return -1; 131 } 132 } 133 return result; 134 } 135 return result; 136 } 137 138 public static void createNewPackage(String projectName, String packageName) { 139 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 140 nfwo.selectProject(projectName); 141 nfwo.selectCategory("Java Classes"); 142 nfwo.selectFileType("Java Package"); 143 nfwo.next(); 144 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 145 nfnlso.txtObjectName().clearText(); 146 nfnlso.txtObjectName().typeText(packageName); 147 nfnlso.finish(); 148 } 149 150 public static void createNewElement(String projectName, String packageName, String name) { 151 NewFileWizardOperator nfwo = NewFileWizardOperator.invoke(); 152 nfwo.selectProject(projectName); 153 nfwo.selectCategory("Java Classes"); 154 nfwo.selectFileType("Java Class"); 155 nfwo.next(); 156 NewFileNameLocationStepOperator nfnlso = new NewFileNameLocationStepOperator(); 157 nfnlso.txtObjectName().clearText(); 158 nfnlso.txtObjectName().typeText(name); 159 nfnlso.selectPackage(packageName); 160 nfnlso.finish(); 161 } 162 163 public static void copyTo(String source, String destination) { 164 try { 165 BufferedInputStream bis = new BufferedInputStream (new FileInputStream (source)); 166 BufferedOutputStream bos = new BufferedOutputStream (new FileOutputStream (destination)); 167 boolean available = true; 168 byte[] buffer = new byte[1024]; 169 int size; 170 try { 171 while (available) { 172 size = bis.read(buffer); 173 if (size != -1) { 174 bos.write(buffer, 0, size); 175 } else { 176 available = false; 177 } 178 } 179 } catch (Exception e) { 180 e.printStackTrace(); 181 } finally { 182 bos.flush(); 183 bos.close(); 184 bis.close(); 185 } 186 } catch (Exception e) { 187 e.printStackTrace(); 188 } 189 } 190 191 public static void printLogStream(PrintStream stream, String message) { 192 if (stream != null) { 193 stream.println(message); 194 } 195 } 196 197 } 198 | Popular Tags |