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 CommittingCvs12Test 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 CommittingCvs12Test(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 CommittingCvs12Test("testCheckOutProject"));
116: suite
117: .addTest(new CommittingCvs12Test(
118: "testCommitModifiedCvs12"));
119: suite.addTest(new CommittingCvs12Test("removeAllData"));
120: return suite;
121: }
122:
123: public void testCheckOutProject() throws Exception {
124: PROTOCOL_FOLDER = "protocol";
125: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
126: //JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
127: TestKit.closeProject(projectName);
128: new ProjectsTabOperator().tree().clearSelection();
129: comOperator = new Operator.DefaultStringComparator(true, true);
130: oldOperator = (DefaultStringComparator) Operator
131: .getDefaultStringComparator();
132: Operator.setDefaultStringComparator(comOperator);
133: CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
134: Operator.setDefaultStringComparator(oldOperator);
135: CVSRootStepOperator crso = new CVSRootStepOperator();
136: //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
137: crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
138: //crso.setPassword("");
139: //crso.setPassword("test");
140:
141: //prepare stream for successful authentification and run PseudoCVSServer
142: InputStream in = TestKit.getStream(getDataDir()
143: .getCanonicalFile().toString()
144: + File.separator + PROTOCOL_FOLDER, "authorized.in");
145: PseudoCvsServer cvss = new PseudoCvsServer(in);
146: new Thread(cvss).start();
147: cvss.ignoreProbe();
148: String CVSroot = cvss.getCvsRoot();
149: sessionCVSroot = CVSroot;
150: //System.out.println(sessionCVSroot);
151: crso.setCVSRoot(CVSroot);
152: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
153: CVSroot);
154: crso.next();
155:
156: //second step of checkoutwizard
157: //2nd step of CheckOutWizard
158:
159: File tmp = new File("/tmp"); // NOI18N
160: File work = new File(tmp, "" + File.separator
161: + System.currentTimeMillis());
162: cacheFolder = new File(work, projectName + File.separator
163: + "src" + File.separator + "forimport" + File.separator
164: + "CVS" + File.separator + "RevisionCache");
165: tmp.mkdirs();
166: work.mkdirs();
167: tmp.deleteOnExit();
168: ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
169: cvss.stop();
170: in.close();
171: moduleCheck.setModule("ForImport");
172: moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
173:
174: //Pseudo CVS server for finishing check out wizard
175: in = TestKit.getStream(getDataDir().getCanonicalFile()
176: .toString()
177: + File.separator + PROTOCOL_FOLDER,
178: "checkout_finish_2.in");
179: cvss = new PseudoCvsServer(in);
180: new Thread(cvss).start();
181: CVSroot = cvss.getCvsRoot();
182: //cvss.ignoreProbe();
183:
184: //crso.setCVSRoot(CVSroot);
185: //combo.setSelectedItem(CVSroot);
186: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
187: CVSroot);
188: cwo.finish();
189:
190: OutputOperator oo = OutputOperator.invoke();
191: //System.out.println(CVSroot);
192:
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: //create new elements for testing
210: TestKit.createNewElementsCommitCvs12(projectName);
211: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
212: }
213:
214: public void testCommitModifiedCvs12() throws Exception {
215: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
216: PseudoCvsServer cvss, cvss2, cvss3, cvss4;
217: InputStream in, in2, in3, in4;
218: CommitOperator co;
219: String CVSroot, color;
220: JTableOperator table;
221: OutputOperator oo;
222: OutputTabOperator oto;
223: VersioningOperator vo;
224: String[] expected;
225: String[] actual;
226: String allCVSRoots;
227: org.openide.nodes.Node nodeIDE;
228: PROTOCOL_FOLDER = "protocol" + File.separator
229: + "cvs_committing_cvs12";
230:
231: Node packNode = new SourcePackagesNode("ForImport");
232:
233: co = CommitOperator.invoke(packNode);
234: Thread.sleep(1000);
235: table = co.tabFiles();
236: TableModel model = table.getModel();
237:
238: expected = new String[] { "NewClass.java", "NewClass2.java",
239: "NewClass.java", "NewClass2.java" };
240: table = co.tabFiles();
241: model = table.getModel();
242: actual = new String[model.getRowCount()];
243: for (int i = 0; i < actual.length; i++) {
244: actual[i] = model.getValueAt(i, 0).toString();
245: }
246: int result = TestKit.compareThem(expected, actual, false);
247: assertEquals("Wrong records displayed in dialog", 4, result);
248: co.setCommitMessage("Initial commit message");
249:
250: oo = OutputOperator.invoke();
251: oto = oo.getOutputTab(sessionCVSroot);
252: oto.getTimeouts().setTimeout(
253: "ComponentOperator.WaitStateTimeout", 30000);
254: oto.clear();
255: in = TestKit.getStream(getDataDir().getCanonicalFile()
256: .toString()
257: + File.separator + PROTOCOL_FOLDER, "commit_invoke.in");
258: cvss = new PseudoCvsServer(in);
259: new Thread(cvss).start();
260: allCVSRoots = cvss.getCvsRoot() + ",";
261:
262: in2 = TestKit.getStream(getDataDir().getCanonicalFile()
263: .toString()
264: + File.separator + PROTOCOL_FOLDER,
265: "commit_invoke_add_4.in");
266: cvss2 = new PseudoCvsServer(in2);
267: new Thread(cvss2).start();
268: allCVSRoots = allCVSRoots + cvss2.getCvsRoot() + ",";
269:
270: in3 = TestKit.getStream(getDataDir().getCanonicalFile()
271: .toString()
272: + File.separator + PROTOCOL_FOLDER,
273: "commit_invoke_commit_4.in");
274: cvss3 = new PseudoCvsServer(in3);
275: new Thread(cvss3).start();
276: allCVSRoots = allCVSRoots + cvss3.getCvsRoot() + ",";
277:
278: in4 = TestKit
279: .getStream(getDataDir().getCanonicalFile().toString()
280: + File.separator + PROTOCOL_FOLDER,
281: "checkout_final.in");
282: cvss4 = new PseudoCvsServer(in4);
283: new Thread(cvss4).start();
284: allCVSRoots = allCVSRoots + cvss4.getCvsRoot();
285:
286: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
287: allCVSRoots);
288: co.commit();
289: oto.waitText("Committing \"src\" finished");
290:
291: cvss.stop();
292: cvss2.stop();
293: cvss3.stop();
294: cvss4.stop();
295:
296: //modify files
297: Node node = new Node(new SourcePackagesNode(projectName),
298: "aa|NewClass.java");
299: node.performPopupAction("Open");
300: EditorOperator eo = new EditorOperator("NewClass.java");
301: eo.deleteLine(2);
302: eo.insert(" a", 3, 4);
303: eo.save();
304: node = new Node(new SourcePackagesNode(projectName),
305: "aa|NewClass2.java");
306: node.performPopupAction("Open");
307: eo = new EditorOperator("NewClass2.java");
308: eo.deleteLine(2);
309: eo.insert(" a", 3, 4);
310: eo.save();
311: node = new Node(new SourcePackagesNode(projectName),
312: "bb|NewClass.java");
313: node.performPopupAction("Open");
314: eo = new EditorOperator("NewClass.java");
315: eo.deleteLine(2);
316: eo.insert(" a", 3, 4);
317: eo.save();
318: node = new Node(new SourcePackagesNode(projectName),
319: "bb|NewClass2.java");
320: node.performPopupAction("Open");
321: eo = new EditorOperator("NewClass2.java");
322: eo.deleteLine(2);
323: eo.insert(" a", 3, 4);
324: eo.save();
325:
326: //
327: oto = new OutputTabOperator(sessionCVSroot);
328: oto.getTimeouts().setTimeout(
329: "ComponentOperator.WaitStateTimeout", 30000);
330: in = TestKit.getStream(getDataDir().getCanonicalFile()
331: .toString()
332: + File.separator + PROTOCOL_FOLDER,
333: "commit_invoke_commit_4_modified_show_changes.in");
334: cvss = new PseudoCvsServer(in);
335: new Thread(cvss).start();
336: CVSroot = cvss.getCvsRoot();
337: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
338: CVSroot);
339: packNode.performPopupAction("CVS|Show Changes");
340: Thread.sleep(1000);
341: oto.waitText("Refreshing");
342: oto.waitText("finished");
343: cvss.stop();
344:
345: oo = OutputOperator.invoke();
346: oto.clear();
347: co = CommitOperator.invoke(packNode);
348: //
349: Thread.sleep(1000);
350: in = TestKit.getStream(getDataDir().getCanonicalFile()
351: .toString()
352: + File.separator + PROTOCOL_FOLDER,
353: "commit_invoke_commit_4_modified_wrong.in");
354: cvss = new PseudoCvsServer(in);
355: new Thread(cvss).start();
356:
357: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
358: .getCvsRoot());
359: co.commit();
360:
361: oto.waitText("Committing \"src\" finished");
362: cvss.stop();
363: cvss2.stop();
364:
365: //
366: Node nodeClass = new Node(new SourcePackagesNode("ForImport"),
367: "aa|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: "aa|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: "bb|NewClass.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: "bb|NewClass2.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: }
|