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: * CommittingCvs11Test.java
044: *
045: * Created on 08 March 2006, 11:03
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.table.TableModel;
056: import junit.textui.TestRunner;
057: import org.netbeans.jellytools.EditorOperator;
058: import org.netbeans.jellytools.JellyTestCase;
059: import org.netbeans.jellytools.NbDialogOperator;
060: import org.netbeans.jellytools.OutputOperator;
061: import org.netbeans.jellytools.OutputTabOperator;
062: import org.netbeans.jellytools.ProjectsTabOperator;
063: import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
064: import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
065: import org.netbeans.jellytools.modules.javacvs.CommitOperator;
066: import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
067: import org.netbeans.jellytools.modules.javacvs.VersioningOperator;
068: import org.netbeans.jellytools.nodes.Node;
069: import org.netbeans.jellytools.nodes.SourcePackagesNode;
070: import org.netbeans.jemmy.QueueTool;
071: import org.netbeans.jemmy.TimeoutExpiredException;
072: import org.netbeans.jemmy.operators.JButtonOperator;
073: import org.netbeans.jemmy.operators.JProgressBarOperator;
074: import org.netbeans.jemmy.operators.JTableOperator;
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 peter
083: */
084: public class CommittingCvs11Test extends JellyTestCase {
085:
086: String os_name;
087: static String sessionCVSroot;
088: final String projectName = "ForImport";
089: final String pathToMain = "forimport|Main.java";
090: static File cacheFolder;
091: String PROTOCOL_FOLDER = "protocol";
092: Operator.DefaultStringComparator comOperator;
093: Operator.DefaultStringComparator oldOperator;
094:
095: /**
096: * Creates a new instance of CommittingCvs11Test
097: */
098: public CommittingCvs11Test(String name) {
099: super (name);
100: }
101:
102: public static void main(String[] args) {
103: // TODO code application logic here
104: TestRunner.run(suite());
105: }
106:
107: protected void setUp() throws Exception {
108: os_name = System.getProperty("os.name");
109: //System.out.println(os_name);
110: System.out.println("### " + getName() + " ###");
111: }
112:
113: public static NbTestSuite suite() {
114: NbTestSuite suite = new NbTestSuite();
115: suite.addTest(new CommittingCvs11Test("testCheckOutProject"));
116: suite.addTest(new CommittingCvs11Test("testCommitModified"));
117: suite.addTest(new CommittingCvs11Test("removeAllData"));
118: return suite;
119: }
120:
121: public void testCheckOutProject() throws Exception {
122: PROTOCOL_FOLDER = "protocol";
123: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
124: //JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
125: TestKit.closeProject(projectName);
126: new ProjectsTabOperator().tree().clearSelection();
127: comOperator = new Operator.DefaultStringComparator(true, true);
128: oldOperator = (DefaultStringComparator) Operator
129: .getDefaultStringComparator();
130: Operator.setDefaultStringComparator(comOperator);
131: CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
132: Operator.setDefaultStringComparator(oldOperator);
133: CVSRootStepOperator crso = new CVSRootStepOperator();
134: //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
135: crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
136: //crso.setPassword("");
137: //crso.setPassword("test");
138:
139: //prepare stream for successful authentification and run PseudoCVSServer
140: InputStream in = TestKit.getStream(getDataDir()
141: .getCanonicalFile().toString()
142: + File.separator + PROTOCOL_FOLDER, "authorized.in");
143: PseudoCvsServer cvss = new PseudoCvsServer(in);
144: new Thread(cvss).start();
145: cvss.ignoreProbe();
146: String CVSroot = cvss.getCvsRoot();
147: sessionCVSroot = CVSroot;
148: //System.out.println(sessionCVSroot);
149: crso.setCVSRoot(CVSroot);
150: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
151: CVSroot);
152: crso.next();
153:
154: //second step of checkoutwizard
155: //2nd step of CheckOutWizard
156:
157: File tmp = new File("/tmp"); // NOI18N
158: File work = new File(tmp, "" + File.separator
159: + System.currentTimeMillis());
160: cacheFolder = new File(work, projectName + File.separator
161: + "src" + File.separator + "forimport" + File.separator
162: + "CVS" + File.separator + "RevisionCache");
163: tmp.mkdirs();
164: work.mkdirs();
165: tmp.deleteOnExit();
166: ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
167: cvss.stop();
168: in.close();
169: moduleCheck.setModule("ForImport");
170: moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
171:
172: //Pseudo CVS server for finishing check out wizard
173: in = TestKit.getStream(getDataDir().getCanonicalFile()
174: .toString()
175: + File.separator + PROTOCOL_FOLDER,
176: "checkout_finish_2.in");
177: cvss = new PseudoCvsServer(in);
178: new Thread(cvss).start();
179: CVSroot = cvss.getCvsRoot();
180: //cvss.ignoreProbe();
181:
182: //crso.setCVSRoot(CVSroot);
183: //combo.setSelectedItem(CVSroot);
184: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
185: CVSroot);
186: cwo.finish();
187:
188: OutputOperator oo = OutputOperator.invoke();
189: //System.out.println(CVSroot);
190:
191: OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
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: //create new elements for testing
206: TestKit.createNewElementsCommitCvs11(projectName);
207: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
208: }
209:
210: public void testCommitModified() throws Exception {
211: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
212: PseudoCvsServer cvss, cvss2, cvss3, cvss4;
213: InputStream in, in2, in3, in4;
214: CommitOperator co;
215: String CVSroot, color;
216: JTableOperator table;
217: OutputOperator oo;
218: OutputTabOperator oto;
219: VersioningOperator vo;
220: String[] expected;
221: String[] actual;
222: String allCVSRoots;
223: org.openide.nodes.Node nodeIDE;
224: PROTOCOL_FOLDER = "protocol" + File.separator
225: + "cvs_committing_cvs11";
226:
227: Node packNode = new Node(new SourcePackagesNode("ForImport"),
228: "xx");
229:
230: co = CommitOperator.invoke(packNode);
231: Thread.sleep(1000);
232: table = co.tabFiles();
233: TableModel model = table.getModel();
234:
235: expected = new String[] { "NewClass.java", "NewClass2.java",
236: "NewClass3.java", "NewClass4.java" };
237: actual = new String[model.getRowCount()];
238: for (int i = 0; i < actual.length; i++) {
239: actual[i] = model.getValueAt(i, 0).toString();
240: }
241: int result = TestKit.compareThem(expected, actual, false);
242: assertEquals("Wrong records displayed in dialog", 4, result);
243: co.setCommitMessage("Initial commit message");
244:
245: oo = OutputOperator.invoke();
246: oto = oo.getOutputTab(sessionCVSroot);
247: oto.getTimeouts().setTimeout(
248: "ComponentOperator.WaitStateTimeout", 30000);
249: oto.clear();
250: in = TestKit.getStream(getDataDir().getCanonicalFile()
251: .toString()
252: + File.separator + PROTOCOL_FOLDER, "commit_invoke.in");
253: cvss = new PseudoCvsServer(in);
254: new Thread(cvss).start();
255: allCVSRoots = cvss.getCvsRoot() + ",";
256:
257: in2 = TestKit.getStream(getDataDir().getCanonicalFile()
258: .toString()
259: + File.separator + PROTOCOL_FOLDER,
260: "commit_invoke_add_4.in");
261: cvss2 = new PseudoCvsServer(in2);
262: new Thread(cvss2).start();
263: allCVSRoots = allCVSRoots + cvss2.getCvsRoot() + ",";
264:
265: in3 = TestKit.getStream(getDataDir().getCanonicalFile()
266: .toString()
267: + File.separator + PROTOCOL_FOLDER,
268: "commit_invoke_commit_4.in");
269: cvss3 = new PseudoCvsServer(in3);
270: new Thread(cvss3).start();
271: allCVSRoots = allCVSRoots + cvss3.getCvsRoot() + ",";
272:
273: in4 = TestKit
274: .getStream(getDataDir().getCanonicalFile().toString()
275: + File.separator + PROTOCOL_FOLDER,
276: "checkout_final.in");
277: cvss4 = new PseudoCvsServer(in4);
278: new Thread(cvss4).start();
279: allCVSRoots = allCVSRoots + cvss4.getCvsRoot();
280:
281: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
282: allCVSRoots);
283: co.commit();
284: oto.waitText("Committing");
285: oto.waitText("finished");
286:
287: cvss.stop();
288: cvss2.stop();
289: cvss3.stop();
290: cvss4.stop();
291: //modify files
292: Node node = new Node(new SourcePackagesNode(projectName),
293: "xx|NewClass.java");
294: node.performPopupAction("Open");
295: EditorOperator eo = new EditorOperator("NewClass.java");
296: eo.deleteLine(2);
297: eo.insert(" a", 3, 4);
298: eo.save();
299: node = new Node(new SourcePackagesNode(projectName),
300: "xx|NewClass2.java");
301: node.performPopupAction("Open");
302: eo = new EditorOperator("NewClass2.java");
303: eo.deleteLine(2);
304: eo.insert(" a", 3, 4);
305: eo.save();
306: node = new Node(new SourcePackagesNode(projectName),
307: "xx|NewClass3.java");
308: node.performPopupAction("Open");
309: eo = new EditorOperator("NewClass3.java");
310: eo.deleteLine(2);
311: eo.insert(" a", 3, 4);
312: eo.save();
313: node = new Node(new SourcePackagesNode(projectName),
314: "xx|NewClass4.java");
315: node.performPopupAction("Open");
316: eo = new EditorOperator("NewClass4.java");
317: eo.deleteLine(2);
318: eo.insert(" a", 3, 4);
319: eo.save();
320: //commit changes
321:
322: //
323: oto = new OutputTabOperator(sessionCVSroot);
324: oto.getTimeouts().setTimeout(
325: "ComponentOperator.WaitStateTimeout", 30000);
326: in = TestKit.getStream(getDataDir().getCanonicalFile()
327: .toString()
328: + File.separator + PROTOCOL_FOLDER,
329: "commit_invoke_commit_4_modified_show_changes.in");
330: cvss = new PseudoCvsServer(in);
331: new Thread(cvss).start();
332: CVSroot = cvss.getCvsRoot();
333: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
334: CVSroot);
335: packNode.performPopupAction("CVS|Show Changes");
336: Thread.sleep(1000);
337: oto.waitText("Refreshing");
338: oto.waitText("finished");
339: cvss.stop();
340:
341: //oo = OutputOperator.invoke();
342: oto = new OutputTabOperator(sessionCVSroot);
343: oto.getTimeouts().setTimeout(
344: "ComponentOperator.WaitStateTimeout", 30000);
345: oto.clear();
346: co = CommitOperator.invoke(packNode);
347: //
348: Thread.sleep(1000);
349: in = TestKit.getStream(getDataDir().getCanonicalFile()
350: .toString()
351: + File.separator + PROTOCOL_FOLDER,
352: "commit_invoke_commit_4_modified_wrong.in");
353: cvss = new PseudoCvsServer(in);
354: new Thread(cvss).start();
355:
356: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
357: .getCvsRoot());
358: co.commit();
359:
360: oto.waitText("Committing");
361: oto.waitText("finished");
362: cvss.stop();
363: cvss2.stop();
364:
365: //
366: Node nodeClass = new Node(new SourcePackagesNode("ForImport"),
367: "xx|NewClass.java");
368: nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
369: //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
370: assertNull("Wrong color of node!!!", nodeIDE
371: .getHtmlDisplayName());
372:
373: nodeClass = new Node(new SourcePackagesNode("ForImport"),
374: "xx|NewClass2.java");
375: nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
376: //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
377: assertNull("Wrong color of node!!!", nodeIDE
378: .getHtmlDisplayName());
379:
380: nodeClass = new Node(new SourcePackagesNode("ForImport"),
381: "xx|NewClass3.java");
382: nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
383: color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
384: assertEquals("Wrong color of node!!!", TestKit.MODIFIED_COLOR,
385: color);
386:
387: nodeClass = new Node(new SourcePackagesNode("ForImport"),
388: "xx|NewClass4.java");
389: nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
390: //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
391: assertNull("Wrong color of node!!!", nodeIDE
392: .getHtmlDisplayName());
393:
394: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
395: }
396:
397: public void removeAllData() throws Exception {
398: TestKit.closeProject(projectName);
399: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
400: }
401: }
|