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: * ExportPatchAndDiffTest.java
044: *
045: * Created on 15. prosinec 2006, 10:57
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.BufferedReader;
054: import java.io.File;
055: import java.io.FileReader;
056: import java.io.InputStream;
057: import junit.textui.TestRunner;
058: import org.netbeans.jellytools.EditorOperator;
059: import org.netbeans.jellytools.JellyTestCase;
060: import org.netbeans.jellytools.NbDialogOperator;
061: import org.netbeans.jellytools.OutputOperator;
062: import org.netbeans.jellytools.OutputTabOperator;
063: import org.netbeans.jellytools.ProjectsTabOperator;
064: import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
065: import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
066: import org.netbeans.jellytools.modules.javacvs.CommitOperator;
067: import org.netbeans.jellytools.modules.javacvs.DiffOperator;
068: import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
069: import org.netbeans.jellytools.nodes.Node;
070: import org.netbeans.jellytools.nodes.SourcePackagesNode;
071: import org.netbeans.jemmy.QueueTool;
072: import org.netbeans.jemmy.TimeoutExpiredException;
073: import org.netbeans.jemmy.operators.JButtonOperator;
074: import org.netbeans.jemmy.operators.JMenuOperator;
075: import org.netbeans.jemmy.operators.JProgressBarOperator;
076: import org.netbeans.jemmy.operators.JTableOperator;
077: import org.netbeans.jemmy.operators.JTextFieldOperator;
078: import org.netbeans.jemmy.operators.Operator;
079: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
080: import org.netbeans.junit.NbTestSuite;
081: import org.netbeans.junit.ide.ProjectSupport;
082:
083: /**
084: *
085: * @author novakm
086: */
087: public class ExportPatchAndDiffTest extends JellyTestCase {
088:
089: String os_name;
090: static String sessionCVSroot;
091: final String projectName = "ForImport";
092: final String pathToMain = "forimport|Main.java";
093: final String PROTOCOL_FOLDER = "protocol";
094: static File cacheFolder;
095: Operator.DefaultStringComparator comOperator;
096: Operator.DefaultStringComparator oldOperator;
097:
098: /** Creates a new instance of ExportPatchAndDiffTest */
099: public ExportPatchAndDiffTest(String name) {
100: super (name);
101: }
102:
103: public static void main(String[] args) {
104: // TODO code application logic here
105: TestRunner.run(suite());
106: }
107:
108: protected void setUp() throws Exception {
109: os_name = System.getProperty("os.name");
110: //System.out.println(os_name);
111: System.out.println("### " + getName() + " ###");
112: }
113:
114: public static NbTestSuite suite() {
115: NbTestSuite suite = new NbTestSuite();
116: suite
117: .addTest(new ExportPatchAndDiffTest(
118: "testCheckOutProject"));
119: suite
120: .addTest(new ExportPatchAndDiffTest(
121: "testExportDiffPatch"));
122: suite.addTest(new ExportPatchAndDiffTest("testDiffFile"));
123: suite.addTest(new ExportPatchAndDiffTest("removeAllData"));
124: return suite;
125: }
126:
127: public void testCheckOutProject() throws Exception {
128: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
129: //JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
130: TestKit.closeProject(projectName);
131: new ProjectsTabOperator().tree().clearSelection();
132: comOperator = new Operator.DefaultStringComparator(true, true);
133: oldOperator = (DefaultStringComparator) Operator
134: .getDefaultStringComparator();
135: Operator.setDefaultStringComparator(comOperator);
136: CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
137: Operator.setDefaultStringComparator(oldOperator);
138: CVSRootStepOperator crso = new CVSRootStepOperator();
139: crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
140: //prepare stream for successful authentification and run PseudoCVSServer
141: InputStream in = TestKit.getStream(getDataDir()
142: .getCanonicalFile().toString()
143: + File.separator + PROTOCOL_FOLDER, "authorized.in");
144: PseudoCvsServer cvss = new PseudoCvsServer(in);
145: new Thread(cvss).start();
146: cvss.ignoreProbe();
147: String CVSroot = cvss.getCvsRoot();
148: sessionCVSroot = CVSroot;
149: crso.setCVSRoot(CVSroot);
150: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
151: CVSroot);
152: crso.next();
153:
154: //2nd step of CheckOutWizard
155: File tmp = new File("/tmp"); // NOI18N
156: File work = new File(tmp, "" + File.separator
157: + System.currentTimeMillis());
158: cacheFolder = new File(work, projectName + File.separator
159: + "src" + File.separator + "forimport" + File.separator
160: + "CVS" + File.separator + "RevisionCache");
161: tmp.mkdirs();
162: work.mkdirs();
163: tmp.deleteOnExit();
164: ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
165: cvss.stop();
166: in.close();
167: moduleCheck.setModule("ForImport");
168: moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
169: //Pseudo CVS server for finishing check out wizard
170: in = TestKit.getStream(getDataDir().getCanonicalFile()
171: .toString()
172: + File.separator + PROTOCOL_FOLDER,
173: "checkout_finish_2.in");
174: cvss = new PseudoCvsServer(in);
175: new Thread(cvss).start();
176: CVSroot = cvss.getCvsRoot();
177: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
178: CVSroot);
179: cwo.finish();
180: OutputOperator oo = OutputOperator.invoke();
181: OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
182: oto.getTimeouts().setTimeout(
183: "ComponentOperator.WaitStateTimeout", 30000);
184: oto.waitText("Checking out finished");
185: cvss.stop();
186: in.close();
187: NbDialogOperator nbdialog = new NbDialogOperator(
188: "Checkout Completed");
189: JButtonOperator open = new JButtonOperator(nbdialog,
190: "Open Project");
191: open.push();
192:
193: ProjectSupport.waitScanFinished();
194: TestKit.waitForQueueEmpty();
195: ProjectSupport.waitScanFinished();
196:
197: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
198: }
199:
200: public void testExportDiffPatch() throws Exception {
201: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
202: //JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
203: PseudoCvsServer cvss;
204: InputStream in;
205: OutputTabOperator oto;
206: oto = new OutputTabOperator(sessionCVSroot);
207: oto.getTimeouts().setTimeout(
208: "ComponentOperator.WaitStateTimeout", 30000);
209: new ProjectsTabOperator().tree().clearSelection();
210: Node nodeClass = new Node(new SourcePackagesNode(projectName),
211: pathToMain);
212:
213: nodeClass.performPopupAction("Open");
214: EditorOperator eo = new EditorOperator("Main.java");
215: eo.insert("// EXPORT PATCH", 5, 1);
216: eo.save();
217:
218: nodeClass = new Node(new SourcePackagesNode(projectName),
219: pathToMain);
220: //nodeClass.select();
221: comOperator = new Operator.DefaultStringComparator(true, true);
222: oldOperator = (DefaultStringComparator) Operator
223: .getDefaultStringComparator();
224: Operator.setDefaultStringComparator(comOperator);
225: nodeClass
226: .performMenuActionNoBlock("Versioning|Export Diff Patch...");
227: Operator.setDefaultStringComparator(oldOperator);
228:
229: //Operator.setDefaultStringComparator(oldOperator);
230: NbDialogOperator dialog = new NbDialogOperator("Export");
231:
232: JTextFieldOperator tf = new JTextFieldOperator(dialog, 0);
233: String patchFile = "/tmp/patch" + System.currentTimeMillis()
234: + ".patch";
235: File file = new File(patchFile);
236: tf.setText(file.getCanonicalFile().toString());
237: JButtonOperator btnExport = new JButtonOperator(dialog,
238: "export");
239: oto = new OutputTabOperator(sessionCVSroot);
240: oto.clear();
241: in = TestKit.getStream(getDataDir().getCanonicalFile()
242: .toString()
243: + File.separator + PROTOCOL_FOLDER,
244: "diff/export_diff.in");
245: cvss = new PseudoCvsServer(in);
246: new Thread(cvss).start();
247: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
248: .getCvsRoot());
249: btnExport.push();
250: // no output in output tab now
251: // oto.waitText("Diff Patch finished");
252: Thread.sleep(3000);
253: cvss.stop();
254: Thread.sleep(2000);
255: //test file existence
256: assertTrue("Diff Patch file wasn't created!", file.isFile());
257: BufferedReader br = new BufferedReader(new FileReader(file));
258: String line = br.readLine();
259: boolean generated = false;
260: if (line != null) {
261: generated = line
262: .indexOf("# This patch file was generated by NetBeans IDE") != -1 ? true
263: : false;
264: }
265:
266: br.close();
267: assertTrue("Diff Patch file is empty!", generated);
268: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
269:
270: }
271:
272: public void testDiffFile() throws Exception {
273: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
274: PseudoCvsServer cvss;
275: InputStream in;
276: //OutputOperator oo;
277: OutputTabOperator oto;
278: org.openide.nodes.Node nodeIDE;
279: String color;
280:
281: oto = new OutputTabOperator(sessionCVSroot);
282: oto.getTimeouts().setTimeout(
283: "ComponentOperator.WaitStateTimeout", 30000);
284:
285: Node node = new Node(new SourcePackagesNode(projectName),
286: pathToMain);
287: node.performPopupAction("Open");
288: EditorOperator eo = new EditorOperator("Main.java");
289: eo.deleteLine(2);
290: eo.insert(" insert", 5, 1);
291: eo.insert("\tSystem.out.println(\"\");\n", 19, 1);
292: eo.save();
293:
294: in = TestKit.getStream(getDataDir().getCanonicalFile()
295: .toString()
296: + File.separator + PROTOCOL_FOLDER, "diff_class.in");
297: cvss = new PseudoCvsServer(in);
298: new Thread(cvss).start();
299: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
300: .getCvsRoot());
301: node.performPopupAction("CVS|Diff");
302:
303: // oto.waitText("Diffing \"Main.java\" finished");
304: Thread.sleep(1000);
305: cvss.stop();
306:
307: Node nodeClass = new Node(new SourcePackagesNode(projectName),
308: pathToMain);
309: nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
310: color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
311: assertEquals("Wrong color for modified file",
312: TestKit.MODIFIED_COLOR, color);
313:
314: //verify next button
315: DiffOperator diffOp = new DiffOperator("Main.java");
316: //
317: try {
318: TimeoutExpiredException afee = null;
319: //find the last difference
320: try {
321: diffOp.next();
322: diffOp.next();
323: diffOp.next();
324: } catch (TimeoutExpiredException e) {
325: //want to be sure that the last difference was found
326: afee = e;
327: }
328: assertNotNull(
329: "TimeoutExpiredException was expected - diff should have pointed to the last difference.",
330: afee);
331:
332: //verify previous button
333: afee = null;
334: diffOp.previous();
335: diffOp.previous();
336: try {
337: diffOp.previous();
338: } catch (TimeoutExpiredException e) {
339: afee = e;
340: }
341: assertNotNull(
342: "TimeoutExpiredException was expected - previous diff should have been disabled.",
343: afee);
344:
345: //verify next button
346: afee = null;
347: diffOp.next();
348: diffOp.next();
349: try {
350: diffOp.next();
351: } catch (TimeoutExpiredException e) {
352: afee = e;
353: }
354: assertNotNull(
355: "TimeoutExpiredException was expected - next diff should have been disabled.",
356: afee);
357:
358: } catch (Exception e) {
359: System.out.println("Problem with buttons of differences");
360: e.printStackTrace();
361: }
362:
363: //refresh button
364: oto = new OutputTabOperator(sessionCVSroot);
365: oto.clear();
366: in = TestKit.getStream(getDataDir().getCanonicalFile()
367: .toString()
368: + File.separator + PROTOCOL_FOLDER, "diff/refresh.in");
369: cvss = new PseudoCvsServer(in);
370: new Thread(cvss).start();
371: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
372: .getCvsRoot());
373: diffOp.refresh();
374: oto.waitText("Refreshing CVS Status finished");
375: cvss.stop();
376: Thread.sleep(1000);
377:
378: //update button
379: oto = new OutputTabOperator(sessionCVSroot);
380: oto.clear();
381: in = TestKit.getStream(getDataDir().getCanonicalFile()
382: .toString()
383: + File.separator + PROTOCOL_FOLDER, "diff/refresh.in");
384: cvss = new PseudoCvsServer(in);
385: new Thread(cvss).start();
386: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
387: .getCvsRoot());
388: diffOp.update();
389: oto.waitText("Updating Sources finished");
390: cvss.stop();
391: Thread.sleep(1000);
392:
393: //commit button
394: CommitOperator co = diffOp.commit();
395: JTableOperator table = co.tabFiles();
396: assertEquals("There should be only one file!", 1, table
397: .getRowCount());
398: assertEquals("There should be Main.java file only!",
399: "Main.java", table.getValueAt(0, 0));
400: co.cancel();
401:
402: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
403: // eo.closeWindow();
404: eo.closeAllDocuments();
405: TestKit.deleteRecursively(cacheFolder);
406: }
407:
408: public void removeAllData() throws Exception {
409: TestKit.closeProject(projectName);
410: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
411: }
412: }
|