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: * ResolveConflictsAndRevertTest.java
044: *
045: * Created on 18. prosinec 2006, 11:21
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.nodes.Node;
065: import org.netbeans.jellytools.nodes.SourcePackagesNode;
066: import org.netbeans.jemmy.JemmyProperties;
067: import org.netbeans.jemmy.QueueTool;
068: import org.netbeans.jemmy.TimeoutExpiredException;
069: import org.netbeans.jemmy.operators.JButtonOperator;
070: import org.netbeans.jemmy.operators.JProgressBarOperator;
071: import org.netbeans.jemmy.operators.Operator;
072: import org.netbeans.jemmy.operators.Operator;
073: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
074: import org.netbeans.junit.NbTestSuite;
075: import org.netbeans.junit.ide.ProjectSupport;
076:
077: /**
078: *
079: * @author novakm
080: */
081: public class ResolveConflictsAndRevertTest extends JellyTestCase {
082: String os_name;
083: static String sessionCVSroot;
084: final String projectName = "ForImport";
085: final String pathToMain = "forimport|Main.java";
086: final String PROTOCOL_FOLDER = "protocol";
087: static File cacheFolder;
088: Operator.DefaultStringComparator comOperator;
089: Operator.DefaultStringComparator oldOperator;
090:
091: /** Creates a new instance of ResolveConflictsAndRevertTest */
092: public ResolveConflictsAndRevertTest(String name) {
093: super (name);
094: }
095:
096: public static void main(String[] args) {
097: // TODO code application logic here
098: TestRunner.run(suite());
099: }
100:
101: protected void setUp() throws Exception {
102: os_name = System.getProperty("os.name");
103: //System.out.println(os_name);
104: System.out.println("### " + getName() + " ###");
105: }
106:
107: public static NbTestSuite suite() {
108: NbTestSuite suite = new NbTestSuite();
109: suite.addTest(new ResolveConflictsAndRevertTest(
110: "testCheckOutProject"));
111: suite.addTest(new ResolveConflictsAndRevertTest(
112: "testResolveConflicts"));
113: suite.addTest(new ResolveConflictsAndRevertTest(
114: "testRevertModifications"));
115: // suite.addTest(new ResolveConflictsAndRevertTest("removeAllData"));
116: return suite;
117: }
118:
119: public void testCheckOutProject() throws Exception {
120: long timeout = JemmyProperties
121: .getCurrentTimeout("ComponentOperator.WaitComponentTimeout");
122: try {
123: JemmyProperties.setCurrentTimeout(
124: "ComponentOperator.WaitComponentTimeout", 30000);
125: } finally {
126: JemmyProperties.setCurrentTimeout(
127: "ComponentOperator.WaitComponentTimeout", timeout);
128: }
129:
130: timeout = JemmyProperties
131: .getCurrentTimeout("DialogWaiter.WaitDialogTimeout");
132: try {
133: JemmyProperties.setCurrentTimeout(
134: "DialogWaiter.WaitDialogTimeout", 30000);
135: } finally {
136: JemmyProperties.setCurrentTimeout(
137: "DialogWaiter.WaitDialogTimeout", timeout);
138: }
139: TestKit.closeProject(projectName);
140: new ProjectsTabOperator().tree().clearSelection();
141: comOperator = new Operator.DefaultStringComparator(true, true);
142: oldOperator = (DefaultStringComparator) Operator
143: .getDefaultStringComparator();
144: Operator.setDefaultStringComparator(comOperator);
145: CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
146: Operator.setDefaultStringComparator(oldOperator);
147: CVSRootStepOperator crso = new CVSRootStepOperator();
148: crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
149: //prepare stream for successful authentification and run PseudoCVSServer
150: InputStream in = TestKit.getStream(getDataDir()
151: .getCanonicalFile().toString()
152: + File.separator + PROTOCOL_FOLDER, "authorized.in");
153: PseudoCvsServer cvss = new PseudoCvsServer(in);
154: new Thread(cvss).start();
155: cvss.ignoreProbe();
156: String CVSroot = cvss.getCvsRoot();
157: sessionCVSroot = CVSroot;
158: crso.setCVSRoot(CVSroot);
159: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
160: CVSroot);
161: crso.next();
162:
163: //2nd step of CheckOutWizard
164: File tmp = new File("/tmp"); // NOI18N
165: File work = new File(tmp, "" + File.separator
166: + System.currentTimeMillis());
167: cacheFolder = new File(work, projectName + File.separator
168: + "src" + File.separator + "forimport" + File.separator
169: + "CVS" + File.separator + "RevisionCache");
170: tmp.mkdirs();
171: work.mkdirs();
172: tmp.deleteOnExit();
173: ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
174: cvss.stop();
175: in.close();
176: moduleCheck.setModule("ForImport");
177: moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
178: //Pseudo CVS server for finishing check out wizard
179: in = TestKit.getStream(getDataDir().getCanonicalFile()
180: .toString()
181: + File.separator + PROTOCOL_FOLDER,
182: "checkout_finish_2.in");
183: cvss = new PseudoCvsServer(in);
184: new Thread(cvss).start();
185: CVSroot = cvss.getCvsRoot();
186: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
187: CVSroot);
188: cwo.finish();
189: OutputOperator oo = OutputOperator.invoke();
190: OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
191: oto.getTimeouts().setTimeout(
192: "ComponentOperator.WaitStateTimeout", 30000);
193: oto.waitText("Checking out finished");
194: cvss.stop();
195: in.close();
196: NbDialogOperator nbdialog = new NbDialogOperator(
197: "Checkout Completed");
198: JButtonOperator open = new JButtonOperator(nbdialog,
199: "Open Project");
200: open.push();
201:
202: ProjectSupport.waitScanFinished();
203: TestKit.waitForQueueEmpty();
204: ProjectSupport.waitScanFinished();
205:
206: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
207: }
208:
209: public void testResolveConflicts() throws Exception {
210: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
211: PseudoCvsServer cvss;
212: InputStream in;
213: OutputTabOperator oto;
214: org.openide.nodes.Node nodeIDE;
215: String color;
216:
217: oto = new OutputTabOperator(sessionCVSroot);
218: oto.getTimeouts().setTimeout(
219: "ComponentOperator.WaitStateTimeout", 30000);
220: oto.clear();
221:
222: Node nodeClass = new Node(new SourcePackagesNode(projectName),
223: pathToMain);
224: in = TestKit.getStream(getDataDir().getCanonicalFile()
225: .toString()
226: + File.separator + PROTOCOL_FOLDER,
227: "diff/create_conflict.in");
228: cvss = new PseudoCvsServer(in);
229: new Thread(cvss).start();
230: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
231: .getCvsRoot());
232: nodeClass.performPopupActionNoBlock("CVS|Update");
233: NbDialogOperator dialog = new NbDialogOperator("Warning");
234: dialog.ok();
235: oto.waitText("cvs server: conflicts found in Main.java");
236: oto.waitText("Updating \"Main.java\" finished");
237: Thread.sleep(1000);
238: cvss.stop();
239:
240: nodeClass = new Node(new SourcePackagesNode(projectName),
241: pathToMain);
242: nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
243: color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
244: assertEquals("Wrong color for file in conflict",
245: TestKit.CONFLICT_COLOR, color);
246: // todo - resolvnout pomoci accept&next , zkontrolovat pocet konfilktu a OK
247: // nodeClass.performPopupActionNoBlock("CVS|Resolve Conflicts...");
248: // pri revert modifications pri otevrenem conflict resolveru lita vyjimka!
249: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
250: }
251:
252: public void testRevertModifications() throws Exception {
253: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
254: PseudoCvsServer cvss;
255: InputStream in;
256: OutputTabOperator oto;
257: org.openide.nodes.Node nodeIDE;
258: oto = new OutputTabOperator(sessionCVSroot);
259: oto.getTimeouts().setTimeout(
260: "ComponentOperator.WaitStateTimeout", 30000);
261: oto.clear();
262: //delete RevsionCache folder. It can contain checked out revisions
263: TestKit.deleteRecursively(cacheFolder);
264: in = TestKit.getStream(getDataDir().getCanonicalFile()
265: .toString()
266: + File.separator + PROTOCOL_FOLDER,
267: "revert_modifications.in");
268: cvss = new PseudoCvsServer(in);
269: new Thread(cvss).start();
270: Node nodeMain = new Node(new SourcePackagesNode("ForImport"),
271: "forimport|Main.java");
272: nodeMain.performPopupActionNoBlock("CVS|Revert Modifications");
273: NbDialogOperator nbDialog = new NbDialogOperator(
274: "Confirm overwrite");
275: JButtonOperator btnYes = new JButtonOperator(nbDialog, "Yes");
276: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss
277: .getCvsRoot());
278: btnYes.push();
279: Thread.sleep(1000);
280: oto = new OutputTabOperator(sessionCVSroot);
281: oto.getTimeouts().setTimeout(
282: "ComponentOperator.WaitStateTimeout", 30000);
283: oto.waitText("Reverting finished");
284: cvss.stop();
285: nodeIDE = (org.openide.nodes.Node) nodeMain.getOpenideNode();
286: assertNull("No color for node expected", nodeIDE
287: .getHtmlDisplayName());
288: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
289: }
290:
291: public void removeAllData() throws Exception {
292: TestKit.closeProject(projectName);
293: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
294: }
295: }
|