KickJava   Java API By Example, From Geeks To Geeks.

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


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 CommittingCvs12Test 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 CommittingCvs12Test(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 CommittingCvs12Test("testCheckOutProject"));
93         suite.addTest(new CommittingCvs12Test("testCommitModifiedCvs12"));
94         suite.addTest(new CommittingCvs12Test("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.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
165         oto.waitText("Checking out finished");
166         cvss.stop();
167         in.close();
168         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
169         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
170         open.push();
171         
172         ProjectSupport.waitScanFinished();
173         new QueueTool().waitEmpty(1000);
174         ProjectSupport.waitScanFinished();
175         
176         //create new elements for testing
177
TestKit.createNewElementsCommitCvs12(projectName);
178         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
179     }
180
181     public void testCommitModifiedCvs12() throws Exception JavaDoc {
182         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
183
PseudoCvsServer cvss, cvss2, cvss3, cvss4;
184         InputStream JavaDoc in, in2, in3, in4;
185         CommitOperator co;
186         String JavaDoc CVSroot, color;
187         JTableOperator table;
188         OutputOperator oo;
189         OutputTabOperator oto;
190         VersioningOperator vo;
191         String JavaDoc[] expected;
192         String JavaDoc[] actual;
193         String JavaDoc allCVSRoots;
194         org.openide.nodes.Node nodeIDE;
195         PROTOCOL_FOLDER = "protocol" + File.separator + "cvs_committing_cvs12";
196
197         Node packNode = new SourcePackagesNode("ForImport");
198
199         co = CommitOperator.invoke(packNode);
200         Thread.sleep(1000);
201         table = co.tabFiles();
202         TableModel JavaDoc model = table.getModel();
203         
204         expected = new String JavaDoc[] {"NewClass.java", "NewClass2.java", "NewClass.java", "NewClass2.java"};
205         table = co.tabFiles();
206         model = table.getModel();
207         actual = new String JavaDoc[model.getRowCount()];
208         for (int i = 0; i < actual.length; i++) {
209             actual[i] = model.getValueAt(i, 0).toString();
210         }
211         int result = TestKit.compareThem(expected, actual, false);
212         assertEquals("Wrong records displayed in dialog", 4, result);
213         co.setCommitMessage("Initial commit message");
214         
215         oo = OutputOperator.invoke();
216         oto = oo.getOutputTab(sessionCVSroot);
217         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
218         oto.clear();
219         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke.in");
220         cvss = new PseudoCvsServer(in);
221         new Thread JavaDoc(cvss).start();
222         allCVSRoots = cvss.getCvsRoot() + ",";
223      
224         in2 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_add_4.in");
225         cvss2 = new PseudoCvsServer(in2);
226         new Thread JavaDoc(cvss2).start();
227         allCVSRoots = allCVSRoots + cvss2.getCvsRoot() + ",";
228         
229         in3 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_commit_4.in");
230         cvss3 = new PseudoCvsServer(in3);
231         new Thread JavaDoc(cvss3).start();
232         allCVSRoots = allCVSRoots + cvss3.getCvsRoot() + ",";
233         
234         in4 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_final.in");
235         cvss4 = new PseudoCvsServer(in4);
236         new Thread JavaDoc(cvss4).start();
237         allCVSRoots = allCVSRoots + cvss4.getCvsRoot();
238         
239         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", allCVSRoots);
240         co.commit();
241         oto.waitText("Committing \"src\" finished");
242         
243         cvss.stop();
244         cvss2.stop();
245         cvss3.stop();
246         cvss4.stop();
247         
248         //modify files
249
Node node = new Node(new SourcePackagesNode(projectName), "aa|NewClass.java");
250         node.performPopupAction("Open");
251         EditorOperator eo = new EditorOperator("NewClass.java");
252         eo.deleteLine(2);
253         eo.insert(" a", 3, 4);
254         eo.save();
255         node = new Node(new SourcePackagesNode(projectName), "aa|NewClass2.java");
256         node.performPopupAction("Open");
257         eo = new EditorOperator("NewClass2.java");
258         eo.deleteLine(2);
259         eo.insert(" a", 3, 4);
260         eo.save();
261         node = new Node(new SourcePackagesNode(projectName), "bb|NewClass.java");
262         node.performPopupAction("Open");
263         eo = new EditorOperator("NewClass.java");
264         eo.deleteLine(2);
265         eo.insert(" a", 3, 4);
266         eo.save();
267         node = new Node(new SourcePackagesNode(projectName), "bb|NewClass2.java");
268         node.performPopupAction("Open");
269         eo = new EditorOperator("NewClass2.java");
270         eo.deleteLine(2);
271         eo.insert(" a", 3, 4);
272         eo.save();
273         
274         //
275
oto = new OutputTabOperator(sessionCVSroot);
276         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
277         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "commit_invoke_commit_4_modified_show_changes.in");
278         cvss = new PseudoCvsServer(in);
279         new Thread JavaDoc(cvss).start();
280         CVSroot = cvss.getCvsRoot();
281         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
282         packNode.performPopupAction("CVS|Show Changes");
283         Thread.sleep(1000);
284         oto.waitText("Refreshing");
285         oto.waitText("finished");
286         cvss.stop();
287         
288         oo = OutputOperator.invoke();
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 \"src\" finished");
301         cvss.stop();
302         cvss2.stop();
303
304         //
305
Node nodeClass = new Node(new SourcePackagesNode("ForImport"), "aa|NewClass.java");
306         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
307         //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
308
assertNull("Wrong color of node!!!", nodeIDE.getHtmlDisplayName());
309
310         nodeClass = new Node(new SourcePackagesNode("ForImport"), "aa|NewClass2.java");
311         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
312         //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
313
assertNull("Wrong color of node!!!", nodeIDE.getHtmlDisplayName());
314
315         nodeClass = new Node(new SourcePackagesNode("ForImport"), "bb|NewClass.java");
316         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
317         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
318         assertEquals("Wrong color of node!!!", TestKit.MODIFIED_COLOR, color);
319
320         nodeClass = new Node(new SourcePackagesNode("ForImport"), "bb|NewClass2.java");
321         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
322         //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
323
assertNull("Wrong color of node!!!", nodeIDE.getHtmlDisplayName());
324
325         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
326     }
327       
328     public void removeAllData() throws Exception JavaDoc {
329         TestKit.closeProject(projectName);
330         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
331     }
332 }
333
Popular Tags