KickJava   Java API By Example, From Geeks To Geeks.

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


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  * VersioningButtonsTest.java
22  *
23  * Created on 18. prosinec 2006, 13:33
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 junit.textui.TestRunner;
34 import org.netbeans.jellytools.JellyTestCase;
35 import org.netbeans.jellytools.NbDialogOperator;
36 import org.netbeans.jellytools.OutputOperator;
37 import org.netbeans.jellytools.OutputTabOperator;
38 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
39 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
40 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
41 import org.netbeans.jellytools.modules.javacvs.VersioningOperator;
42 import org.netbeans.jellytools.nodes.Node;
43 import org.netbeans.jellytools.nodes.SourcePackagesNode;
44 import org.netbeans.jemmy.JemmyProperties;
45 import org.netbeans.jemmy.QueueTool;
46 import org.netbeans.jemmy.TimeoutExpiredException;
47 import org.netbeans.jemmy.operators.JButtonOperator;
48 import org.netbeans.jemmy.operators.JProgressBarOperator;
49 import org.netbeans.jemmy.operators.JTableOperator;
50 import org.netbeans.jemmy.operators.Operator;
51 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
52 import org.netbeans.junit.NbTestSuite;
53 import org.netbeans.junit.ide.ProjectSupport;
54
55 /**
56  *
57  * @author novakm
58  */

59 public class VersioningButtonsTest extends JellyTestCase {
60     String JavaDoc os_name;
61     static String JavaDoc sessionCVSroot;
62     final String JavaDoc projectName = "ForImport";
63     final String JavaDoc pathToMain = "forimport|Main.java";
64     final String JavaDoc PROTOCOL_FOLDER = "protocol";
65     static File JavaDoc cacheFolder;
66     Operator.DefaultStringComparator comOperator;
67     Operator.DefaultStringComparator oldOperator;
68     /** Creates a new instance of VersioningButtonsTest */
69     public VersioningButtonsTest(String JavaDoc name) {
70         super(name);
71     }
72     public static void main(String JavaDoc[] args) {
73         // TODO code application logic here
74
TestRunner.run(suite());
75     }
76     
77     protected void setUp() throws Exception JavaDoc {
78         os_name = System.getProperty("os.name");
79         //System.out.println(os_name);
80
System.out.println("### " + getName() + " ###");
81     }
82     
83     public static NbTestSuite suite() {
84         NbTestSuite suite = new NbTestSuite();
85         suite.addTest(new VersioningButtonsTest("testCheckOutProject"));
86         suite.addTest(new VersioningButtonsTest("testVersioningButtons"));
87         // suite.addTest(new VersioningButtonsTest("removeAllData"));
88
return suite;
89     }
90     public void testCheckOutProject() throws Exception JavaDoc {
91         TestKit.closeProject(projectName);
92         comOperator = new Operator.DefaultStringComparator(true, true);
93         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
94         Operator.setDefaultStringComparator(comOperator);
95         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
96         Operator.setDefaultStringComparator(oldOperator);
97         CVSRootStepOperator crso = new CVSRootStepOperator();
98         crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
99         //prepare stream for successful authentification and run PseudoCVSServer
100
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
101         PseudoCvsServer cvss = new PseudoCvsServer(in);
102         new Thread JavaDoc(cvss).start();
103         cvss.ignoreProbe();
104         String JavaDoc CVSroot = cvss.getCvsRoot();
105         sessionCVSroot = CVSroot;
106         crso.setCVSRoot(CVSroot);
107         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
108         crso.next();
109         try {
110             JProgressBarOperator progress = new JProgressBarOperator(crso);
111             JButtonOperator btnStop = new JButtonOperator(crso);
112         } catch (TimeoutExpiredException e) {
113             throw e;
114         }
115         //2nd step of CheckOutWizard
116
File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
117
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
118         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
119         tmp.mkdirs();
120         work.mkdirs();
121         tmp.deleteOnExit();
122         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
123         cvss.stop();
124         in.close();
125         moduleCheck.setModule("ForImport");
126         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
127
//Pseudo CVS server for finishing check out wizard
128
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
129         cvss = new PseudoCvsServer(in);
130         new Thread JavaDoc(cvss).start();
131         CVSroot = cvss.getCvsRoot();
132         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
133         cwo.finish();
134         OutputOperator oo = OutputOperator.invoke();
135         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
136         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
137         oto.waitText("Checking out finished");
138         cvss.stop();
139         in.close();
140         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
141         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
142         open.push();
143         
144         ProjectSupport.waitScanFinished();
145         new QueueTool().waitEmpty(1000);
146         ProjectSupport.waitScanFinished();
147         
148         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
149     }
150     
151     public void testVersioningButtons() throws Exception JavaDoc {
152         VersioningOperator vo;
153         //OutputOperator oo;
154
OutputTabOperator oto;
155         InputStream JavaDoc in;
156         PseudoCvsServer cvss;
157         String JavaDoc CVSroot;
158         JTableOperator table;
159         org.openide.nodes.Node nodeIDE;
160         String JavaDoc color;
161         
162         oto = new OutputTabOperator(sessionCVSroot);
163         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
164         
165         //perform Show Changes action on Main.java file
166
Node nodeMain = new Node(new SourcePackagesNode(projectName), pathToMain);
167         //oo = OutputOperator.invoke();
168
//System.out.println(sessionCVSroot);
169
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "versioning/show_changes_main.in");
170         cvss = new PseudoCvsServer(in);
171         new Thread JavaDoc(cvss).start();
172         CVSroot = cvss.getCvsRoot();
173         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
174         nodeMain.performPopupAction("CVS|Show Changes");
175         Thread.sleep(1000);
176         vo = VersioningOperator.invoke();
177         table = vo.tabFiles();
178         //System.out.println(""+table);
179
oto.waitText("Refreshing CVS Status finished");
180         Thread.sleep(1000);
181         assertEquals("Table should be empty", 1, table.getRowCount());
182         assertEquals("File should be [Remotely Modified]", "Remotely Modified", table.getValueAt(0, 1).toString());
183         cvss.stop();
184         //System.out.println("Show Changes is ok");
185

186         //push refresh button
187
//oo = OutputOperator.invoke();
188
//oto = oo.getOutputTab(sessionCVSroot);
189
oto = new OutputTabOperator(sessionCVSroot);
190         oto.clear();
191         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "versioning/refresh_main.in");
192         cvss = new PseudoCvsServer(in);
193         new Thread JavaDoc(cvss).start();
194         CVSroot = cvss.getCvsRoot();
195         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
196         //vo = VersioningOperator.invoke();
197
vo.refresh();
198         oto.waitText("Refreshing CVS Status finished");
199         Thread.sleep(1000);
200         table = vo.tabFiles();
201         assertEquals("Table should be empty", 0, table.getRowCount());
202         cvss.stop();
203         
204         //push Update all
205
//oo = OutputOperator.invoke();
206
oto = new OutputTabOperator(sessionCVSroot);
207         oto.clear();
208         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "versioning/refresh_main.in");
209         cvss = new PseudoCvsServer(in);
210         new Thread JavaDoc(cvss).start();
211         CVSroot = cvss.getCvsRoot();
212         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
213         //vo = VersioningOperator.invoke();
214
vo.update();
215         oto.waitText("Updating Sources finished");
216         Thread.sleep(1000);
217         cvss.stop();
218         
219         //push commit button
220
vo.commit();
221         Thread.sleep(1000);
222         
223         NbDialogOperator dialog = new NbDialogOperator("Comm");
224         JButtonOperator btnOk = new JButtonOperator(dialog, "OK");
225         btnOk.push();
226         
227         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
228     }
229     
230     public void removeAllData() throws Exception JavaDoc {
231         TestKit.closeProject(projectName);
232         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
233     }
234 }
235
Popular Tags