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: * VersioningButtonsTest.java
044: *
045: * Created on 18. prosinec 2006, 13:33
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 junit.textui.TestRunner;
056: import org.netbeans.jellytools.JellyTestCase;
057: import org.netbeans.jellytools.NbDialogOperator;
058: import org.netbeans.jellytools.OutputOperator;
059: import org.netbeans.jellytools.OutputTabOperator;
060: import org.netbeans.jellytools.ProjectsTabOperator;
061: import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
062: import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
063: import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
064: import org.netbeans.jellytools.modules.javacvs.VersioningOperator;
065: import org.netbeans.jellytools.nodes.Node;
066: import org.netbeans.jellytools.nodes.SourcePackagesNode;
067: import org.netbeans.jemmy.JemmyProperties;
068: import org.netbeans.jemmy.QueueTool;
069: import org.netbeans.jemmy.TimeoutExpiredException;
070: import org.netbeans.jemmy.operators.JButtonOperator;
071: import org.netbeans.jemmy.operators.JProgressBarOperator;
072: import org.netbeans.jemmy.operators.JTableOperator;
073: import org.netbeans.jemmy.operators.Operator;
074: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
075: import org.netbeans.junit.NbTestSuite;
076: import org.netbeans.junit.ide.ProjectSupport;
077:
078: /**
079: *
080: * @author novakm
081: */
082: public class VersioningButtonsTest extends JellyTestCase {
083: String os_name;
084: static String sessionCVSroot;
085: final String projectName = "ForImport";
086: final String pathToMain = "forimport|Main.java";
087: final String PROTOCOL_FOLDER = "protocol";
088: static File cacheFolder;
089: Operator.DefaultStringComparator comOperator;
090: Operator.DefaultStringComparator oldOperator;
091:
092: /** Creates a new instance of VersioningButtonsTest */
093: public VersioningButtonsTest(String name) {
094: super (name);
095: }
096:
097: public static void main(String[] args) {
098: // TODO code application logic here
099: TestRunner.run(suite());
100: }
101:
102: protected void setUp() throws Exception {
103: os_name = System.getProperty("os.name");
104: //System.out.println(os_name);
105: System.out.println("### " + getName() + " ###");
106: }
107:
108: public static NbTestSuite suite() {
109: NbTestSuite suite = new NbTestSuite();
110: suite.addTest(new VersioningButtonsTest("testCheckOutProject"));
111: suite
112: .addTest(new VersioningButtonsTest(
113: "testVersioningButtons"));
114: // suite.addTest(new VersioningButtonsTest("removeAllData"));
115: return suite;
116: }
117:
118: public void testCheckOutProject() throws Exception {
119: long timeout = JemmyProperties
120: .getCurrentTimeout("ComponentOperator.WaitComponentTimeout");
121: try {
122: JemmyProperties.setCurrentTimeout(
123: "ComponentOperator.WaitComponentTimeout", 30000);
124: } finally {
125: JemmyProperties.setCurrentTimeout(
126: "ComponentOperator.WaitComponentTimeout", timeout);
127: }
128:
129: timeout = JemmyProperties
130: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
131: try {
132: JemmyProperties.setCurrentTimeout(
133: "DialogWaiter.WaitDialogTimeout", 30000);
134: } finally {
135: JemmyProperties.setCurrentTimeout(
136: "DialogWaiter.WaitDialogTimeout", timeout);
137: }
138: TestKit.closeProject(projectName);
139: new ProjectsTabOperator().tree().clearSelection();
140: comOperator = new Operator.DefaultStringComparator(true, true);
141: oldOperator = (DefaultStringComparator) Operator
142: .getDefaultStringComparator();
143: Operator.setDefaultStringComparator(comOperator);
144: CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
145: Operator.setDefaultStringComparator(oldOperator);
146: CVSRootStepOperator crso = new CVSRootStepOperator();
147: crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
148: //prepare stream for successful authentification and run PseudoCVSServer
149: InputStream in = TestKit.getStream(getDataDir()
150: .getCanonicalFile().toString()
151: + File.separator + PROTOCOL_FOLDER, "authorized.in");
152: PseudoCvsServer cvss = new PseudoCvsServer(in);
153: new Thread(cvss).start();
154: cvss.ignoreProbe();
155: String CVSroot = cvss.getCvsRoot();
156: sessionCVSroot = CVSroot;
157: crso.setCVSRoot(CVSroot);
158: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
159: CVSroot);
160: crso.next();
161:
162: //2nd step of CheckOutWizard
163: File tmp = new File("/tmp"); // NOI18N
164: File work = new File(tmp, "" + File.separator
165: + System.currentTimeMillis());
166: cacheFolder = new File(work, projectName + File.separator
167: + "src" + File.separator + "forimport" + File.separator
168: + "CVS" + File.separator + "RevisionCache");
169: tmp.mkdirs();
170: work.mkdirs();
171: tmp.deleteOnExit();
172: ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
173: cvss.stop();
174: in.close();
175: moduleCheck.setModule("ForImport");
176: moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
177: //Pseudo CVS server for finishing check out wizard
178: in = TestKit.getStream(getDataDir().getCanonicalFile()
179: .toString()
180: + File.separator + PROTOCOL_FOLDER,
181: "checkout_finish_2.in");
182: cvss = new PseudoCvsServer(in);
183: new Thread(cvss).start();
184: CVSroot = cvss.getCvsRoot();
185: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
186: CVSroot);
187: cwo.finish();
188: OutputOperator oo = OutputOperator.invoke();
189: OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
190: oto.getTimeouts().setTimeout(
191: "ComponentOperator.WaitStateTimeout", 30000);
192: oto.waitText("Checking out finished");
193: cvss.stop();
194: in.close();
195: NbDialogOperator nbdialog = new NbDialogOperator(
196: "Checkout Completed");
197: JButtonOperator open = new JButtonOperator(nbdialog,
198: "Open Project");
199: open.push();
200:
201: ProjectSupport.waitScanFinished();
202: TestKit.waitForQueueEmpty();
203: ProjectSupport.waitScanFinished();
204:
205: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
206: }
207:
208: public void testVersioningButtons() throws Exception {
209: VersioningOperator vo;
210: //OutputOperator oo;
211: OutputTabOperator oto;
212: InputStream in;
213: PseudoCvsServer cvss;
214: String CVSroot;
215: JTableOperator table;
216: org.openide.nodes.Node nodeIDE;
217: String color;
218:
219: oto = new OutputTabOperator(sessionCVSroot);
220: oto.getTimeouts().setTimeout(
221: "ComponentOperator.WaitStateTimeout", 30000);
222:
223: //perform Show Changes action on Main.java file
224: Node nodeMain = new Node(new SourcePackagesNode(projectName),
225: pathToMain);
226: //oo = OutputOperator.invoke();
227: //System.out.println(sessionCVSroot);
228: in = TestKit.getStream(getDataDir().getCanonicalFile()
229: .toString()
230: + File.separator + PROTOCOL_FOLDER,
231: "versioning/show_changes_main.in");
232: cvss = new PseudoCvsServer(in);
233: new Thread(cvss).start();
234: CVSroot = cvss.getCvsRoot();
235: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
236: CVSroot);
237: nodeMain.performPopupAction("CVS|Show Changes");
238: Thread.sleep(1000);
239: vo = VersioningOperator.invoke();
240: table = vo.tabFiles();
241: //System.out.println(""+table);
242: oto.waitText("Refreshing CVS Status finished");
243: Thread.sleep(1000);
244: assertEquals("Table should be empty", 1, table.getRowCount());
245: assertEquals("File should be [Remotely Modified]",
246: "Remotely Modified", table.getValueAt(0, 1).toString());
247: cvss.stop();
248: //System.out.println("Show Changes is ok");
249:
250: //push refresh button
251: //oo = OutputOperator.invoke();
252: //oto = oo.getOutputTab(sessionCVSroot);
253: oto = new OutputTabOperator(sessionCVSroot);
254: oto.clear();
255: in = TestKit.getStream(getDataDir().getCanonicalFile()
256: .toString()
257: + File.separator + PROTOCOL_FOLDER,
258: "versioning/refresh_main.in");
259: cvss = new PseudoCvsServer(in);
260: new Thread(cvss).start();
261: CVSroot = cvss.getCvsRoot();
262: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
263: CVSroot);
264: //vo = VersioningOperator.invoke();
265: vo.refresh();
266: oto.waitText("Refreshing CVS Status finished");
267: Thread.sleep(1000);
268: table = vo.tabFiles();
269: assertEquals("Table should be empty", 0, table.getRowCount());
270: cvss.stop();
271:
272: //push Update all
273: //oo = OutputOperator.invoke();
274: oto = new OutputTabOperator(sessionCVSroot);
275: oto.clear();
276: in = TestKit.getStream(getDataDir().getCanonicalFile()
277: .toString()
278: + File.separator + PROTOCOL_FOLDER,
279: "versioning/refresh_main.in");
280: cvss = new PseudoCvsServer(in);
281: new Thread(cvss).start();
282: CVSroot = cvss.getCvsRoot();
283: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
284: CVSroot);
285: //vo = VersioningOperator.invoke();
286: vo.update();
287: oto.waitText("Updating Sources finished");
288: Thread.sleep(1000);
289: cvss.stop();
290:
291: //push commit button
292: vo.commit();
293: Thread.sleep(1000);
294:
295: NbDialogOperator dialog = new NbDialogOperator("Comm");
296: JButtonOperator btnOk = new JButtonOperator(dialog, "OK");
297: btnOk.push();
298:
299: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
300: }
301:
302: public void removeAllData() throws Exception {
303: TestKit.closeProject(projectName);
304: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
305: }
306: }
|