KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > cvsmodule > ExportPatchAndDiffTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * ExportPatchAndDiffTest.java
22  *
23  * Created on 15. prosinec 2006, 10:57
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.test.cvsmodule;
30
31 import java.io.BufferedReader JavaDoc;
32 import java.io.File JavaDoc;
33 import java.io.FileReader JavaDoc;
34 import java.io.InputStream JavaDoc;
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 /**
61  *
62  * @author novakm
63  */

64 public class ExportPatchAndDiffTest extends JellyTestCase {
65     
66     String JavaDoc os_name;
67     static String JavaDoc sessionCVSroot;
68     final String JavaDoc projectName = "ForImport";
69     final String JavaDoc pathToMain = "forimport|Main.java";
70     final String JavaDoc PROTOCOL_FOLDER = "protocol";
71     static File JavaDoc cacheFolder;
72     Operator.DefaultStringComparator comOperator;
73     Operator.DefaultStringComparator oldOperator;
74     
75     /** Creates a new instance of ExportPatchAndDiffTest */
76     public ExportPatchAndDiffTest(String JavaDoc name) {
77         super(name);
78     }
79     
80     public static void main(String JavaDoc[] args) {
81         // TODO code application logic here
82
TestRunner.run(suite());
83     }
84     
85     protected void setUp() throws Exception JavaDoc {
86         os_name = System.getProperty("os.name");
87         //System.out.println(os_name);
88
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 JavaDoc {
101         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
102
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
103
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         //prepare stream for successful authentification and run PseudoCVSServer
112
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
113         PseudoCvsServer cvss = new PseudoCvsServer(in);
114         new Thread JavaDoc(cvss).start();
115         cvss.ignoreProbe();
116         String JavaDoc 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         //2nd step of CheckOutWizard
128
File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
129
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
130         cacheFolder = new File JavaDoc(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()); // NOI18N
139
//Pseudo CVS server for finishing check out wizard
140
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
141         cvss = new PseudoCvsServer(in);
142         new Thread JavaDoc(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 JavaDoc {
164         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
165
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
166
PseudoCvsServer cvss;
167         InputStream JavaDoc 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         //nodeClass.performMenuActionNoBlock("Versioning|CVS|Export");
180
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 JavaDoc patchFile = "/tmp/patch" + System.currentTimeMillis() + ".patch";
187         File JavaDoc file = new File JavaDoc(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 JavaDoc(cvss).start();
195         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
196         btnExport.push();
197         // no output in output tab now
198
// oto.waitText("Diff Patch finished");
199
Thread.sleep(3000);
200         cvss.stop();
201         Thread.sleep(2000);
202         //test file existence
203
assertTrue("Diff Patch file wasn't created!", file.isFile());
204         BufferedReader JavaDoc br = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
205         String JavaDoc 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 JavaDoc {
216         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
217
PseudoCvsServer cvss;
218         InputStream JavaDoc in;
219         //OutputOperator oo;
220
OutputTabOperator oto;
221         org.openide.nodes.Node nodeIDE;
222         String JavaDoc 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 JavaDoc(cvss).start();
238         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
239         node.performPopupAction("CVS|Diff...");
240         
241         // oto.waitText("Diffing \"Main.java\" finished");
242
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         //verify next button
251
DiffOperator diffOp = new DiffOperator("Main.java");
252         //
253
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             //verify previous button
265
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 JavaDoc e) {
275             System.out.println("Problem with buttons of differences");
276         }
277         
278         //refresh button
279
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 JavaDoc(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         //update button
291
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 JavaDoc(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         //commit button
303
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.closeWindow();
311
eo.closeAllDocuments();
312         TestKit.deleteRecursively(cacheFolder);
313     }
314     
315     public void removeAllData() throws Exception JavaDoc {
316         TestKit.closeProject(projectName);
317         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
318     }
319 }
320
Popular Tags