1 9 10 package org.netbeans.test.subversion.main.checkout; 11 12 import java.io.File ; 13 import javax.swing.table.TableModel ; 14 import junit.textui.TestRunner; 15 import org.netbeans.jellytools.JellyTestCase; 16 import org.netbeans.jellytools.ProjectsTabOperator; 17 import org.netbeans.jellytools.nodes.Node; 18 import org.netbeans.jemmy.JemmyProperties; 19 import org.netbeans.jemmy.operators.JTableOperator; 20 import org.netbeans.jemmy.operators.Operator; 21 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 22 import org.netbeans.junit.NbTestSuite; 23 import org.netbeans.test.subversion.operators.CommitStepOperator; 24 import org.netbeans.test.subversion.operators.CreateNewFolderOperator; 25 import org.netbeans.test.subversion.operators.FolderToImportStepOperator; 26 import org.netbeans.test.subversion.operators.ImportWizardOperator; 27 import org.netbeans.test.subversion.operators.RepositoryBrowserImpOperator; 28 import org.netbeans.test.subversion.operators.RepositoryStepOperator; 29 import org.netbeans.test.subversion.utils.RepositoryMaintenance; 30 import org.netbeans.test.subversion.utils.TestKit; 31 32 36 public class ImportUITest extends JellyTestCase { 37 38 public static final String TMP_PATH = "/tmp"; 39 public static final String REPO_PATH = "repo"; 40 public static final String WORK_PATH = "work"; 41 public static final String PROJECT_NAME = "SVNApplication"; 42 public File projectPath; 43 String os_name; 44 Operator.DefaultStringComparator comOperator; 45 Operator.DefaultStringComparator oldOperator; 46 47 48 public ImportUITest(String name) { 49 super(name); 50 } 51 52 protected void setUp() throws Exception { 53 os_name = System.getProperty("os.name"); 54 System.out.println("### "+getName()+" ###"); 56 57 } 58 59 protected boolean isUnix() { 60 boolean unix = false; 61 if (os_name.indexOf("Windows") == -1) { 62 unix = true; 63 } 64 return unix; 65 } 66 67 public static void main(String [] args) { 68 TestRunner.run(suite()); 70 } 71 72 public static NbTestSuite suite() { 73 NbTestSuite suite = new NbTestSuite(); 74 suite.addTest(new ImportUITest("testInvoke")); 75 suite.addTest(new ImportUITest("testWarningMessage")); 76 suite.addTest(new ImportUITest("testRepositoryFolderLoad")); 77 suite.addTest(new ImportUITest("testCommitStep")); 78 return suite; 79 } 80 81 public void testInvoke() throws Exception { 82 try { 85 TestKit.closeProject(PROJECT_NAME); 86 87 new File (TMP_PATH).mkdirs(); 88 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 89 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 90 projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME); 91 comOperator = new Operator.DefaultStringComparator(true, true); 92 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 93 Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 94 Operator.setDefaultStringComparator(comOperator); 95 ImportWizardOperator iwo = ImportWizardOperator.invoke(node); 96 Operator.setDefaultStringComparator(oldOperator); 97 iwo.cancel(); 98 99 } catch (Exception e) { 100 throw new Exception ("Test failed: " + e); 101 } finally { 102 TestKit.closeProject(PROJECT_NAME); 103 } 104 } 105 106 public void testWarningMessage() throws Exception { 107 try { 110 TestKit.closeProject(PROJECT_NAME); 111 112 new File (TMP_PATH).mkdirs(); 113 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 114 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 115 projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME); 116 117 comOperator = new Operator.DefaultStringComparator(true, true); 118 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 119 Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 120 Operator.setDefaultStringComparator(comOperator); 121 ImportWizardOperator iwo = ImportWizardOperator.invoke(node); 122 Operator.setDefaultStringComparator(oldOperator); 123 RepositoryStepOperator rso = new RepositoryStepOperator(); 124 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 126 rso.next(); 127 Thread.sleep(2000); 128 129 FolderToImportStepOperator ftiso = new FolderToImportStepOperator(); 130 ftiso.verify(); 131 132 ftiso.setRepositoryFolder(""); 134 assertEquals("Repository Folder must be specified", "Repository Folder must be specified", ftiso.lblImportMessageRequired().getText()); 135 assertFalse("Next button should be disabled", ftiso.btNext().isEnabled()); 136 assertFalse("Finish button should be disabled", ftiso.btFinish().isEnabled()); 137 138 ftiso.setRepositoryFolder(PROJECT_NAME); 140 ftiso.setImportMessage(""); 141 assertEquals("Import message required", "Import Message required", ftiso.lblImportMessageRequired().getText()); 142 assertFalse("Next button should be disabled", ftiso.btNext().isEnabled()); 143 assertFalse("Finish button should be disabled", ftiso.btFinish().isEnabled()); 144 145 ftiso.setRepositoryFolder(PROJECT_NAME); 147 ftiso.setImportMessage("initial import"); 148 assertEquals("No Warning message", " ", ftiso.lblImportMessageRequired().getText()); 149 assertTrue("Next button should be enabled", ftiso.btNext().isEnabled()); 150 assertTrue("Finish button should be enabled", ftiso.btFinish().isEnabled()); 153 iwo.cancel(); 154 155 } catch (Exception e) { 156 throw new Exception ("Test failed: " + e); 157 } finally { 158 TestKit.closeProject(PROJECT_NAME); 159 } 160 } 161 162 public void testRepositoryFolderLoad() throws Exception { 163 TestKit.closeProject(PROJECT_NAME); 166 try { 167 168 new File (TMP_PATH).mkdirs(); 169 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 170 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 171 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 172 projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME); 173 174 comOperator = new Operator.DefaultStringComparator(true, true); 175 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 176 Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 177 Operator.setDefaultStringComparator(comOperator); 178 ImportWizardOperator iwo = ImportWizardOperator.invoke(node); 179 Operator.setDefaultStringComparator(oldOperator); 180 RepositoryStepOperator rso = new RepositoryStepOperator(); 181 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 183 rso.next(); 184 Thread.sleep(2000); 185 186 FolderToImportStepOperator ftiso = new FolderToImportStepOperator(); 187 188 RepositoryBrowserImpOperator rbo = ftiso.browseRepository(); 190 rbo.selectFolder("branches"); 191 rbo.selectFolder("tags"); 192 rbo.selectFolder("trunk"); 193 rbo.selectFolder("trunk|JavaApp|src|javaapp"); 194 rbo.ok(); 195 assertEquals("Wrong folder selection!!!", "trunk/JavaApp/src/javaapp", ftiso.getRepositoryFolder()); 196 197 204 205 ftiso.setRepositoryFolder("trunk"); 207 rbo = ftiso.browseRepository(); 208 rbo.selectFolder("trunk"); 209 CreateNewFolderOperator cnfo = rbo.createNewFolder(); 210 cnfo.setFolderName(PROJECT_NAME); 211 cnfo.ok(); 212 rbo.selectFolder("trunk|" + PROJECT_NAME); 213 rbo.ok(); 214 assertEquals("Wrong folder selection!!!", "trunk/" + PROJECT_NAME, ftiso.getRepositoryFolder()); 215 216 ftiso.setRepositoryFolder("trunk"); 218 rbo = ftiso.browseRepository(); 219 rbo.selectFolder("branches"); 220 cnfo = rbo.createNewFolder(); 221 cnfo.setFolderName("release_01"); 222 cnfo.ok(); 223 rbo.selectFolder("branches|release_01"); 224 cnfo = rbo.createNewFolder(); 225 cnfo.setFolderName(PROJECT_NAME); 226 cnfo.ok(); 227 rbo.selectFolder("branches|release_01|" + PROJECT_NAME); 228 rbo.ok(); 229 assertEquals("Wrong folder selection!!!", "branches/release_01/" + PROJECT_NAME, ftiso.getRepositoryFolder()); 230 231 iwo.cancel(); 232 233 } catch (Exception e) { 234 throw new Exception ("Test failed: " + e); 235 } finally { 236 TestKit.closeProject(PROJECT_NAME); 237 } 238 } 239 240 public void testCommitStep() throws Exception { 241 try { 244 TestKit.closeProject(PROJECT_NAME); 245 246 new File (TMP_PATH).mkdirs(); 247 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 248 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 249 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 250 projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME); 251 252 comOperator = new Operator.DefaultStringComparator(true, true); 253 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 254 Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 255 Operator.setDefaultStringComparator(comOperator); 256 ImportWizardOperator iwo = ImportWizardOperator.invoke(node); 257 Operator.setDefaultStringComparator(oldOperator); 258 RepositoryStepOperator rso = new RepositoryStepOperator(); 259 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 261 rso.next(); 262 Thread.sleep(1000); 263 264 FolderToImportStepOperator ftiso = new FolderToImportStepOperator(); 265 ftiso.setRepositoryFolder("trunk/" + PROJECT_NAME); 266 ftiso.setImportMessage("initial import"); 267 ftiso.next(); 268 Thread.sleep(1000); 269 CommitStepOperator cso = new CommitStepOperator(); 270 cso.verify(); 271 272 JTableOperator table = cso.tabFiles(); 273 TableModel model = table.getModel(); 274 String [] expected = {"genfiles.properties", "build-impl.xml", "Main.java", "manifest.mf", "src", "project.xml", PROJECT_NAME.toLowerCase(), "nbproject", "project.properties", "test", "build.xml"}; 275 String [] actual = new String [model.getRowCount()]; 276 for (int i = 0; i < actual.length; i++) { 277 actual[i] = model.getValueAt(i, 0).toString(); 278 } 279 assertEquals("Incorrect count of records for addition!!!", 11, model.getRowCount()); 280 assertEquals("Some records were omitted from addition", 11, TestKit.compareThem(expected, actual, false)); 281 cso.selectCommitAction("project.xml", "Add As Text"); 283 cso.selectCommitAction("project.xml", "Add As Binary"); 284 cso.selectCommitAction("project.xml", "Exclude from Commit"); 285 cso.selectCommitAction("test", "Add Directory"); 286 cso.selectCommitAction("test", "Exclude from Commit"); 287 iwo.cancel(); 288 289 } catch (Exception e) { 290 throw new Exception ("Test failed: " + e); 291 } finally { 292 TestKit.closeProject(PROJECT_NAME); 293 } 294 } 295 296 public void testStopProcess() throws Exception { 297 try { 300 TestKit.closeProject(PROJECT_NAME); 301 302 new File (TMP_PATH).mkdirs(); 303 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 304 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 305 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 306 projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME); 307 308 comOperator = new Operator.DefaultStringComparator(true, true); 309 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 310 Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME); 311 Operator.setDefaultStringComparator(comOperator); 312 ImportWizardOperator iwo = ImportWizardOperator.invoke(node); 313 Operator.setDefaultStringComparator(oldOperator); 314 RepositoryStepOperator rso = new RepositoryStepOperator(); 315 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 317 rso.next(); 318 rso.btStop().push(); 320 assertEquals("Warning message - process was cancelled by user", "Action canceled by user", rso.lblWarning().getText()); 321 rso.setRepositoryURL(RepositoryStepOperator.ITEM_HTTPS); 322 rso = new RepositoryStepOperator(); 323 325 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 326 rso.next(); 327 328 FolderToImportStepOperator ftiso = new FolderToImportStepOperator(); 329 ftiso.setRepositoryFolder("trunk/" + PROJECT_NAME); 330 ftiso.setImportMessage("initial import"); 331 ftiso.next(); 332 ftiso.btStop().push(); 334 335 ftiso = new FolderToImportStepOperator(); 336 ftiso.back(); 338 339 rso = new RepositoryStepOperator(); 340 rso.setRepositoryURL(RepositoryStepOperator.ITEM_HTTPS); 341 rso = new RepositoryStepOperator(); 342 rso.verify(); 343 344 } catch (Exception e) { 345 throw new Exception ("Test failed: " + e); 346 } finally { 347 TestKit.closeProject(PROJECT_NAME); 348 } 349 } 350 } 351 | Popular Tags |