1 9 10 package org.netbeans.test.subversion.main.diff; 11 12 import java.io.BufferedReader ; 13 import java.io.File ; 14 import java.io.FileReader ; 15 import java.io.PrintStream ; 16 import org.netbeans.jellytools.JellyTestCase; 17 import org.netbeans.junit.NbTestSuite; 18 import org.netbeans.junit.ide.ProjectSupport; 19 import junit.textui.TestRunner; 20 import org.netbeans.jellytools.EditorOperator; 21 import org.netbeans.jellytools.NbDialogOperator; 22 import org.netbeans.jellytools.OutputTabOperator; 23 import org.netbeans.jellytools.ProjectsTabOperator; 24 import org.netbeans.jellytools.nodes.Node; 25 import org.netbeans.jellytools.nodes.SourcePackagesNode; 26 import org.netbeans.jemmy.JemmyProperties; 27 import org.netbeans.jemmy.QueueTool; 28 import org.netbeans.jemmy.operators.JButtonOperator; 29 import org.netbeans.jemmy.operators.JTextFieldOperator; 30 import org.netbeans.test.subversion.operators.CheckoutWizardOperator; 31 import org.netbeans.test.subversion.operators.RepositoryStepOperator; 32 import org.netbeans.test.subversion.operators.VersioningOperator; 33 import org.netbeans.test.subversion.operators.WorkDirStepOperator; 34 import org.netbeans.test.subversion.utils.RepositoryMaintenance; 35 import org.netbeans.test.subversion.utils.TestKit; 36 37 41 public class ExportDiffPatchTest extends JellyTestCase { 42 43 public static final String TMP_PATH = "/tmp"; 44 public static final String REPO_PATH = "repo"; 45 public static final String WORK_PATH = "work"; 46 public static final String PROJECT_NAME = "JavaApp"; 47 public File projectPath; 48 public PrintStream stream; 49 String os_name; 50 51 52 public ExportDiffPatchTest(String name) { 53 super(name); 54 } 55 56 protected void setUp() throws Exception { 57 os_name = System.getProperty("os.name"); 58 System.out.println("### "+getName()+" ###"); 60 61 } 62 63 protected boolean isUnix() { 64 boolean unix = false; 65 if (os_name.indexOf("Windows") == -1) { 66 unix = true; 67 } 68 return unix; 69 } 70 71 public static void main(String [] args) { 72 TestRunner.run(suite()); 74 } 75 76 public static NbTestSuite suite() { 77 NbTestSuite suite = new NbTestSuite(); 78 suite.addTest(new ExportDiffPatchTest("invokeExportDiffPatch")); 79 return suite; 80 } 81 82 public void invokeExportDiffPatch() throws Exception { 83 try { 86 TestKit.closeProject(PROJECT_NAME); 87 88 stream = new PrintStream (new File (getWorkDir(), getName() + ".log")); 89 VersioningOperator vo = VersioningOperator.invoke(); 90 CheckoutWizardOperator co = CheckoutWizardOperator.invoke(); 91 RepositoryStepOperator rso = new RepositoryStepOperator(); 92 93 File work = new File (TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis()); 95 new File (TMP_PATH).mkdirs(); 96 work.mkdirs(); 97 RepositoryMaintenance.deleteFolder(new File (TMP_PATH + File.separator + REPO_PATH)); 98 RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH); 100 RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump"); 101 rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false)); 102 103 rso.next(); 104 WorkDirStepOperator wdso = new WorkDirStepOperator(); 105 wdso.setRepositoryFolder("trunk/" + PROJECT_NAME); 106 wdso.setLocalFolder(work.getCanonicalPath()); 107 wdso.checkCheckoutContentOnly(false); 108 OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo"); 109 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 110 oto.clear(); 111 wdso.finish(); 112 oto.waitText("Checking out... finished."); 114 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 115 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 116 open.push(); 117 118 ProjectSupport.waitScanFinished(); 119 new QueueTool().waitEmpty(1000); 120 ProjectSupport.waitScanFinished(); 121 122 oto = new OutputTabOperator("file:///tmp/repo"); 124 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 125 oto.clear(); 126 Node node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java"); 127 node.performPopupAction("Open"); 128 EditorOperator eo = new EditorOperator("Main.java"); 129 eo.deleteLine(2); 130 eo.insert(" insert", 5, 1); 131 eo.insert("\tSystem.out.println(\"\");\n", 19, 1); 132 eo.save(); 133 node.performPopupAction("Subversion|Show Changes"); 134 Thread.sleep(1000); 135 vo = VersioningOperator.invoke(); 136 org.openide.nodes.Node nodeIDE = (org.openide.nodes.Node) node.getOpenideNode(); 138 String color = TestKit.getColor(nodeIDE.getHtmlDisplayName()); 139 String status = TestKit.getStatus(nodeIDE.getHtmlDisplayName()); 140 assertEquals("Wrong color of node - file color should be new!!!", TestKit.MODIFIED_COLOR, color); 141 assertEquals("Wrong annotation of node - file status should be new!!!", TestKit.MODIFIED_STATUS, status); 142 assertEquals("Wrong number of records in Versioning view!!!", 1, vo.tabFiles().getRowCount()); 143 144 node = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME); 145 node.select(); 146 node.performMenuActionNoBlock("Versioning|Export"); 147 nbdialog = new NbDialogOperator("Export"); 148 JButtonOperator btn = new JButtonOperator(nbdialog, "Export"); 149 JTextFieldOperator tf = new JTextFieldOperator(nbdialog, 0); 150 String patchFile = "/tmp/patch" + System.currentTimeMillis() + ".patch"; 151 File file = new File (patchFile); 152 tf.setText(file.getCanonicalFile().toString()); 153 oto = new OutputTabOperator("file:///tmp/repo"); 154 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 155 oto.clear(); 156 btn.push(); 157 oto.waitText("Diff Patch finished"); 158 159 BufferedReader br = new BufferedReader (new FileReader (file)); 160 String line = br.readLine(); 161 boolean generated = false; 162 if (line != null) { 163 generated = line.indexOf("# This patch file was generated by NetBeans IDE") != -1 ? true : false; 164 } 165 166 br.close(); 167 assertTrue("Diff Patch file is empty!", generated); 168 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 169 stream.flush(); 170 stream.close(); 171 172 } catch (Exception e) { 173 throw new Exception ("Test failed: " + e); 174 } finally { 175 TestKit.closeProject(PROJECT_NAME); 176 } 177 } 178 179 } 180 | Popular Tags |