KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import junit.textui.TestRunner;
26 import org.netbeans.jellytools.EditorOperator;
27 import org.netbeans.jellytools.JellyTestCase;
28 import org.netbeans.jellytools.NbDialogOperator;
29 import org.netbeans.jellytools.OutputOperator;
30 import org.netbeans.jellytools.OutputTabOperator;
31 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
32 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
33 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
34 import org.netbeans.jellytools.modules.javacvs.TagOperator;
35 import org.netbeans.jellytools.nodes.Node;
36 import org.netbeans.jellytools.nodes.SourcePackagesNode;
37 import org.netbeans.jemmy.JemmyProperties;
38 import org.netbeans.jemmy.QueueTool;
39 import org.netbeans.jemmy.TimeoutExpiredException;
40 import org.netbeans.jemmy.operators.JButtonOperator;
41 import org.netbeans.jemmy.operators.JProgressBarOperator;
42 import org.netbeans.jemmy.operators.Operator;
43 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
44 import org.netbeans.junit.NbTestSuite;
45 import org.netbeans.junit.ide.ProjectSupport;
46 /**
47  *
48  * @author peter
49  */

50 public class TagTest extends JellyTestCase {
51     
52     String JavaDoc os_name;
53     static String JavaDoc sessionCVSroot;
54     boolean unix = false;
55     final String JavaDoc projectName = "ForImport";
56     final String JavaDoc pathToMain = "forimport|Main.java";
57     final String JavaDoc PROTOCOL_FOLDER = "protocol";
58     Operator.DefaultStringComparator comOperator;
59     Operator.DefaultStringComparator oldOperator;
60     
61     /** Creates a new instance of TagTest */
62     public TagTest(String JavaDoc name) {
63         super(name);
64     }
65     
66     protected void setUp() throws Exception JavaDoc {
67         
68         os_name = System.getProperty("os.name");
69         //System.out.println(os_name);
70
System.out.println("### "+getName()+" ###");
71         
72     }
73     
74     protected boolean isUnix() {
75         boolean unix = false;
76         if (os_name.indexOf("Windows") == -1) {
77             unix = true;
78         }
79         return unix;
80     }
81     
82     public static void main(String JavaDoc[] args) {
83         // TODO code application logic here
84
TestRunner.run(suite());
85     }
86     
87     public static NbTestSuite suite() {
88         NbTestSuite suite = new NbTestSuite();
89         suite.addTest(new TagTest("testCheckOutProject"));
90         suite.addTest(new TagTest("testTagDialogUI"));
91         suite.addTest(new TagTest("testCreateNewTag"));
92         suite.addTest(new TagTest("testCreateTagOnModified"));
93         suite.addTest(new TagTest("testOnNonVersioned"));
94         suite.addTest(new TagTest("removeAllData"));
95         //debug
96
//suite.addTest(new TagTest("testOnNonVersioned"));
97
return suite;
98     }
99     
100     public void testCheckOutProject() throws Exception JavaDoc {
101         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 36000);
102
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 36000);
103
TestKit.closeProject(projectName);
104         OutputOperator oo = OutputOperator.invoke();
105         comOperator = new Operator.DefaultStringComparator(true, true);
106         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
107         Operator.setDefaultStringComparator(comOperator);
108         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
109         Operator.setDefaultStringComparator(oldOperator);
110         CVSRootStepOperator crso = new CVSRootStepOperator();
111         //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
112
crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
113         //crso.setPassword("");
114
//crso.setPassword("test");
115

116         //prepare stream for successful authentification and run PseudoCVSServer
117
//InputStream in = getClass().getResourceAsStream("authorized.in");
118
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
119         PseudoCvsServer cvss = new PseudoCvsServer(in);
120         new Thread JavaDoc(cvss).start();
121         cvss.ignoreProbe();
122         String JavaDoc CVSroot = cvss.getCvsRoot();
123         sessionCVSroot = CVSroot;
124         crso.setCVSRoot(CVSroot);
125         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
126         crso.next();
127               
128         try {
129            JProgressBarOperator progress = new JProgressBarOperator(crso);
130            JButtonOperator btnStop = new JButtonOperator(crso);
131         } catch (TimeoutExpiredException e) {
132             throw e;
133         }
134         
135         //second step of checkoutwizard
136
//2nd step of CheckOutWizard
137

138         File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
139
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
140         tmp.mkdirs();
141         work.mkdirs();
142         tmp.deleteOnExit();
143         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
144         cvss.stop();
145         in.close();
146         moduleCheck.setModule("ForImport");
147         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
148

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

156         //crso.setCVSRoot(CVSroot);
157
//combo.setSelectedItem(CVSroot);
158
System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
159         cwo.finish();
160         
161         
162         //System.out.println(CVSroot);
163
//sessionCVSroot = CVSroot;
164
OutputTabOperator oto = new OutputTabOperator(sessionCVSroot);
165         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
166         oto.waitText("Checking out finished");
167         cvss.stop();
168         in.close();
169         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
170         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
171         open.push();
172         
173         ProjectSupport.waitScanFinished();
174         new QueueTool().waitEmpty(1000);
175         ProjectSupport.waitScanFinished();
176         
177         //create new elements for testing
178
TestKit.createNewElements(projectName);
179         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
180     }
181     
182     public void testTagDialogUI() throws Exception JavaDoc {
183         Node node = new Node(new SourcePackagesNode(projectName), pathToMain);
184         TagOperator to = TagOperator.invoke(node);
185         to.setTagName("TagTest");
186         
187         //System.out.println("Error in dialog buttons - OK -> Tag, Help -> missing!!!");
188
JButtonOperator btnTag = new JButtonOperator(to, "Tag");
189         JButtonOperator btnHelp = new JButtonOperator(to, "Help");
190         JButtonOperator btnCancel = new JButtonOperator(to, "Cancel");
191         
192         to.checkAvoidTaggingLocallyModifiedFiles(false);
193         //
194
assertFalse(to.cbAvoidTaggingLocallyModifiedFiles().isSelected());
195         //
196
to.checkAvoidTaggingLocallyModifiedFiles(true);
197         assertTrue(to.cbAvoidTaggingLocallyModifiedFiles().isSelected());
198         //
199
to.checkMoveExistingTag(false);
200         assertFalse(to.cbMoveExistingTag().isSelected());
201         //
202
to.checkMoveExistingTag(true);
203         assertTrue(to.cbMoveExistingTag().isSelected());
204         to.cancel();
205     }
206     
207     public void testCreateNewTag() throws Exception JavaDoc {
208         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
209
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
210
PseudoCvsServer cvss;
211         InputStream JavaDoc in;
212         
213         Node node = new Node(new SourcePackagesNode(projectName), pathToMain);
214         TagOperator to = TagOperator.invoke(node);
215         to.setTagName("MyNewTag");
216         
217         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "create_new_tag.in");
218         cvss = new PseudoCvsServer(in);
219         new Thread JavaDoc(cvss).start();
220         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
221         JButtonOperator btnTag = new JButtonOperator(to, "Tag");
222         btnTag.push();
223         
224         //OutputOperator oo = OutputOperator.invoke();
225
OutputTabOperator oto = new OutputTabOperator(sessionCVSroot);
226         oto.waitText("Tagging \"Main.java\"... finished");
227         cvss.stop();
228         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
229     }
230     
231     public void testCreateTagOnModified() throws Exception JavaDoc {
232         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
233
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
234
PseudoCvsServer cvss;
235         InputStream JavaDoc in;
236         
237         Node node = new Node(new SourcePackagesNode(projectName), pathToMain);
238         node.performPopupAction("Open");
239         EditorOperator eo = new EditorOperator("Main.java");
240         eo.insert("//Comment\n");
241         eo.save();
242         Thread.sleep(1000);
243         
244         TagOperator to = TagOperator.invoke(node);
245         to.setTagName("MyNewTag");
246         to.checkAvoidTaggingLocallyModifiedFiles(false);
247         
248         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "create_new_tag_on_modified.in");
249         cvss = new PseudoCvsServer(in);
250         new Thread JavaDoc(cvss).start();
251         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
252         JButtonOperator btnTag = new JButtonOperator(to, "Tag");
253         btnTag.push();
254         
255         //OutputOperator oo = OutputOperator.invoke();
256
OutputTabOperator oto = new OutputTabOperator(sessionCVSroot);
257         oto.waitText("cvs server: Main.java is locally modified");
258         oto.waitText("correct the above errors first!");
259         cvss.stop();
260         
261         NbDialogOperator nbd = new NbDialogOperator("Command Failed");
262         JButtonOperator btnOk = new JButtonOperator(nbd, "OK");
263         btnOk.push();
264         oto.waitText("Tagging \"Main.java\"... finished");
265         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
266     }
267     
268     public void testOnNonVersioned() throws Exception JavaDoc{
269         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
270
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
271
//delete fake versioning of file
272
//TestKit.unversionProject(file, projNonName);
273

274         TimeoutExpiredException tee = null;
275         try {
276             Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java");
277             TagOperator bo = TagOperator.invoke(node);
278         } catch (Exception JavaDoc e) {
279             tee = (TimeoutExpiredException) e;
280         }
281         assertNotNull(tee);
282         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
283     }
284     
285     public void removeAllData() throws Exception JavaDoc {
286         TestKit.closeProject(projectName);
287         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
288     }
289 }
290
Popular Tags