KickJava   Java API By Example, From Geeks To Geeks.

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


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

61 public class IgnoreUnignoreTest extends JellyTestCase {
62     String JavaDoc os_name;
63     static String JavaDoc sessionCVSroot;
64     final String JavaDoc projectName = "ForImport";
65     final String JavaDoc pathToMain = "forimport|Main.java";
66     final String JavaDoc PROTOCOL_FOLDER = "protocol";
67     static File JavaDoc cacheFolder;
68     Operator.DefaultStringComparator comOperator;
69     Operator.DefaultStringComparator oldOperator;
70     
71     /** Creates a new instance of ignoreUnignoreFileTest */
72     public IgnoreUnignoreTest(String JavaDoc name) {
73         super(name);
74     }
75     
76     public static void main(String JavaDoc[] args) {
77         // TODO code application logic here
78
TestRunner.run(suite());
79     }
80     
81     protected void setUp() throws Exception JavaDoc {
82         os_name = System.getProperty("os.name");
83         //System.out.println(os_name);
84
System.out.println("### " + getName() + " ###");
85     }
86     
87     public static NbTestSuite suite() {
88         NbTestSuite suite = new NbTestSuite();
89         suite.addTest(new IgnoreUnignoreTest("testCheckOutProject"));
90         suite.addTest(new IgnoreUnignoreTest("testIgnoreUnignoreFile"));
91         suite.addTest(new IgnoreUnignoreTest("testIgnoreUnignoreGuiForm"));
92         suite.addTest(new IgnoreUnignoreTest("removeAllData"));
93         return suite;
94     }
95     
96     public void testCheckOutProject() throws Exception JavaDoc {
97         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
98
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
99
TestKit.closeProject(projectName);
100         comOperator = new Operator.DefaultStringComparator(true, true);
101         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
102         Operator.setDefaultStringComparator(comOperator);
103         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
104         Operator.setDefaultStringComparator(oldOperator);
105         CVSRootStepOperator crso = new CVSRootStepOperator();
106         crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
107         //prepare stream for successful authentification and run PseudoCVSServer
108
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
109         PseudoCvsServer cvss = new PseudoCvsServer(in);
110         new Thread JavaDoc(cvss).start();
111         cvss.ignoreProbe();
112         String JavaDoc CVSroot = cvss.getCvsRoot();
113         sessionCVSroot = CVSroot;
114         crso.setCVSRoot(CVSroot);
115         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
116         crso.next();
117         try {
118             JProgressBarOperator progress = new JProgressBarOperator(crso);
119             JButtonOperator btnStop = new JButtonOperator(crso);
120         } catch (TimeoutExpiredException e) {
121             throw e;
122         }
123         //second step of checkoutwizard
124
//2nd step of CheckOutWizard
125
File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
126
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
127         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
128         tmp.mkdirs();
129         work.mkdirs();
130         tmp.deleteOnExit();
131         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
132         cvss.stop();
133         in.close();
134         moduleCheck.setModule("ForImport");
135         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
136
//Pseudo CVS server for finishing check out wizard
137
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
138         cvss = new PseudoCvsServer(in);
139         new Thread JavaDoc(cvss).start();
140         CVSroot = cvss.getCvsRoot();
141         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
142         cwo.finish();
143         OutputOperator oo = OutputOperator.invoke();
144         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
145         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
146         oto.waitText("Checking out finished");
147         cvss.stop();
148         in.close();
149         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
150         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
151         open.push();
152         
153         ProjectSupport.waitScanFinished();
154         new QueueTool().waitEmpty(1000);
155         ProjectSupport.waitScanFinished();
156         
157         //create new elements for testing
158
TestKit.createNewElements(projectName);
159         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
160     }
161     
162     public void testIgnoreUnignoreFile() throws Exception JavaDoc{
163         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
164
VersioningOperator vo;
165         //OutputOperator oo;
166
OutputTabOperator oto;
167         InputStream JavaDoc in;
168         PseudoCvsServer cvss;
169         String JavaDoc CVSroot;
170         JTableOperator table;
171         org.openide.nodes.Node nodeIDE;
172         String JavaDoc color;
173         
174         Node nodeClass = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java");
175         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
176         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
177         assertEquals("Wrong color for new file", TestKit.NEW_COLOR, color);
178         
179         oto = new OutputTabOperator(sessionCVSroot);
180         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
181         oto.clear();
182         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_for_file");
183         cvss = new PseudoCvsServer(in);
184         new Thread JavaDoc(cvss).start();
185         CVSroot = cvss.getCvsRoot();
186         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
187         nodeClass.performPopupAction("CVS|Show Changes");
188         Thread.sleep(1000);
189         vo = VersioningOperator.invoke();
190         table = vo.tabFiles();
191         //System.out.println(""+table);
192
oto.waitText("Refreshing CVS Status finished");
193         Thread.sleep(1000);
194         assertEquals("Wrong row count of table.", 1, table.getRowCount());
195         assertEquals("Wrong file listed in table.", "NewClass.java", table.getValueAt(0, 0).toString());
196         cvss.stop();
197         
198         //ignore java file
199
oto = new OutputTabOperator(sessionCVSroot);
200         oto.clear();
201         nodeClass.performPopupAction("CVS|Ignore");
202         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_for_file");
203         cvss = new PseudoCvsServer(in);
204         new Thread JavaDoc(cvss).start();
205         CVSroot = cvss.getCvsRoot();
206         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
207         
208         Thread.sleep(1000);
209         assertEquals("File should not be listed in table", 0, table.getRowCount());
210         cvss.stop();
211         
212         nodeClass = new Node(new SourcePackagesNode(projectName), "xx|NewClass.java");
213         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
214         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
215         assertEquals("Wrong color for new file", TestKit.IGNORED_COLOR, color);
216         
217         //unignore java file
218
oto.clear();
219         nodeClass.performPopupAction("CVS|Unignore");
220         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_for_file");
221         cvss = new PseudoCvsServer(in);
222         new Thread JavaDoc(cvss).start();
223         CVSroot = cvss.getCvsRoot();
224         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
225         nodeClass.performPopupAction("CVS|Show Changes");
226         oto.waitText("Refreshing CVS Status finished");
227         Thread.sleep(1000);
228         assertEquals("File should not be listed in table", 1, table.getRowCount());
229         cvss.stop();
230         
231         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
232         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
233         assertEquals("Wrong color for new file", TestKit.NEW_COLOR, color);
234         
235         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
236     }
237     
238     public void testIgnoreUnignoreGuiForm() throws Exception JavaDoc{
239         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
240
VersioningOperator vo;
241         OutputTabOperator oto;
242         InputStream JavaDoc in;
243         PseudoCvsServer cvss;
244         String JavaDoc CVSroot;
245         JTableOperator table;
246         org.openide.nodes.Node nodeIDE;
247         String JavaDoc color;
248         Object JavaDoc[] expected;
249         Object JavaDoc[] actual;
250         
251         Node nodeFrame = new Node(new SourcePackagesNode(projectName), "xx|NewJFrame.java");
252         nodeIDE = (org.openide.nodes.Node) nodeFrame.getOpenideNode();
253         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
254         assertEquals("Wrong color for new file", TestKit.NEW_COLOR, color);
255         
256         //show changes stream for pseudocvsserver
257
oto = new OutputTabOperator(sessionCVSroot);
258         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
259         oto.clear();
260         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_for_jframe");
261         cvss = new PseudoCvsServer(in);
262         new Thread JavaDoc(cvss).start();
263         CVSroot = cvss.getCvsRoot();
264         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
265         nodeFrame.performPopupAction("CVS|Show Changes");
266         Thread.sleep(1000);
267         vo = VersioningOperator.invoke();
268         table = vo.tabFiles();
269         oto.waitText("Refreshing CVS Status finished");
270         Thread.sleep(1000);
271         cvss.stop();
272         TableModel JavaDoc model = table.getModel();
273         
274         expected = new String JavaDoc[] {"NewJFrame.form", "NewJFrame.java"};
275         actual = new String JavaDoc[model.getRowCount()];
276         for (int i = 0; i < actual.length; i++) {
277             actual[i] = model.getValueAt(i, 0).toString();
278         }
279         int result = TestKit.compareThem(expected, actual, false);
280         assertEquals("Wrong files in view", 2, result);
281         
282         //ignore
283
oto = new OutputTabOperator(sessionCVSroot);
284         oto.clear();
285         nodeFrame.performPopupAction("CVS|Ignore");
286         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_for_jframe");
287         cvss = new PseudoCvsServer(in);
288         new Thread JavaDoc(cvss).start();
289         CVSroot = cvss.getCvsRoot();
290         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
291         
292         Thread.sleep(1000);
293         assertEquals("File should not be listed in table", 0, table.getRowCount());
294         cvss.stop();
295         
296         nodeFrame = new Node(new SourcePackagesNode(projectName), "xx|NewJFrame.java");
297         nodeIDE = (org.openide.nodes.Node) nodeFrame.getOpenideNode();
298         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
299         assertEquals("Wrong color for new file", TestKit.IGNORED_COLOR, color);
300         
301         //unignore
302
oto = new OutputTabOperator(sessionCVSroot);
303         oto.clear();
304         nodeFrame.performPopupAction("CVS|Unignore");
305         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_for_jframe");
306         cvss = new PseudoCvsServer(in);
307         new Thread JavaDoc(cvss).start();
308         CVSroot = cvss.getCvsRoot();
309         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
310         nodeFrame.performPopupAction("CVS|Show Changes");
311         oto.waitText("Refreshing CVS Status finished");
312         Thread.sleep(1000);
313         assertEquals("File should not be listed in table", 2, table.getRowCount());
314         cvss.stop();
315         
316         nodeIDE = (org.openide.nodes.Node) nodeFrame.getOpenideNode();
317         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
318         assertEquals("Wrong color for new file", TestKit.NEW_COLOR, color);
319         
320         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
321     }
322     
323     public void removeAllData() throws Exception JavaDoc {
324         TestKit.closeProject(projectName);
325         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
326     }
327 }
328
Popular Tags