KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.test.cvsmodule;
21
22 import java.io.File JavaDoc;
23 import java.io.InputStream JavaDoc;
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 /**
51  *
52  * @author peter
53  */

54 public class BranchTest extends JellyTestCase {
55     
56     String JavaDoc os_name;
57     static String JavaDoc sessionCVSroot;
58     boolean unix = false;
59     final String JavaDoc projectName = "ForImport";
60     final String JavaDoc pathToMain = "forimport|Main.java";
61     final String JavaDoc PROTOCOL_FOLDER = "protocol";
62     Operator.DefaultStringComparator comOperator;
63     Operator.DefaultStringComparator oldOperator;
64     
65     /** Creates a new instance of BranchTest */
66     public BranchTest(String JavaDoc name) {
67         super(name);
68     }
69     
70     protected void setUp() throws Exception JavaDoc {
71         
72         os_name = System.getProperty("os.name");
73         //System.out.println(os_name);
74
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 JavaDoc[] args) {
87         // TODO code application logic here
88
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         //debug
100
//suite.addTest(new BranchTest("testOnNonVersioned"));
101
return suite;
102     }
103     
104     public void testCheckOutProject() throws Exception JavaDoc {
105         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 36000);
106
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 36000);
107
TestKit.closeProject(projectName);
108         String JavaDoc 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         //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
117
crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
118         //crso.setPassword("");
119
//crso.setPassword("test");
120

121         //prepare stream for successful authentification and run PseudoCVSServer
122
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
123         PseudoCvsServer cvss = new PseudoCvsServer(in);
124         new Thread JavaDoc(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         //second step of checkoutwizard
140
//2nd step of CheckOutWizard
141

142         File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
143
File JavaDoc work = new File JavaDoc(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()); // NOI18N
152

153         //Pseudo CVS server for finishing check out wizard
154
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
155         cvss = new PseudoCvsServer(in);
156         new Thread JavaDoc(cvss).start();
157         CVSroot = cvss.getCvsRoot();
158         //cvss.ignoreProbe();
159

160         //crso.setCVSRoot(CVSroot);
161
//combo.setSelectedItem(CVSroot);
162
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         //create new elements for testing
180
TestKit.createNewElements(projectName);
181         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
182     }
183     
184     public void removeAllData() throws Exception JavaDoc {
185         TestKit.closeProject(projectName);
186         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
187     }
188     
189     public void testBranchDialogUI() throws Exception JavaDoc {
190         
191         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
192
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
193
PseudoCvsServer cvss;
194         InputStream JavaDoc 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 JavaDoc(cvss).start();
199         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
200         //invoke Branch dialog on file node
201
Node node = new Node(new SourcePackagesNode(projectName), pathToMain);
202         
203         BranchOperator bo = BranchOperator.invoke(node);
204         BrowseTagsOperator browseTags = bo.browse();
205         
206         //Head node
207
browseTags.selectPath("Head");
208         //Tags node
209
browseTags.selectPath("Tags");
210         //Branches node
211
browseTags.selectPath("Branches");
212         //
213
browseTags.selectPath("Branches|MyBranch");
214         browseTags.selectPath("Tags|MyBranch_root");
215         cvss.stop();
216         //
217
//Ok button
218
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         //
239
bo.checkTagBeforeBranching(false);
240         assertFalse(bo.txtTagName().isEnabled());
241         //
242
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 JavaDoc {
249         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
250
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
251
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 JavaDoc 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 JavaDoc(cvss).start();
263         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
264         //invoke Branch dialog on file node
265

266         BrowseTagsOperator browseTags = sbo.browse();
267         //Head node
268
browseTags.selectPath("Head");
269         //Tags node
270
browseTags.selectPath("Tags");
271         //Branches node
272
browseTags.selectPath("Branches");
273         //
274
browseTags.selectPath("Branches|MyBranch");
275         browseTags.selectPath("Tags|MyBranch_root");
276         cvss.stop();
277         //
278
//Ok button
279
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 JavaDoc 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             //tf1.getFocus();
298

299             JButtonOperator btnBranch = new JButtonOperator(sbo, "Switch");
300             JButtonOperator btnHelp = new JButtonOperator(sbo, "Help");
301             JButtonOperator btnCancel = new JButtonOperator(sbo, "Cancel");
302         } catch (Exception JavaDoc 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         //check functionality of radiobutton selection
312
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 JavaDoc {
321         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
322
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
323
Node node = new Node(new SourcePackagesNode(projectName), pathToMain);
324         MergeChangesFromBranchOperator mcbo = MergeChangesFromBranchOperator.invoke(node);
325         mcbo.mergeFromBranch();
326         
327         //browse 1.
328
PseudoCvsServer cvss;
329         InputStream JavaDoc 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 JavaDoc(cvss).start();
334         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
335         
336         BrowseTagsOperator browseTags = mcbo.browseMergeFromBranch();
337         //Head node
338
browseTags.selectPath("Head");
339         //Tags node
340
browseTags.selectPath("Tags");
341         //Branches node
342
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         //browse 2.
356
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in");
357         cvss = new PseudoCvsServer(in);
358         new Thread JavaDoc(cvss).start();
359         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
360         
361         mcbo.checkMergeAfterTag(true);
362         browseTags = mcbo.browseMergeAfterTag();
363         //Head node
364
browseTags.selectPath("Head");
365         //Tags node
366
browseTags.selectPath("Tags");
367         //Branches node
368
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         //browse 3.
382
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "browse_tags_branches.in");
383         cvss = new PseudoCvsServer(in);
384         new Thread JavaDoc(cvss).start();
385         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
386         
387         mcbo.checkTagAfterMerge(true);
388         browseTags = mcbo.browseTagAfterMerge();
389         //Head node
390
browseTags.selectPath("Head");
391         //Tags node
392
browseTags.selectPath("Tags");
393         //Branches node
394
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         //functionality of button
418
//for radiobutton
419
mcbo.mergeFromTrunk();
420         assertFalse(mcbo.txtMergeFromBranch().isEnabled());
421         assertFalse(mcbo.btBrowseMergeFromBranch().isEnabled());
422         //
423
mcbo.mergeFromBranch();
424         assertTrue(mcbo.txtMergeFromBranch().isEnabled());
425         assertTrue(mcbo.btBrowseMergeFromBranch().isEnabled());
426         
427         //
428
mcbo.checkMergeAfterTag(false);
429         assertFalse(mcbo.txtMergeAfterTag().isEnabled());
430         assertFalse(mcbo.btBrowseMergeAfterTag().isEnabled());
431         //
432
mcbo.checkMergeAfterTag(true);
433         assertTrue(mcbo.txtMergeAfterTag().isEnabled());
434         assertTrue(mcbo.btBrowseMergeAfterTag().isEnabled());
435         
436         //
437
mcbo.checkTagAfterMerge(false);
438         assertFalse(mcbo.txtTagAfterMerge().isEnabled());
439         assertFalse(mcbo.btBrowseTagAfterMerge().isEnabled());
440         //
441
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 JavaDoc {
449         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
450
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
451
//delete fake versioning of file
452
//TestKit.unversionProject(file, projNonName);
453

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 JavaDoc e) {
459             tee = (TimeoutExpiredException) e;
460         }
461         assertNotNull(tee);
462         //
463
tee = null;
464         try {
465             Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java");
466             SwitchToBranchOperator sbo = SwitchToBranchOperator.invoke(node);
467         } catch (Exception JavaDoc e) {
468             tee = (TimeoutExpiredException) e;
469         }
470         assertNotNull(tee);
471         //
472
tee = null;
473         try {
474             Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java");
475             MergeChangesFromBranchOperator mcbo = MergeChangesFromBranchOperator.invoke(node);
476         } catch (Exception JavaDoc e) {
477             tee = (TimeoutExpiredException) e;
478         }
479         assertNotNull(tee);
480         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
481     }
482 }
483
484
485
Popular Tags