KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CommittingCvs11Test.java
22  *
23  * Created on 08 March 2006, 11:03
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.File JavaDoc;
32 import java.io.InputStream JavaDoc;
33 import javax.swing.table.TableModel JavaDoc;
34 import junit.textui.TestRunner;
35 import org.netbeans.jellytools.EditorOperator;
36 import org.netbeans.jellytools.JellyTestCase;
37 import org.netbeans.jellytools.NbDialogOperator;
38 import org.netbeans.jellytools.OutputOperator;
39 import org.netbeans.jellytools.OutputTabOperator;
40 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
41 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
42 import org.netbeans.jellytools.modules.javacvs.CommitOperator;
43 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
44 import org.netbeans.jellytools.modules.javacvs.VersioningOperator;
45 import org.netbeans.jellytools.nodes.Node;
46 import org.netbeans.jellytools.nodes.SourcePackagesNode;
47 import org.netbeans.jemmy.JemmyProperties;
48 import org.netbeans.jemmy.QueueTool;
49 import org.netbeans.jemmy.TimeoutExpiredException;
50 import org.netbeans.jemmy.operators.JButtonOperator;
51 import org.netbeans.jemmy.operators.JProgressBarOperator;
52 import org.netbeans.jemmy.operators.JTableOperator;
53 import org.netbeans.jemmy.operators.Operator;
54 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
55 import org.netbeans.junit.NbTestSuite;
56 import org.netbeans.junit.ide.ProjectSupport;
57 /**
58  *
59  * @author peter
60  */

61 public class CommittingCvs11Test extends JellyTestCase {
62
63     String JavaDoc os_name;
64     static String JavaDoc sessionCVSroot;
65     final String JavaDoc projectName = "ForImport";
66     final String JavaDoc pathToMain = "forimport|Main.java";
67     static File JavaDoc cacheFolder;
68     String JavaDoc PROTOCOL_FOLDER = "protocol";
69     Operator.DefaultStringComparator comOperator;
70     Operator.DefaultStringComparator oldOperator;
71
72     /**
73      * Creates a new instance of CommittingCvs11Test
74      */

75     public CommittingCvs11Test(String JavaDoc name) {
76         super(name);
77     }
78
79     public static void main(String JavaDoc[] args) {
80         // TODO code application logic here
81
TestRunner.run(suite());
82     }
83     
84     protected void setUp() throws Exception JavaDoc {
85         os_name = System.getProperty("os.name");
86         //System.out.println(os_name);
87
System.out.println("### " + getName() + " ###");
88     }
89
90     public static NbTestSuite suite() {
91         NbTestSuite suite = new NbTestSuite();
92         suite.addTest(new CommittingCvs11Test("testCheckOutProject"));
93         suite.addTest(new CommittingCvs11Test("testCommitModified"));
94         suite.addTest(new CommittingCvs11Test("removeAllData"));
95         return suite;
96     }
97
98     public void testCheckOutProject() throws Exception JavaDoc {
99         PROTOCOL_FOLDER = "protocol";
100         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
101
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
102
TestKit.closeProject(projectName);
103         comOperator = new Operator.DefaultStringComparator(true, true);
104         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
105         Operator.setDefaultStringComparator(comOperator);
106         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
107         Operator.setDefaultStringComparator(oldOperator);
108         CVSRootStepOperator crso = new CVSRootStepOperator();
109         //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
110
crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
111         //crso.setPassword("");
112
//crso.setPassword("test");
113

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

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

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

155         //crso.setCVSRoot(CVSroot);
156
//combo.setSelectedItem(CVSroot);
157
System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
158         cwo.finish();
159         
160         OutputOperator oo = OutputOperator.invoke();
161         //System.out.println(CVSroot);
162

163         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
164         oto.waitText("Checking out finished");
165         cvss.stop();
166         in.close();
167         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
168         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
169         open.push();
170         
171         ProjectSupport.waitScanFinished();
172         new QueueTool().waitEmpty(1000);
173         ProjectSupport.waitScanFinished();
174         
175         //create new elements for testing
176
TestKit.createNewElementsCommitCvs11(projectName);
177         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
178     }
179
180     public void testCommitModified() throws Exception JavaDoc {
181         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
182
PseudoCvsServer cvss, cvss2, cvss3, cvss4;
183         InputStream JavaDoc in, in2, in3, in4;
184         CommitOperator co;
185         String JavaDoc CVSroot, color;
186         JTableOperator table;
187         OutputOperator oo;
188         OutputTabOperator oto;
189         VersioningOperator vo;
190         String JavaDoc[] expected;
191         String JavaDoc[] actual;
192         String JavaDoc allCVSRoots;
193         org.openide.nodes.Node nodeIDE;
194         PROTOCOL_FOLDER = "protocol" + File.separator + "cvs_committing_cvs11";
195         
196         Node packNode = new Node(new SourcePackagesNode("ForImport"), "xx");
197
198         co = CommitOperator.invoke(packNode);
199         Thread.sleep(1000);
200         table = co.tabFiles();
201         TableModel JavaDoc model = table.getModel();
202         
203         expected = new String JavaDoc[] {"NewClass.java", "NewClass2.java", "NewClass3.java", "NewClass4.java"};
204         actual = new String JavaDoc[model.getRowCount()];
205         for (int i = 0; i < actual.length; i++) {
206             actual[i] = model.getValueAt(i, 0).toString();
207         }
208         int result = TestKit.compareThem(expected, actual, false);
209         assertEquals("Wrong records displayed in dialog", 4, result);
210         co.setCommitMessage("Initial commit message");
211         
212         oo = OutputOperator.invoke();
213         oto = oo.getOutputTab(sessionCVSroot);
214         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
215         oto.clear();
216         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke.in");
217         cvss = new PseudoCvsServer(in);
218         new Thread JavaDoc(cvss).start();
219         allCVSRoots = cvss.getCvsRoot() + ",";
220
221         in2 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_add_4.in");
222         cvss2 = new PseudoCvsServer(in2);
223         new Thread JavaDoc(cvss2).start();
224         allCVSRoots = allCVSRoots + cvss2.getCvsRoot() + ",";
225         
226         in3 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_commit_4.in");
227         cvss3 = new PseudoCvsServer(in3);
228         new Thread JavaDoc(cvss3).start();
229         allCVSRoots = allCVSRoots + cvss3.getCvsRoot()+ ",";
230         
231         in4 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_final.in");
232         cvss4 = new PseudoCvsServer(in4);
233         new Thread JavaDoc(cvss4).start();
234         allCVSRoots = allCVSRoots + cvss4.getCvsRoot();
235         
236         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", allCVSRoots);
237         co.commit();
238         oto.waitText("Committing");
239         oto.waitText("finished");
240                
241         cvss.stop();
242         cvss2.stop();
243         cvss3.stop();
244         cvss4.stop();
245         //modify files
246
Node node = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java");
247         node.performPopupAction("Open");
248         EditorOperator eo = new EditorOperator("NewClass.java");
249         eo.deleteLine(2);
250         eo.insert(" a", 3, 4);
251         eo.save();
252         node = new Node(new SourcePackagesNode(projectName), "xx|NewClass2.java");
253         node.performPopupAction("Open");
254         eo = new EditorOperator("NewClass2.java");
255         eo.deleteLine(2);
256         eo.insert(" a", 3, 4);
257         eo.save();
258         node = new Node(new SourcePackagesNode(projectName), "xx|NewClass3.java");
259         node.performPopupAction("Open");
260         eo = new EditorOperator("NewClass3.java");
261         eo.deleteLine(2);
262         eo.insert(" a", 3, 4);
263         eo.save();
264         node = new Node(new SourcePackagesNode(projectName), "xx|NewClass4.java");
265         node.performPopupAction("Open");
266         eo = new EditorOperator("NewClass4.java");
267         eo.deleteLine(2);
268         eo.insert(" a", 3, 4);
269         eo.save();
270         //commit changes
271

272         //
273
oto = new OutputTabOperator(sessionCVSroot);
274         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
275         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_commit_4_modified_show_changes.in");
276         cvss = new PseudoCvsServer(in);
277         new Thread JavaDoc(cvss).start();
278         CVSroot = cvss.getCvsRoot();
279         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
280         packNode.performPopupAction("CVS|Show Changes");
281         Thread.sleep(1000);
282         oto.waitText("Refreshing");
283         oto.waitText("finished");
284         cvss.stop();
285         
286         //oo = OutputOperator.invoke();
287
oto = new OutputTabOperator(sessionCVSroot);
288         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
289         oto.clear();
290         co = CommitOperator.invoke(packNode);
291         //
292
Thread.sleep(1000);
293         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_commit_4_modified_wrong.in");
294         cvss = new PseudoCvsServer(in);
295         new Thread JavaDoc(cvss).start();
296         
297         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
298         co.commit();
299                
300         oto.waitText("Committing");
301         oto.waitText("finished");
302         cvss.stop();
303         cvss2.stop();
304
305         //
306
Node nodeClass = new Node(new SourcePackagesNode("ForImport"), "xx|NewClass.java");
307         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
308         //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
309
assertNull("Wrong color of node!!!", nodeIDE.getHtmlDisplayName());
310
311         nodeClass = new Node(new SourcePackagesNode("ForImport"), "xx|NewClass2.java");
312         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
313         //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
314
assertNull("Wrong color of node!!!", nodeIDE.getHtmlDisplayName());
315
316         nodeClass = new Node(new SourcePackagesNode("ForImport"), "xx|NewClass3.java");
317         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
318         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
319         assertEquals("Wrong color of node!!!", TestKit.MODIFIED_COLOR, color);
320
321         nodeClass = new Node(new SourcePackagesNode("ForImport"), "xx|NewClass4.java");
322         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
323         //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
324
assertNull("Wrong color of node!!!", nodeIDE.getHtmlDisplayName());
325
326         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
327     }
328
329     public void removeAllData() throws Exception JavaDoc {
330         TestKit.closeProject(projectName);
331         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
332     }
333 }
334
Popular Tags