1 19 20 package org.netbeans.test.cvsmodule; 21 22 import java.io.File ; 23 import java.io.InputStream ; 24 import junit.textui.TestRunner; 25 import org.netbeans.jellytools.JellyTestCase; 26 import org.netbeans.jellytools.NbDialogOperator; 27 import org.netbeans.jellytools.OutputOperator; 28 import org.netbeans.jellytools.OutputTabOperator; 29 import org.netbeans.jellytools.modules.javacvs.BranchOperator; 30 import org.netbeans.jellytools.modules.javacvs.BrowseTagsOperator; 31 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator; 32 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator; 33 import org.netbeans.jellytools.modules.javacvs.MergeChangesFromBranchOperator; 34 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator; 35 import org.netbeans.jellytools.modules.javacvs.SwitchToBranchOperator; 36 import org.netbeans.jellytools.nodes.Node; 37 import org.netbeans.jellytools.nodes.SourcePackagesNode; 38 import org.netbeans.jemmy.JemmyProperties; 39 import org.netbeans.jemmy.QueueTool; 40 import org.netbeans.jemmy.TimeoutExpiredException; 41 import org.netbeans.jemmy.operators.JButtonOperator; 42 import org.netbeans.jemmy.operators.JCheckBoxOperator; 43 import org.netbeans.jemmy.operators.JProgressBarOperator; 44 import org.netbeans.jemmy.operators.JRadioButtonOperator; 45 import org.netbeans.jemmy.operators.JTextFieldOperator; 46 import org.netbeans.jemmy.operators.Operator; 47 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 48 import org.netbeans.junit.NbTestSuite; 49 import org.netbeans.junit.ide.ProjectSupport; 50 54 public class BranchTest extends JellyTestCase { 55 56 String os_name; 57 static String sessionCVSroot; 58 boolean unix = false; 59 final String projectName = "ForImport"; 60 final String pathToMain = "forimport|Main.java"; 61 final String PROTOCOL_FOLDER = "protocol"; 62 Operator.DefaultStringComparator comOperator; 63 Operator.DefaultStringComparator oldOperator; 64 65 66 public BranchTest(String name) { 67 super(name); 68 } 69 70 protected void setUp() throws Exception { 71 72 os_name = System.getProperty("os.name"); 73 System.out.println("### "+getName()+" ###"); 75 76 } 77 78 protected boolean isUnix() { 79 boolean unix = false; 80 if (os_name.indexOf("Windows") == -1) { 81 unix = true; 82 } 83 return unix; 84 } 85 86 public static void main(String [] args) { 87 TestRunner.run(suite()); 89 } 90 91 public static NbTestSuite suite() { 92 NbTestSuite suite = new NbTestSuite(); 93 suite.addTest(new BranchTest("testCheckOutProject")); 94 suite.addTest(new BranchTest("testBranchDialogUI")); 95 suite.addTest(new BranchTest("testSwitchToBranchDialogUI")); 96 suite.addTest(new BranchTest("testMergeChangesFromBranchDialogUI")); 97 suite.addTest(new BranchTest("testOnNonVersioned")); 98 suite.addTest(new BranchTest("removeAllData")); 99 return suite; 102 } 103 104 public void testCheckOutProject() throws Exception { 105 TestKit.closeProject(projectName); 108 String CVSroot; 109 OutputOperator oo = OutputOperator.invoke(); 110 comOperator = new Operator.DefaultStringComparator(true, true); 111 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 112 Operator.setDefaultStringComparator(comOperator); 113 CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke(); 114 Operator.setDefaultStringComparator(oldOperator); 115 CVSRootStepOperator crso = new CVSRootStepOperator(); 116 crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs"); 118 121 InputStream in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in"); 123 PseudoCvsServer cvss = new PseudoCvsServer(in); 124 new Thread (cvss).start(); 125 cvss.ignoreProbe(); 126 CVSroot = cvss.getCvsRoot(); 127 sessionCVSroot = CVSroot; 128 crso.setCVSRoot(CVSroot); 129 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot); 130 crso.next(); 131 132 try { 133 JProgressBarOperator progress = new JProgressBarOperator(crso); 134 JButtonOperator btnStop = new JButtonOperator(crso); 135 } catch (TimeoutExpiredException e) { 136 throw e; 137 } 138 139 142 File tmp = new File ("/tmp"); File work = new File (tmp, "" + File.separator + System.currentTimeMillis()); 144 tmp.mkdirs(); 145 work.mkdirs(); 146 tmp.deleteOnExit(); 147 ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator(); 148 cvss.stop(); 149 in.close(); 150 moduleCheck.setModule(projectName); 151 moduleCheck.setLocalFolder(work.getAbsolutePath()); 153 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in"); 155 cvss = new PseudoCvsServer(in); 156 new Thread (cvss).start(); 157 CVSroot = cvss.getCvsRoot(); 158 160 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot); 163 cwo.finish(); 164 165 OutputTabOperator oto = new OutputTabOperator(sessionCVSroot); 166 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 167 oto.waitText("Checking out finished"); 168 Thread.sleep(1000); 169 cvss.stop(); 170 in.close(); 171 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 172 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 173 open.push(); 174 175 ProjectSupport.waitScanFinished(); 176 new QueueTool().waitEmpty(1000); 177 ProjectSupport.waitScanFinished(); 178 179 TestKit.createNewElements(projectName); 181 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 182 } 183 184 public void removeAllData() throws Exception { 185 TestKit.closeProject(projectName); 186 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 187 } 188 189 public void testBranchDialogUI() throws Exception { 190 191 PseudoCvsServer cvss; 194 InputStream in; 195 196 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in"); 197 cvss = new PseudoCvsServer(in); 198 new Thread (cvss).start(); 199 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 200 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 202 203 BranchOperator bo = BranchOperator.invoke(node); 204 BrowseTagsOperator browseTags = bo.browse(); 205 206 browseTags.selectPath("Head"); 208 browseTags.selectPath("Tags"); 210 browseTags.selectPath("Branches"); 212 browseTags.selectPath("Branches|MyBranch"); 214 browseTags.selectPath("Tags|MyBranch_root"); 215 cvss.stop(); 216 try { 219 JButtonOperator btnBranch = new JButtonOperator(browseTags, "OK"); 220 JButtonOperator btnHelp = new JButtonOperator(browseTags, "Help"); 221 JButtonOperator btnCancel = new JButtonOperator(browseTags, "Cancel"); 222 btnCancel.push(); 223 } catch(TimeoutExpiredException e) { 224 throw e; 225 } 226 try { 227 JTextFieldOperator tf1 = new JTextFieldOperator(bo, 0); 228 JTextFieldOperator tf2 = new JTextFieldOperator(bo, 1); 229 JCheckBoxOperator cb1 = new JCheckBoxOperator(bo, "Tag Before Branching"); 230 JCheckBoxOperator cb2 = new JCheckBoxOperator(bo, "Switch to This Branch Afterwards"); 231 JButtonOperator btnBranch = new JButtonOperator(bo, "Branch"); 232 JButtonOperator btnHelp = new JButtonOperator(bo, "Help"); 233 JButtonOperator btnCancel = new JButtonOperator(bo, "Cancel"); 234 235 } catch (TimeoutExpiredException ex) { 236 throw ex; 237 } 238 bo.checkTagBeforeBranching(false); 240 assertFalse(bo.txtTagName().isEnabled()); 241 bo.checkTagBeforeBranching(true); 243 assertTrue(bo.txtTagName().isEnabled()); 244 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 245 bo.cancel(); 246 } 247 248 public void testSwitchToBranchDialogUI() throws Exception { 249 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 252 SwitchToBranchOperator sbo = SwitchToBranchOperator.invoke(node); 253 JRadioButtonOperator trunkRb = new JRadioButtonOperator(sbo, "Switch to Trunk"); 254 JRadioButtonOperator branchRb = new JRadioButtonOperator(sbo, "Switch to Branch"); 255 sbo.switchToBranch(); 256 257 PseudoCvsServer cvss; 258 InputStream in; 259 260 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in"); 261 cvss = new PseudoCvsServer(in); 262 new Thread (cvss).start(); 263 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 264 266 BrowseTagsOperator browseTags = sbo.browse(); 267 browseTags.selectPath("Head"); 269 browseTags.selectPath("Tags"); 271 browseTags.selectPath("Branches"); 273 browseTags.selectPath("Branches|MyBranch"); 275 browseTags.selectPath("Tags|MyBranch_root"); 276 cvss.stop(); 277 TimeoutExpiredException tee = null; 280 try { 281 JButtonOperator btnOk = new JButtonOperator(browseTags, "OK"); 282 JButtonOperator btnHelp = new JButtonOperator(browseTags, "Help"); 283 JButtonOperator btnCancel = new JButtonOperator(browseTags, "Cancel"); 284 btnCancel.push(); 285 } catch(Exception e) { 286 if (e instanceof TimeoutExpiredException) { 287 tee = (TimeoutExpiredException) e; 288 } else { 289 throw e; 290 } 291 } 292 assertNull("All components should be available, but some of them were not!", tee); 293 294 tee = null; 295 try { 296 JTextFieldOperator tf1 = new JTextFieldOperator(sbo, 0); 297 299 JButtonOperator btnBranch = new JButtonOperator(sbo, "Switch"); 300 JButtonOperator btnHelp = new JButtonOperator(sbo, "Help"); 301 JButtonOperator btnCancel = new JButtonOperator(sbo, "Cancel"); 302 } catch (Exception e) { 303 if (e instanceof TimeoutExpiredException) { 304 tee = (TimeoutExpiredException) e; 305 } else { 306 throw e; 307 } 308 } 309 assertNull("All components should be available, but some of them were not!", tee); 310 311 sbo.switchToTrunk(); 313 assertEquals(false, sbo.btBrowse().isEnabled()); 314 sbo.switchToBranch(); 315 assertEquals(true, sbo.btBrowse().isEnabled()); 316 sbo.cancel(); 317 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 318 } 319 320 public void testMergeChangesFromBranchDialogUI() throws Exception { 321 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 324 MergeChangesFromBranchOperator mcbo = MergeChangesFromBranchOperator.invoke(node); 325 mcbo.mergeFromBranch(); 326 327 PseudoCvsServer cvss; 329 InputStream in; 330 331 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in"); 332 cvss = new PseudoCvsServer(in); 333 new Thread (cvss).start(); 334 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 335 336 BrowseTagsOperator browseTags = mcbo.browseMergeFromBranch(); 337 browseTags.selectPath("Head"); 339 browseTags.selectPath("Tags"); 341 browseTags.selectPath("Branches"); 343 browseTags.selectPath("Branches|MyBranch"); 344 browseTags.selectPath("Tags|MyBranch_root"); 345 cvss.stop(); 346 try { 347 JButtonOperator btnOk = new JButtonOperator(browseTags, "OK"); 348 JButtonOperator btnHelp = new JButtonOperator(browseTags, "Help"); 349 JButtonOperator btnCancel = new JButtonOperator(browseTags, "Cancel"); 350 btnCancel.push(); 351 } catch(TimeoutExpiredException e) { 352 throw e; 353 } 354 355 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in"); 357 cvss = new PseudoCvsServer(in); 358 new Thread (cvss).start(); 359 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 360 361 mcbo.checkMergeAfterTag(true); 362 browseTags = mcbo.browseMergeAfterTag(); 363 browseTags.selectPath("Head"); 365 browseTags.selectPath("Tags"); 367 browseTags.selectPath("Branches"); 369 browseTags.selectPath("Branches|MyBranch"); 370 browseTags.selectPath("Tags|MyBranch_root"); 371 cvss.stop(); 372 try { 373 JButtonOperator btnOk = new JButtonOperator(browseTags, "OK"); 374 JButtonOperator btnHelp = new JButtonOperator(browseTags, "Help"); 375 JButtonOperator btnCancel = new JButtonOperator(browseTags, "Cancel"); 376 btnCancel.push(); 377 } catch(TimeoutExpiredException e) { 378 throw e; 379 } 380 381 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in"); 383 cvss = new PseudoCvsServer(in); 384 new Thread (cvss).start(); 385 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 386 387 mcbo.checkTagAfterMerge(true); 388 browseTags = mcbo.browseTagAfterMerge(); 389 browseTags.selectPath("Head"); 391 browseTags.selectPath("Tags"); 393 browseTags.selectPath("Branches"); 395 browseTags.selectPath("Branches|MyBranch"); 396 browseTags.selectPath("Tags|MyBranch_root"); 397 cvss.stop(); 398 try { 399 JButtonOperator btnOk = new JButtonOperator(browseTags, "OK"); 400 JButtonOperator btnHelp = new JButtonOperator(browseTags, "Help"); 401 JButtonOperator btnCancel = new JButtonOperator(browseTags, "Cancel"); 402 btnCancel.push(); 403 } catch(TimeoutExpiredException e) { 404 throw e; 405 } 406 try { 407 JTextFieldOperator tf1 = new JTextFieldOperator(mcbo, 0); 408 JTextFieldOperator tf2 = new JTextFieldOperator(mcbo, 1); 409 JTextFieldOperator tf3 = new JTextFieldOperator(mcbo, 2); 410 JButtonOperator btnMerge = new JButtonOperator(mcbo, "Merge"); 411 JButtonOperator btnHelp = new JButtonOperator(mcbo, "Help"); 412 JButtonOperator btnCancel = new JButtonOperator(mcbo, "Cancel"); 413 } catch (TimeoutExpiredException ex) { 414 throw ex; 415 } 416 417 mcbo.mergeFromTrunk(); 420 assertFalse(mcbo.txtMergeFromBranch().isEnabled()); 421 assertFalse(mcbo.btBrowseMergeFromBranch().isEnabled()); 422 mcbo.mergeFromBranch(); 424 assertTrue(mcbo.txtMergeFromBranch().isEnabled()); 425 assertTrue(mcbo.btBrowseMergeFromBranch().isEnabled()); 426 427 mcbo.checkMergeAfterTag(false); 429 assertFalse(mcbo.txtMergeAfterTag().isEnabled()); 430 assertFalse(mcbo.btBrowseMergeAfterTag().isEnabled()); 431 mcbo.checkMergeAfterTag(true); 433 assertTrue(mcbo.txtMergeAfterTag().isEnabled()); 434 assertTrue(mcbo.btBrowseMergeAfterTag().isEnabled()); 435 436 mcbo.checkTagAfterMerge(false); 438 assertFalse(mcbo.txtTagAfterMerge().isEnabled()); 439 assertFalse(mcbo.btBrowseTagAfterMerge().isEnabled()); 440 mcbo.checkTagAfterMerge(true); 442 assertTrue(mcbo.txtTagAfterMerge().isEnabled()); 443 assertTrue(mcbo.btBrowseTagAfterMerge().isEnabled()); 444 mcbo.cancel(); 445 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 446 } 447 448 public void testOnNonVersioned() throws Exception { 449 454 TimeoutExpiredException tee = null; 455 try { 456 Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java"); 457 BranchOperator bo = BranchOperator.invoke(node); 458 } catch (Exception e) { 459 tee = (TimeoutExpiredException) e; 460 } 461 assertNotNull(tee); 462 tee = null; 464 try { 465 Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java"); 466 SwitchToBranchOperator sbo = SwitchToBranchOperator.invoke(node); 467 } catch (Exception e) { 468 tee = (TimeoutExpiredException) e; 469 } 470 assertNotNull(tee); 471 tee = null; 473 try { 474 Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java"); 475 MergeChangesFromBranchOperator mcbo = MergeChangesFromBranchOperator.invoke(node); 476 } catch (Exception e) { 477 tee = (TimeoutExpiredException) e; 478 } 479 assertNotNull(tee); 480 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 481 } 482 } 483 484 485 | Popular Tags |