1 19 20 28 29 package org.netbeans.test.cvsmodule; 30 31 import java.io.BufferedReader ; 32 import java.io.File ; 33 import java.io.FileReader ; 34 import java.io.InputStream ; 35 import junit.textui.TestRunner; 36 import org.netbeans.jellytools.EditorOperator; 37 import org.netbeans.jellytools.JellyTestCase; 38 import org.netbeans.jellytools.NbDialogOperator; 39 import org.netbeans.jellytools.OutputOperator; 40 import org.netbeans.jellytools.OutputTabOperator; 41 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator; 42 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator; 43 import org.netbeans.jellytools.modules.javacvs.CommitOperator; 44 import org.netbeans.jellytools.modules.javacvs.DiffOperator; 45 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator; 46 import org.netbeans.jellytools.nodes.Node; 47 import org.netbeans.jellytools.nodes.SourcePackagesNode; 48 import org.netbeans.jemmy.JemmyProperties; 49 import org.netbeans.jemmy.QueueTool; 50 import org.netbeans.jemmy.TimeoutExpiredException; 51 import org.netbeans.jemmy.operators.JButtonOperator; 52 import org.netbeans.jemmy.operators.JProgressBarOperator; 53 import org.netbeans.jemmy.operators.JTableOperator; 54 import org.netbeans.jemmy.operators.JTextFieldOperator; 55 import org.netbeans.jemmy.operators.Operator; 56 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 57 import org.netbeans.junit.NbTestSuite; 58 import org.netbeans.junit.ide.ProjectSupport; 59 60 64 public class ExportPatchAndDiffTest extends JellyTestCase { 65 66 String os_name; 67 static String sessionCVSroot; 68 final String projectName = "ForImport"; 69 final String pathToMain = "forimport|Main.java"; 70 final String PROTOCOL_FOLDER = "protocol"; 71 static File cacheFolder; 72 Operator.DefaultStringComparator comOperator; 73 Operator.DefaultStringComparator oldOperator; 74 75 76 public ExportPatchAndDiffTest(String name) { 77 super(name); 78 } 79 80 public static void main(String [] args) { 81 TestRunner.run(suite()); 83 } 84 85 protected void setUp() throws Exception { 86 os_name = System.getProperty("os.name"); 87 System.out.println("### " + getName() + " ###"); 89 } 90 91 public static NbTestSuite suite() { 92 NbTestSuite suite = new NbTestSuite(); 93 suite.addTest(new ExportPatchAndDiffTest("testCheckOutProject")); 94 suite.addTest(new ExportPatchAndDiffTest("testExportDiffPatch")); 95 suite.addTest(new ExportPatchAndDiffTest("testDiffFile")); 96 suite.addTest(new ExportPatchAndDiffTest("removeAllData")); 97 return suite; 98 } 99 100 public void testCheckOutProject() throws Exception { 101 TestKit.closeProject(projectName); 104 comOperator = new Operator.DefaultStringComparator(true, true); 105 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 106 Operator.setDefaultStringComparator(comOperator); 107 CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke(); 108 Operator.setDefaultStringComparator(oldOperator); 109 CVSRootStepOperator crso = new CVSRootStepOperator(); 110 crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs"); 111 InputStream in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in"); 113 PseudoCvsServer cvss = new PseudoCvsServer(in); 114 new Thread (cvss).start(); 115 cvss.ignoreProbe(); 116 String CVSroot = cvss.getCvsRoot(); 117 sessionCVSroot = CVSroot; 118 crso.setCVSRoot(CVSroot); 119 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot); 120 crso.next(); 121 try { 122 JProgressBarOperator progress = new JProgressBarOperator(crso); 123 JButtonOperator btnStop = new JButtonOperator(crso); 124 } catch (TimeoutExpiredException e) { 125 throw e; 126 } 127 File tmp = new File ("/tmp"); File work = new File (tmp, "" + File.separator + System.currentTimeMillis()); 130 cacheFolder = new File (work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache"); 131 tmp.mkdirs(); 132 work.mkdirs(); 133 tmp.deleteOnExit(); 134 ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator(); 135 cvss.stop(); 136 in.close(); 137 moduleCheck.setModule("ForImport"); 138 moduleCheck.setLocalFolder(work.getAbsolutePath()); in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in"); 141 cvss = new PseudoCvsServer(in); 142 new Thread (cvss).start(); 143 CVSroot = cvss.getCvsRoot(); 144 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot); 145 cwo.finish(); 146 OutputOperator oo = OutputOperator.invoke(); 147 OutputTabOperator oto = oo.getOutputTab(sessionCVSroot); 148 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 149 oto.waitText("Checking out finished"); 150 cvss.stop(); 151 in.close(); 152 NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed"); 153 JButtonOperator open = new JButtonOperator(nbdialog, "Open Project"); 154 open.push(); 155 156 ProjectSupport.waitScanFinished(); 157 new QueueTool().waitEmpty(1000); 158 ProjectSupport.waitScanFinished(); 159 160 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 161 } 162 163 public void testExportDiffPatch() throws Exception { 164 PseudoCvsServer cvss; 167 InputStream in; 168 OutputTabOperator oto; 169 oto = new OutputTabOperator(sessionCVSroot); 170 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 171 Node nodeClass = new Node(new SourcePackagesNode(projectName), pathToMain); 172 oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator(); 173 comOperator = new Operator.DefaultStringComparator(true, true); 174 175 nodeClass.performPopupAction("Open"); 176 EditorOperator eo = new EditorOperator("Main.java"); 177 eo.insert("// EXPORT PATCH", 5, 1); 178 eo.save(); 179 Operator.setDefaultStringComparator(comOperator); 181 nodeClass.select(); 182 nodeClass.performMenuActionNoBlock("Versioning|Export \"Main.java\" Diff Patch..."); 183 Operator.setDefaultStringComparator(oldOperator); 184 NbDialogOperator dialog = new NbDialogOperator("Export"); 185 JTextFieldOperator tf = new JTextFieldOperator(dialog, 0); 186 String patchFile = "/tmp/patch" + System.currentTimeMillis() + ".patch"; 187 File file = new File (patchFile); 188 tf.setText(file.getCanonicalFile().toString()); 189 JButtonOperator btnExport = new JButtonOperator(dialog, "export"); 190 oto = new OutputTabOperator(sessionCVSroot); 191 oto.clear(); 192 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "diff/export_diff.in"); 193 cvss = new PseudoCvsServer(in); 194 new Thread (cvss).start(); 195 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 196 btnExport.push(); 197 Thread.sleep(3000); 200 cvss.stop(); 201 Thread.sleep(2000); 202 assertTrue("Diff Patch file wasn't created!", file.isFile()); 204 BufferedReader br = new BufferedReader (new FileReader (file)); 205 String line = br.readLine(); 206 boolean generated = false; 207 if (line != null) { 208 generated = line.indexOf("# This patch file was generated by NetBeans IDE") != -1 ? true : false; 209 } 210 211 br.close(); 212 assertTrue("Diff Patch file is empty!", generated); 213 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 214 } 215 public void testDiffFile() throws Exception { 216 PseudoCvsServer cvss; 218 InputStream in; 219 OutputTabOperator oto; 221 org.openide.nodes.Node nodeIDE; 222 String color; 223 224 oto = new OutputTabOperator(sessionCVSroot); 225 oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000); 226 227 Node node = new Node(new SourcePackagesNode(projectName), pathToMain); 228 node.performPopupAction("Open"); 229 EditorOperator eo = new EditorOperator("Main.java"); 230 eo.deleteLine(2); 231 eo.insert(" insert", 5, 1); 232 eo.insert("\tSystem.out.println(\"\");\n", 19, 1); 233 eo.save(); 234 235 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "diff_class.in"); 236 cvss = new PseudoCvsServer(in); 237 new Thread (cvss).start(); 238 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 239 node.performPopupAction("CVS|Diff..."); 240 241 Thread.sleep(1000); 243 cvss.stop(); 244 245 Node nodeClass = new Node(new SourcePackagesNode(projectName), pathToMain); 246 nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode(); 247 color = TestKit.getColor(nodeIDE.getHtmlDisplayName()); 248 assertEquals("Wrong color for modified file", TestKit.MODIFIED_COLOR, color); 249 250 DiffOperator diffOp = new DiffOperator("Main.java"); 252 try { 254 TimeoutExpiredException afee = null; 255 diffOp.next(); 256 diffOp.next(); 257 try { 258 diffOp.next(); 259 } catch (TimeoutExpiredException e) { 260 afee = e; 261 } 262 assertNotNull("TimeoutExpiredException was expected.", afee); 263 264 afee = null; 266 diffOp.previous(); 267 diffOp.previous(); 268 try { 269 diffOp.previous(); 270 } catch (TimeoutExpiredException e) { 271 afee = e; 272 } 273 assertNotNull("TimeoutExpiredException was expected.", afee); 274 } catch (Exception e) { 275 System.out.println("Problem with buttons of differences"); 276 } 277 278 oto = new OutputTabOperator(sessionCVSroot); 280 oto.clear(); 281 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "diff/refresh.in"); 282 cvss = new PseudoCvsServer(in); 283 new Thread (cvss).start(); 284 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 285 diffOp.refresh(); 286 oto.waitText("Refreshing CVS Status finished"); 287 cvss.stop(); 288 Thread.sleep(1000); 289 290 oto = new OutputTabOperator(sessionCVSroot); 292 oto.clear(); 293 in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "diff/refresh.in"); 294 cvss = new PseudoCvsServer(in); 295 new Thread (cvss).start(); 296 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot()); 297 diffOp.update(); 298 oto.waitText("Updating Sources finished"); 299 cvss.stop(); 300 Thread.sleep(1000); 301 302 CommitOperator co = diffOp.commit(); 304 JTableOperator table = co.tabFiles(); 305 assertEquals("There should be only one file!", 1, table.getRowCount()); 306 assertEquals("There should be Main.java file only!", "Main.java", table.getValueAt(0, 0)); 307 co.cancel(); 308 309 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 310 eo.closeAllDocuments(); 312 TestKit.deleteRecursively(cacheFolder); 313 } 314 315 public void removeAllData() throws Exception { 316 TestKit.closeProject(projectName); 317 System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", ""); 318 } 319 } 320 | Popular Tags |