001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * ShowAnnotationsAndSearchHistoryTest.java
044: *7
045: * Created on 18. prosinec 2006, 9:47
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.test.cvsmodule;
052:
053: import java.io.File;
054: import java.io.InputStream;
055: import javax.swing.ListModel;
056: import junit.textui.TestRunner;
057: import org.netbeans.jellytools.JellyTestCase;
058: import org.netbeans.jellytools.NbDialogOperator;
059: import org.netbeans.jellytools.OutputOperator;
060: import org.netbeans.jellytools.OutputTabOperator;
061: import org.netbeans.jellytools.ProjectsTabOperator;
062: import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
063: import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
064: import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
065: import org.netbeans.jellytools.modules.javacvs.SearchHistoryOperator;
066: import org.netbeans.jellytools.nodes.Node;
067: import org.netbeans.jellytools.nodes.SourcePackagesNode;
068: import org.netbeans.jemmy.JemmyProperties;
069: import org.netbeans.jemmy.QueueTool;
070: import org.netbeans.jemmy.TimeoutExpiredException;
071: import org.netbeans.jemmy.operators.JButtonOperator;
072: import org.netbeans.jemmy.operators.JListOperator;
073: import org.netbeans.jemmy.operators.JProgressBarOperator;
074: import org.netbeans.jemmy.operators.Operator;
075: import org.netbeans.jemmy.operators.Operator;
076: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
077: import org.netbeans.junit.NbTestSuite;
078: import org.netbeans.junit.ide.ProjectSupport;
079:
080: /**
081: *
082: * @author novakm
083: */
084: public class ShowAnnotationsAndSearchHistoryTest extends JellyTestCase {
085: String os_name;
086: static String sessionCVSroot;
087: final String projectName = "ForImport";
088: final String pathToMain = "forimport|Main.java";
089: final String PROTOCOL_FOLDER = "protocol";
090: static File cacheFolder;
091: Operator.DefaultStringComparator comOperator;
092: Operator.DefaultStringComparator oldOperator;
093:
094: /** Creates a new instance of ShowAnnotationsAndSearchHistoryTest */
095: public ShowAnnotationsAndSearchHistoryTest(String name) {
096: super (name);
097: }
098:
099: public static void main(String[] args) {
100: // TODO code application logic here
101: TestRunner.run(suite());
102: }
103:
104: protected void setUp() throws Exception {
105: os_name = System.getProperty("os.name");
106: //System.out.println(os_name);
107: System.out.println("### " + getName() + " ###");
108: }
109:
110: public static NbTestSuite suite() {
111: NbTestSuite suite = new NbTestSuite();
112: suite.addTest(new ShowAnnotationsAndSearchHistoryTest(
113: "testCheckOutProject"));
114: //suite.addTest(new ShowAnnotationsAndSearchHistoryTest("testSearchHistory"));
115: suite.addTest(new ShowAnnotationsAndSearchHistoryTest(
116: "testShowAnnotations"));
117: suite.addTest(new ShowAnnotationsAndSearchHistoryTest(
118: "removeAllData"));
119: return suite;
120: }
121:
122: public void testCheckOutProject() throws Exception {
123: long timeout = JemmyProperties
124: .getCurrentTimeout("ComponentOperator.WaitComponentTimeout");
125: try {
126: JemmyProperties.setCurrentTimeout(
127: "ComponentOperator.WaitComponentTimeout", 30000);
128: } finally {
129: JemmyProperties.setCurrentTimeout(
130: "ComponentOperator.WaitComponentTimeout", timeout);
131: }
132:
133: timeout = JemmyProperties
134: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
135: try {
136: JemmyProperties.setCurrentTimeout(
137: "DialogWaiter.WaitDialogTimeout", 30000);
138: } finally {
139: JemmyProperties.setCurrentTimeout(
140: "DialogWaiter.WaitDialogTimeout", timeout);
141: }
142: TestKit.closeProject(projectName);
143: new ProjectsTabOperator().tree().clearSelection();
144: comOperator = new Operator.DefaultStringComparator(true, true);
145: oldOperator = (DefaultStringComparator) Operator
146: .getDefaultStringComparator();
147: Operator.setDefaultStringComparator(comOperator);
148: CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
149: Operator.setDefaultStringComparator(oldOperator);
150: CVSRootStepOperator crso = new CVSRootStepOperator();
151: crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
152: //prepare stream for successful authentification and run PseudoCVSServer
153: InputStream in = TestKit.getStream(getDataDir()
154: .getCanonicalFile().toString()
155: + File.separator + PROTOCOL_FOLDER, "authorized.in");
156: PseudoCvsServer cvss = new PseudoCvsServer(in);
157: new Thread(cvss).start();
158: cvss.ignoreProbe();
159: String CVSroot = cvss.getCvsRoot();
160: sessionCVSroot = CVSroot;
161: crso.setCVSRoot(CVSroot);
162: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
163: CVSroot);
164: crso.next();
165:
166: //2nd step of CheckOutWizard
167: File tmp = new File("/tmp"); // NOI18N
168: File work = new File(tmp, "" + File.separator
169: + System.currentTimeMillis());
170: cacheFolder = new File(work, projectName + File.separator
171: + "src" + File.separator + "forimport" + File.separator
172: + "CVS" + File.separator + "RevisionCache");
173: tmp.mkdirs();
174: work.mkdirs();
175: tmp.deleteOnExit();
176: ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
177: cvss.stop();
178: in.close();
179: moduleCheck.setModule("ForImport");
180: moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
181: //Pseudo CVS server for finishing check out wizard
182: in = TestKit.getStream(getDataDir().getCanonicalFile()
183: .toString()
184: + File.separator + PROTOCOL_FOLDER,
185: "checkout_finish_2.in");
186: cvss = new PseudoCvsServer(in);
187: new Thread(cvss).start();
188: CVSroot = cvss.getCvsRoot();
189: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
190: CVSroot);
191: cwo.finish();
192: OutputOperator oo = OutputOperator.invoke();
193: OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
194: oto.getTimeouts().setTimeout(
195: "ComponentOperator.WaitStateTimeout", 30000);
196: oto.waitText("Checking out finished");
197: cvss.stop();
198: in.close();
199: NbDialogOperator nbdialog = new NbDialogOperator(
200: "Checkout Completed");
201: JButtonOperator open = new JButtonOperator(nbdialog,
202: "Open Project");
203: open.push();
204:
205: ProjectSupport.waitScanFinished();
206: TestKit.waitForQueueEmpty();
207: ProjectSupport.waitScanFinished();
208:
209: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
210: }
211:
212: public void testShowAnnotations() throws Exception {
213: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
214: PseudoCvsServer cvss, cvss2;
215: InputStream in, in2;
216: //OutputOperator oo;
217: OutputTabOperator oto;
218: org.openide.nodes.Node nodeIDE;
219: String color, cvsRoot;
220:
221: TestKit.deleteRecursively(cacheFolder);
222:
223: //oo = OutputOperator.invoke();
224: oto = new OutputTabOperator(sessionCVSroot);
225: oto.getTimeouts().setTimeout(
226: "ComponentOperator.WaitStateTimeout", 30000);
227: in = TestKit.getStream(getDataDir().getCanonicalFile()
228: .toString()
229: + File.separator + PROTOCOL_FOLDER,
230: "show_annotation.in");
231: cvss = new PseudoCvsServer(in);
232: new Thread(cvss).start();
233:
234: in2 = TestKit.getStream(getDataDir().getCanonicalFile()
235: .toString()
236: + File.separator + PROTOCOL_FOLDER,
237: "show_annotation_1.in");
238: cvss2 = new PseudoCvsServer(in2);
239: new Thread(cvss2).start();
240:
241: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
242: .getCvsRoot()
243: + "," + cvss2.getCvsRoot());
244: Node nodeMain = new Node(new SourcePackagesNode("ForImport"),
245: "forimport|Main.java");
246: oto = new OutputTabOperator(sessionCVSroot);
247: oto.getTimeouts().setTimeout(
248: "ComponentOperator.WaitStateTimeout", 30000);
249: nodeMain.performPopupAction("CVS|Show Annotations");
250: Thread.sleep(1000);
251: oto.waitText("Loading Annotations finished");
252: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
253: cvss.stop();
254: cvss2.stop();
255: }
256:
257: public void testSearchHistory() throws Exception {
258: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
259: PseudoCvsServer cvss, cvss2;
260: InputStream in, in2;
261: //OutputOperator oo;
262: OutputTabOperator oto;
263: org.openide.nodes.Node nodeIDE;
264: String color, cvsRoot;
265: TestKit.deleteRecursively(cacheFolder);
266: oto = new OutputTabOperator(sessionCVSroot);
267: oto.getTimeouts().setTimeout(
268: "ComponentOperator.WaitStateTimeout", 30000);
269: in = TestKit
270: .getStream(getDataDir().getCanonicalFile().toString()
271: + File.separator + PROTOCOL_FOLDER,
272: "search_history.in");
273: cvss = new PseudoCvsServer(in);
274: new Thread(cvss).start();
275: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
276: .getCvsRoot());
277: Node nodeMain = new Node(new SourcePackagesNode("ForImport"),
278: "forimport|Main.java");
279: //nodeMain.performPopupAction("CVS|Search History...");
280: SearchHistoryOperator sho = SearchHistoryOperator
281: .invoke(nodeMain);
282: oto.waitText("Searching History finished");
283: Thread.sleep(1000);
284: cvss.stop();
285: oto.clear();
286: in = TestKit.getStream(getDataDir().getCanonicalFile()
287: .toString()
288: + File.separator + PROTOCOL_FOLDER,
289: "search_history_1.in");
290: cvss = new PseudoCvsServer(in);
291: new Thread(cvss).start();
292: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
293: .getCvsRoot());
294: sho.setUsername("test");
295: sho.setFrom("1.1");
296: sho.setTo("1.1");
297: sho.btSearch().push();
298: oto.waitText("Searching History started");
299: Thread.sleep(1000);
300: cvss.stop();
301: JListOperator list = sho.lstHistory();
302: ListModel model = list.getModel();
303: assertEquals("Wrong result count", 2, model.getSize());
304: assertTrue("Revision \"1.1\" is missing", model.getElementAt(1)
305: .toString().indexOf("1.1") > 0);
306: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
307: }
308:
309: public void removeAllData() throws Exception {
310: TestKit.closeProject(projectName);
311: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
312: }
313: }
|