KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ShowAnnotationsAndSearchHistoryTest.java
22  *7
23  * Created on 18. prosinec 2006, 9:47
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.ListModel 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.SearchHistoryOperator;
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.JListOperator;
50 import org.netbeans.jemmy.operators.JProgressBarOperator;
51 import org.netbeans.jemmy.operators.Operator;
52 import org.netbeans.jemmy.operators.Operator;
53 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
54 import org.netbeans.junit.NbTestSuite;
55 import org.netbeans.junit.ide.ProjectSupport;
56
57 /**
58  *
59  * @author novakm
60  */

61 public class ShowAnnotationsAndSearchHistoryTest 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     /** Creates a new instance of ShowAnnotationsAndSearchHistoryTest */
71     public ShowAnnotationsAndSearchHistoryTest(String JavaDoc name) {
72         super(name);
73     }
74     
75     public static void main(String JavaDoc[] args) {
76         // TODO code application logic here
77
TestRunner.run(suite());
78     }
79     
80     protected void setUp() throws Exception JavaDoc {
81         os_name = System.getProperty("os.name");
82         //System.out.println(os_name);
83
System.out.println("### " + getName() + " ###");
84     }
85     
86     public static NbTestSuite suite() {
87         NbTestSuite suite = new NbTestSuite();
88         suite.addTest(new ShowAnnotationsAndSearchHistoryTest("testCheckOutProject"));
89         //suite.addTest(new ShowAnnotationsAndSearchHistoryTest("testSearchHistory"));
90
suite.addTest(new ShowAnnotationsAndSearchHistoryTest("testShowAnnotations"));
91         suite.addTest(new ShowAnnotationsAndSearchHistoryTest("removeAllData"));
92         return suite;
93     }
94     
95     public void testCheckOutProject() throws Exception JavaDoc {
96         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
97
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
98
TestKit.closeProject(projectName);
99         comOperator = new Operator.DefaultStringComparator(true, true);
100         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
101         Operator.setDefaultStringComparator(comOperator);
102         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
103         Operator.setDefaultStringComparator(oldOperator);
104         CVSRootStepOperator crso = new CVSRootStepOperator();
105         crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
106         //prepare stream for successful authentification and run PseudoCVSServer
107
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
108         PseudoCvsServer cvss = new PseudoCvsServer(in);
109         new Thread JavaDoc(cvss).start();
110         cvss.ignoreProbe();
111         String JavaDoc CVSroot = cvss.getCvsRoot();
112         sessionCVSroot = CVSroot;
113         crso.setCVSRoot(CVSroot);
114         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
115         crso.next();
116         try {
117             JProgressBarOperator progress = new JProgressBarOperator(crso);
118             JButtonOperator btnStop = new JButtonOperator(crso);
119         } catch (TimeoutExpiredException e) {
120             throw e;
121         }
122         //2nd step of CheckOutWizard
123
File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
124
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
125         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
126         tmp.mkdirs();
127         work.mkdirs();
128         tmp.deleteOnExit();
129         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
130         cvss.stop();
131         in.close();
132         moduleCheck.setModule("ForImport");
133         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
134
//Pseudo CVS server for finishing check out wizard
135
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
136         cvss = new PseudoCvsServer(in);
137         new Thread JavaDoc(cvss).start();
138         CVSroot = cvss.getCvsRoot();
139         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
140         cwo.finish();
141         OutputOperator oo = OutputOperator.invoke();
142         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
143         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
144         oto.waitText("Checking out finished");
145         cvss.stop();
146         in.close();
147         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
148         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
149         open.push();
150         
151         ProjectSupport.waitScanFinished();
152         new QueueTool().waitEmpty(1000);
153         ProjectSupport.waitScanFinished();
154         
155         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
156     }
157     public void testShowAnnotations() throws Exception JavaDoc {
158         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
159
PseudoCvsServer cvss, cvss2;
160         InputStream JavaDoc in, in2;
161         //OutputOperator oo;
162
OutputTabOperator oto;
163         org.openide.nodes.Node nodeIDE;
164         String JavaDoc color, cvsRoot;
165         
166         TestKit.deleteRecursively(cacheFolder);
167         
168         //oo = OutputOperator.invoke();
169
oto = new OutputTabOperator(sessionCVSroot);
170         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
171         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_annotation.in");
172         cvss = new PseudoCvsServer(in);
173         new Thread JavaDoc(cvss).start();
174         
175         in2 = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_annotation_1.in");
176         cvss2 = new PseudoCvsServer(in2);
177         new Thread JavaDoc(cvss2).start();
178         
179         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot() + "," + cvss2.getCvsRoot());
180         Node nodeMain = new Node(new SourcePackagesNode("ForImport"), "forimport|Main.java");
181         oto = new OutputTabOperator(sessionCVSroot);
182         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
183         nodeMain.performPopupAction("CVS|Show Annotations");
184         Thread.sleep(1000);
185         oto.waitText("Loading Annotations finished");
186         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
187         cvss.stop();
188         cvss2.stop();
189     }
190     
191     public void testSearchHistory() throws Exception JavaDoc {
192         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
193
PseudoCvsServer cvss, cvss2;
194         InputStream JavaDoc in, in2;
195         //OutputOperator oo;
196
OutputTabOperator oto;
197         org.openide.nodes.Node nodeIDE;
198         String JavaDoc color, cvsRoot;
199         TestKit.deleteRecursively(cacheFolder);
200         oto = new OutputTabOperator(sessionCVSroot);
201         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
202         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "search_history.in");
203         cvss = new PseudoCvsServer(in);
204         new Thread JavaDoc(cvss).start();
205         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
206         Node nodeMain = new Node(new SourcePackagesNode("ForImport"), "forimport|Main.java");
207         //nodeMain.performPopupAction("CVS|Search History...");
208
SearchHistoryOperator sho = SearchHistoryOperator.invoke(nodeMain);
209         oto.waitText("Searching History finished");
210         Thread.sleep(1000);
211         cvss.stop();
212         oto.clear();
213         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "search_history_1.in");
214         cvss = new PseudoCvsServer(in);
215         new Thread JavaDoc(cvss).start();
216         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
217         sho.setUsername("test");
218         sho.setFrom("1.1");
219         sho.setTo("1.1");
220         sho.btSearch().push();
221         oto.waitText("Searching History started");
222         Thread.sleep(1000);
223         cvss.stop();
224         JListOperator list = sho.lstHistory();
225         ListModel JavaDoc model = list.getModel();
226         assertEquals("Wrong result count", 2, model.getSize());
227         assertTrue("Revision \"1.1\" is missing", model.getElementAt(1).toString().indexOf("1.1") > 0);
228         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
229     }
230     
231     public void removeAllData() throws Exception JavaDoc {
232         TestKit.closeProject(projectName);
233         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
234     }
235 }
236
Popular Tags