1 9 10 package org.netbeans.test.subversion.main.commit; 11 12 import java.io.File ; 13 import java.io.PrintStream ; 14 import javax.swing.table.TableModel ; 15 import junit.textui.TestRunner; 16 import org.netbeans.jellytools.JellyTestCase; 17 import org.netbeans.jellytools.NbDialogOperator; 18 import org.netbeans.jellytools.OutputTabOperator; 19 import org.netbeans.jellytools.ProjectsTabOperator; 20 import org.netbeans.jellytools.nodes.Node; 21 import org.netbeans.jellytools.nodes.SourcePackagesNode; 22 import org.netbeans.jemmy.JemmyProperties; 23 import org.netbeans.jemmy.QueueTool; 24 import org.netbeans.jemmy.TimeoutExpiredException; 25 import org.netbeans.jemmy.operators.JButtonOperator; 26 import org.netbeans.jemmy.operators.JTableOperator; 27 import org.netbeans.jemmy.operators.Operator; 28 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 29 import org.netbeans.junit.NbTestSuite; 30 import org.netbeans.junit.ide.ProjectSupport; 31 import org.netbeans.test.subversion.operators.CheckoutWizardOperator; 32 import org.netbeans.test.subversion.operators.CommitOperator; 33 import org.netbeans.test.subversion.operators.RepositoryStepOperator; 34 import org.netbeans.test.subversion.operators.VersioningOperator; 35 import org.netbeans.test.subversion.operators.WorkDirStepOperator; 36 import org.netbeans.test.subversion.utils.RepositoryMaintenance; 37 import org.netbeans.test.subversion.utils.TestKit; 38 39 43 public class CommitDataTest extends JellyTestCase { 44 45 public static final String TMP_PATH = "/tmp"; 46 public static final String REPO_PATH = "repo"; 47 public static final String WORK_PATH = "work"; 48 public static final String PROJECT_NAME = "JavaApp"; 49 public File projectPath; 50 public PrintStream stream; 51 String os_name; 52 Operator.DefaultStringComparator comOperator; 53 Operator.DefaultStringComparator oldOperator; 54 55 56 public CommitDataTest(String name) { 57 super(name); 58 } 59 60 protected void setUp() throws Exception { 61 os_name = System.getProperty("os.name"); 62 System.out.println("### "+getName()+" ###"); 64 65 } 66 67 protected boolean isUnix() { 68 boolean unix = false; 69 if (os_name.indexOf("Windows") == -1) { 70 unix = true; 71 } 72 return unix; 73 } 74 75 public static void main(String [] args) { 76 TestRunner.run(suite()); 78 } 79 80 public static NbTestSuite suite() { 81 NbTestSuite suite = new NbTestSuite(); 82 suite.addTest(new CommitDataTest("testCommitFile")); 83 suite.addTest(new CommitDataTest("testCommitPackage")); 84 suite.addTest(new CommitDataTest("testRecognizeMimeType")); 85 return suite; 86 } 87 88 public void testCommitFile() throws Exception { 89 try { 92 TestKit.closeProject(PROJECT_NAME); 93 org.openide.nodes.Node nodeIDE; 94 long start; 95 long end; 96 String color; 97 String status; 98 JTableOperator table; 99 TableModel model; 100 VersioningOperator vo; 101 102 stream = new PrintStream (new File (getWorkDir(), getName() + ".log")); 103 comOperator = new Operator.DefaultStringComparator(true, true); 104 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 105 Operator.setDefaultStringComparator(comOperator); 106 CheckoutWizardOperator co = CheckoutWizardOperator.invoke(); 107 Operator.setDefaultStringComparator(oldOperator); 108 RepositoryStepOperator rso = new RepositoryStepOperator(); 109 110 File work = new File (TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis()); 112 new File (TMP_PATH).mkdirs(); 113 work.mkdirs(); 114 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 115 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 117 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 118 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 119 120 rso.next(); 121 OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo"); 122 oto.clear(); 123 WorkDirStepOperator wdso = new WorkDirStepOperator(); 124 wdso.setRepositoryFolder("trunk/" + PROJECT_NAME); 125 wdso.setLocalFolder(work.getCanonicalPath()); 126 wdso.checkCheckoutContentOnly(false); 127 wdso.finish(); 128 oto = new OutputTabOperator("file:///tmp/repo"); 130 oto.waitText("Checking out... finished."); 131 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 132 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 133 open.push(); 134 135 ProjectSupport.waitScanFinished(); 136 new QueueTool().waitEmpty(1000); 137 ProjectSupport.waitScanFinished(); 138 140 TestKit.createNewElement(PROJECT_NAME, "javaapp", "NewClass"); 141 Node nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java"); 142 nodeFile.performPopupAction("Subversion|Show Changes"); 143 nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode(); 144 color = TestKit.getColor(nodeIDE.getHtmlDisplayName()); 145 vo = VersioningOperator.invoke(); 146 table = vo.tabFiles(); 147 assertEquals("Wrong row count of table.", 1, table.getRowCount()); 148 assertEquals("Wrong color of node!!!", TestKit.NEW_COLOR, color); 149 150 start = System.currentTimeMillis(); 152 nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java"); 153 CommitOperator cmo = CommitOperator.invoke(nodeFile); 154 end = System.currentTimeMillis(); 155 TestKit.printLogStream(stream, "Duration of invoking Commit dialog: " + (end - start)); 158 cmo.selectCommitAction("NewClass.java", "Exclude from Commit"); 159 TimeoutExpiredException tee = null; 160 assertFalse(cmo.btCommit().isEnabled()); 161 cmo.cancel(); 162 nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java"); 163 nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode(); 164 color = TestKit.getColor(nodeIDE.getHtmlDisplayName()); 165 table = vo.tabFiles(); 166 Thread.sleep(1000); 167 assertEquals("Wrong row count of table.", 1, table.getRowCount()); 168 assertEquals("Expected file is missing.", "NewClass.java", table.getModel().getValueAt(0, 0).toString()); 169 assertEquals("Wrong color of node!!!", TestKit.NEW_COLOR, color); 170 171 oto = new OutputTabOperator("file:///tmp/repo"); 172 oto.clear(); 173 nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java"); 174 cmo = CommitOperator.invoke(nodeFile); 175 cmo.selectCommitAction("NewClass.java", "Add as Text"); 176 start = System.currentTimeMillis(); 177 cmo.commit(); 178 oto.waitText("Committing... finished."); 179 end = System.currentTimeMillis(); 180 181 nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java"); 182 nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode(); 183 TestKit.printLogStream(stream, "Duration of invoking Commit dialog: " + (end - start)); 185 Thread.sleep(1000); 187 vo = VersioningOperator.invoke(); 188 try { 190 vo.tabFiles(); 191 } catch (Exception e) { 192 tee = (TimeoutExpiredException) e; 193 } 194 assertNotNull("There shouldn't be any table in Versioning view", tee); 195 stream.flush(); 196 stream.close(); 197 198 } catch (Exception e) { 199 throw new Exception ("Test failed: " + e); 200 } finally { 201 TestKit.closeProject(PROJECT_NAME); 202 } 203 } 204 205 public void testCommitPackage() throws Exception { 206 try { 209 TestKit.closeProject(PROJECT_NAME); 210 org.openide.nodes.Node nodeIDE; 211 JTableOperator table; 212 long start; 213 long end; 214 String color; 215 String status; 216 VersioningOperator vo = VersioningOperator.invoke(); 217 218 stream = new PrintStream (new File (getWorkDir(), getName() + ".log")); 219 comOperator = new Operator.DefaultStringComparator(true, true); 220 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 221 Operator.setDefaultStringComparator(comOperator); 222 CheckoutWizardOperator co = CheckoutWizardOperator.invoke(); 223 Operator.setDefaultStringComparator(oldOperator); 224 RepositoryStepOperator rso = new RepositoryStepOperator(); 225 226 File work = new File (TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis()); 228 new File (TMP_PATH).mkdirs(); 229 work.mkdirs(); 230 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 231 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 233 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 234 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 235 236 rso.next(); 237 OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo"); 238 oto.clear(); 239 WorkDirStepOperator wdso = new WorkDirStepOperator(); 240 wdso.setRepositoryFolder("trunk/" + PROJECT_NAME); 241 wdso.setLocalFolder(work.getCanonicalPath()); 242 wdso.checkCheckoutContentOnly(false); 243 wdso.finish(); 244 oto.waitText("Checking out... finished."); 246 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 247 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 248 open.push(); 249 250 ProjectSupport.waitScanFinished(); 251 new QueueTool().waitEmpty(1000); 252 ProjectSupport.waitScanFinished(); 253 254 Node projNode = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME); 255 256 TestKit.createNewPackage(PROJECT_NAME, "xx"); 257 Node nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx"); 258 nodePack.performPopupAction("Subversion|Show Changes"); 259 nodeIDE = (org.openide.nodes.Node) nodePack.getOpenideNode(); 260 status = TestKit.getStatus(nodeIDE.getHtmlDisplayName()); 261 Thread.sleep(1000); 263 vo = VersioningOperator.invoke(); 264 table = vo.tabFiles(); 265 assertEquals("Wrong status of node!!!", TestKit.NEW_STATUS, status); 266 assertEquals("Wrong row count of table.", 1, table.getRowCount()); 267 assertEquals("Expected folder is missing.", "xx", table.getModel().getValueAt(0, 0).toString()); 268 269 start = System.currentTimeMillis(); 271 nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx"); 272 CommitOperator cmo = CommitOperator.invoke(nodePack); 273 end = System.currentTimeMillis(); 274 TestKit.printLogStream(stream, "Duration of invoking Commit dialog: " + (end - start)); 277 cmo.selectCommitAction("xx", "Exclude from Commit"); 278 assertFalse(cmo.btCommit().isEnabled()); 279 cmo.cancel(); 280 nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx"); 281 nodeIDE = (org.openide.nodes.Node) nodePack.getOpenideNode(); 282 status = TestKit.getStatus(nodeIDE.getHtmlDisplayName()); 283 assertEquals("Wrong status of node!!!", TestKit.NEW_STATUS, status); 284 285 oto = new OutputTabOperator("file:///tmp/repo"); 286 oto.clear(); 287 nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx"); 288 cmo = CommitOperator.invoke(nodePack); 289 cmo.selectCommitAction("xx", "Add Directory"); 290 start = System.currentTimeMillis(); 291 cmo.commit(); 292 oto.waitText("Committing... finished."); 293 end = System.currentTimeMillis(); 294 295 nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx"); 296 nodeIDE = (org.openide.nodes.Node) nodePack.getOpenideNode(); 297 TestKit.printLogStream(stream, "Duration of committing folder: " + (end - start)); 299 status = TestKit.getStatus(nodeIDE.getHtmlDisplayName()); 300 assertEquals("Wrong status of node!!!", TestKit.UPTODATE_STATUS, status); 301 Thread.sleep(1000); 302 vo = VersioningOperator.invoke(); 303 TimeoutExpiredException tee = null; 304 try { 305 vo.tabFiles(); 306 } catch (Exception e) { 307 tee = (TimeoutExpiredException) e; 308 } 309 assertNotNull("There shouldn't be any table in Versioning view", tee); 310 stream.flush(); 312 stream.close(); 313 314 } catch (Exception e) { 315 throw new Exception ("Test failed: " + e); 316 } finally { 317 TestKit.closeProject(PROJECT_NAME); 318 } 319 } 320 321 public void testRecognizeMimeType() throws Exception { 322 try { 325 TestKit.closeProject(PROJECT_NAME); 326 org.openide.nodes.Node nodeIDE; 327 JTableOperator table; 328 long start; 329 long end; 330 String color; 331 String status; 332 String [] expected = {"pp.bmp", "pp.dib", "pp.GIF", "pp.JFIF", "pp.JPE", "pp.JPEG", "pp.JPG", "pp.PNG", "pp.TIF", "pp.TIFF", "pp.zip", "text.txt", "test.jar"}; 333 334 VersioningOperator vo = VersioningOperator.invoke(); 335 336 stream = new PrintStream (new File (getWorkDir(), getName() + ".log")); 337 comOperator = new Operator.DefaultStringComparator(true, true); 338 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 339 Operator.setDefaultStringComparator(comOperator); 340 CheckoutWizardOperator co = CheckoutWizardOperator.invoke(); 341 Operator.setDefaultStringComparator(oldOperator); 342 RepositoryStepOperator rso = new RepositoryStepOperator(); 343 344 File work = new File (TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis()); 346 new File (TMP_PATH).mkdirs(); 347 work.mkdirs(); 348 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 349 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 351 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 352 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 353 354 rso.next(); 355 OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo"); 356 oto.clear(); 357 WorkDirStepOperator wdso = new WorkDirStepOperator(); 358 wdso.setRepositoryFolder("trunk/" + PROJECT_NAME); 359 wdso.setLocalFolder(work.getCanonicalPath()); 360 wdso.checkCheckoutContentOnly(false); 361 wdso.finish(); 362 oto.waitText("Checking out... finished."); 364 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 365 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 366 open.push(); 367 368 ProjectSupport.waitScanFinished(); 369 new QueueTool().waitEmpty(1000); 370 ProjectSupport.waitScanFinished(); 371 372 String src = getDataDir().getCanonicalPath() + File.separator + "files" + File.separator; 374 String dest = work.getCanonicalPath() + File.separator + PROJECT_NAME + File.separator + "src" + File.separator + "javaapp" + File.separator; 375 376 for (int i = 0; i < expected.length; i++) { 377 TestKit.copyTo(src + expected[i], dest + expected[i]); 378 } 379 380 oto = new OutputTabOperator("file:///tmp/repo"); 381 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 382 oto.clear(); 383 384 Node nodeSrc = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp"); 385 nodeSrc.performPopupAction("Subversion|Show Changes"); 386 oto.waitText("Refreshing... finished."); 387 388 Node nodeTest; 389 for (int i = 0; i < expected.length; i++) { 390 nodeTest = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|" + expected[i]); 391 nodeIDE = (org.openide.nodes.Node) nodeTest.getOpenideNode(); 392 status = TestKit.getStatus(nodeIDE.getHtmlDisplayName()); 393 color = TestKit.getColor(nodeIDE.getHtmlDisplayName()); 394 assertEquals("Wrong status of node!!!", TestKit.NEW_STATUS, status); 395 assertEquals("Wrong color of node!!!", TestKit.NEW_COLOR, color); 396 } 397 398 vo = VersioningOperator.invoke(); 399 TableModel model = vo.tabFiles().getModel(); 400 String [] actual = new String [model.getRowCount()];; 401 for (int i = 0; i < actual.length; i++) { 402 actual[i] = model.getValueAt(i, 0).toString(); 403 } 404 int result = TestKit.compareThem(expected, actual, false); 405 assertEquals("Not All files listed in Commit dialog", expected.length, result); 406 407 oto = new OutputTabOperator("file:///tmp/repo"); 408 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 409 oto.clear(); 410 nodeSrc = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp"); 411 CommitOperator cmo = CommitOperator.invoke(nodeSrc); 412 table = cmo.tabFiles(); 413 model = table.getModel(); 414 actual = new String [model.getRowCount()]; 415 for (int i = 0; i < actual.length; i++) { 416 actual[i] = model.getValueAt(i, 0).toString(); 417 if (actual[i].endsWith(".txt")) { 418 assertEquals("Expected text file.", "Add as Text", model.getValueAt(i, 2).toString()); 419 } else { 421 assertEquals("Expected text file.", "Add as Binary", model.getValueAt(i, 2).toString()); 422 } 423 } 424 result = TestKit.compareThem(expected, actual, false); 425 assertEquals("Not All files listed in Commit dialog", expected.length, result); 426 cmo.commit(); 427 for (int i = 0; i < expected.length; i++) { 428 oto.waitText("add -N"); 429 oto.waitText(expected[i]); 430 } 431 oto.waitText("Committing... finished."); 432 434 for (int i = 0; i < expected.length; i++) { 437 nodeTest = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|" + expected[i]); 438 nodeIDE = (org.openide.nodes.Node) nodeTest.getOpenideNode(); 439 assertNull("Wrong status or color of node!!!", nodeIDE.getHtmlDisplayName()); 440 } 441 vo = VersioningOperator.invoke(); 443 TimeoutExpiredException tee = null; 444 try { 445 vo.tabFiles(); 446 } catch (Exception e) { 447 tee = (TimeoutExpiredException) e; 448 } 449 assertNotNull("There shouldn't be any table in Versioning view", tee); 450 stream.flush(); 452 stream.close(); 453 454 } catch (Exception e) { 455 throw new Exception ("Test failed: " + e); 456 } finally { 457 TestKit.closeProject(PROJECT_NAME); 458 } 459 } 460 } 461 | Popular Tags |