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: package complete;
043:
044: import complete.GenericStub.GenericNode;
045: import java.io.File;
046: import java.text.SimpleDateFormat;
047: import java.util.Date;
048: import java.util.Enumeration;
049: import junit.framework.AssertionFailedError;
050: import org.netbeans.jellytools.NbDialogOperator;
051: import org.netbeans.jellytools.NewWizardOperator;
052: import org.netbeans.jellytools.actions.Action;
053: import org.netbeans.jellytools.actions.CustomizeAction;
054: import org.netbeans.jellytools.modules.javacvs.CVSClientCustomizerDialogOperator;
055: import org.netbeans.jellytools.modules.javacvs.actions.JCVSMountAction;
056: import org.netbeans.jellytools.modules.javacvs.wizard.*;
057: import org.netbeans.jellytools.nodes.Node;
058: import org.netbeans.jellytools.properties.ComboBoxProperty;
059: import org.netbeans.jellytools.properties.PropertySheetOperator;
060: import org.netbeans.jemmy.operators.JCheckBoxOperator;
061: import org.netbeans.jemmy.operators.JTableOperator;
062: import org.netbeans.test.oo.gui.jelly.javacvs.AddDialog;
063: import org.netbeans.test.oo.gui.jelly.javacvs.CheckoutDialog;
064: import org.netbeans.test.oo.gui.jelly.javacvs.CommitDialog;
065: import org.netbeans.test.oo.gui.jelly.javacvs.TagDialog;
066: import org.openide.filesystems.FileSystem;
067: import org.openide.filesystems.Repository;
068: import util.History;
069:
070: public abstract class JCVSStub extends GenericStub {
071:
072: public JCVSStub(String testName) {
073: super (testName);
074: nRootPrefix = "CVS ";
075: }
076:
077: static FileSystem sfs = null;
078:
079: protected FileSystem getFileSystem() {
080: return sfs;
081: }
082:
083: protected void setFileSystem(FileSystem fs) {
084: sfs = fs;
085: }
086:
087: protected void prepareServer(String dir) {
088: }
089:
090: protected static String roothis toryshort = null;
091:
092: protected void setUp() throws Exception {
093: super .setUp();
094: if (!"configure".equals(getName())) {
095: history.switchToJCVS();
096: history.setTimeout(30);
097: root.setHistoryShort(roothis toryshort);
098: }
099: }
100:
101: protected void findFS() {
102: if (!GenericStub.DEBUG) {
103: super .findFS();
104: return;
105: }
106: String normalizedClient = (nRootPrefix + clientDirectory
107: .replace('\\', '/')).toLowerCase();
108: Enumeration e = Repository.getDefault().getFileSystems();
109: while (e.hasMoreElements()) {
110: FileSystem f = (FileSystem) e.nextElement();
111: info.println("Is it?: " + f.getDisplayName());
112: String path = f.getDisplayName().replace('\\', '/')
113: .toLowerCase();
114: if (path.indexOf(normalizedClient) >= 0) {
115: info.println("Yes");
116: setFileSystem(f);
117: roothis toryshort = f.getDisplayName().substring(
118: f.getDisplayName().lastIndexOf('/') + 1);
119: return;
120: }
121: }
122: new AssertionFailedError("Filesystem not found: Filesystem: "
123: + normalizedClient);
124: }
125:
126: protected void mountVCSFileSystem() {
127: new Action("Versioning|Mount Version Control", null)
128: .performMenu(); // workaround for issue #31026
129: new Action("Tools", null).performMenu(); // workaround for issue #31026
130: sleep(10000);
131: new Action("Versioning|Mount Version Control", null)
132: .performMenu(); // workaround for issue #31026
133: new Action("Tools", null).performMenu(); // workaround for issue #31026
134: new JCVSMountAction().perform();
135:
136: WorkingDirectoryStepOperator wdso = new WorkingDirectoryStepOperator();
137: wdso.verify();
138: txtSetTypeText(wdso.cboWorkingDirectory().getTextField(),
139: clientDirectory);
140: wdso.next();
141:
142: CVSConnectionMethodStepOperator ccmsto = new CVSConnectionMethodStepOperator();
143: ccmsto.verify();
144: ccmsto.passwordServer();
145: // ccmsto.setServerName("qa-w2k-s1");
146: // ccmsto.setUserName("test");
147: // txtSetTypeText (ccmsto.txtRepository(), "d:\\apps\\vcs\\cvs\\repository");
148: // ccmsto.txtCVSROOT().waitText(":pserver:test@qa-w2k-s1:d:\\apps\\vcs\\cvs\\repository");
149: ccmsto.setServerName("mercury");
150: ccmsto.setUserName("test");
151: txtSetTypeText(ccmsto.txtRepository(), "/cvsroot");
152: ccmsto.txtCVSROOT().waitText(":pserver:test@mercury:/cvsroot");
153: ccmsto.next();
154:
155: CVSClientStepOperator ccso = new CVSClientStepOperator();
156: ccso.verify();
157: ccso.useBuiltInCVSClient();
158: ccso.next();
159:
160: CVSLoginStepOperator clso = new CVSLoginStepOperator();
161: clso.verify();
162: clso.txtPassword().clearText();
163: clso.txtPassword().typeText("test");
164: clso.login();
165: clso.txtLogin().waitText("Login successful.");
166: clso.next();
167:
168: InitialCheckoutStepOperator icso = new InitialCheckoutStepOperator();
169: icso
170: .checkCheckOutACopyOfTheRepositoryFilesToYourWorkingDirectory(false);
171: icso.finish();
172: }
173:
174: protected void prepareClient() {
175: history = new History(getFileSystem(), info);
176: history.switchToJCVS();
177: history.setTimeout(30);
178: root.setHistoryShort("client");
179:
180: closeAllVCSWindows();
181: closeAllProperties();
182:
183: root.jcvsNode().properties();
184: PropertySheetOperator pso = new PropertySheetOperator(root
185: .node());
186: ComboBoxProperty cbp = new ComboBoxProperty(pso,
187: "User Interface Mode");
188: cbp.setValue("GUI Style");
189: sleep(1000);
190: info.println("User Interface Mode property value 1: "
191: + cbp.getValue());
192: closeAllProperties();
193:
194: // stabilization
195: root.jcvsNode().properties();
196: pso = new PropertySheetOperator(root.node());
197: cbp = new ComboBoxProperty(pso, "User Interface Mode");
198: info.println("User Interface Mode property value 2: "
199: + cbp.getValue());
200: cbp.setValue("GUI Style");
201: sleep(1000);
202: info.println("User Interface Mode property value 3: "
203: + cbp.getValue());
204: closeAllProperties();
205:
206: history.setTimeout(120);
207: checkout(root, "test/jcvs");
208: history.setTimeout(30);
209: GenericNode test = new GenericNode(root, "test");
210: GenericNode jcvs = new GenericNode(test, "jcvs");
211: jcvs.waitStatus(null);
212: jcvs.jcvsNode().select();
213:
214: roothis toryshort = new SimpleDateFormat("yyMMddHHmmssSS")
215: .format(new Date(System.currentTimeMillis()));
216: GenericNode cur = new GenericNode(jcvs, roothis toryshort);
217: cur.mkdirs();
218: refresh(jcvs);
219: cur.waitStatus("Local");
220: addDirectory(cur);
221:
222: new CustomizeAction().performPopup(root.jcvsNode());
223: CVSClientCustomizerDialogOperator cus = new CVSClientCustomizerDialogOperator();
224: new Node(cus.treeSelectRelativeMountPoint(), "test|jcvs|"
225: + roothis toryshort).select();
226: cus.txtRelativeMountPoint().waitText(
227: "test" + File.separator + "jcvs" + File.separator
228: + roothis toryshort);
229: cus.ok();
230: cus.waitClosed();
231: closeAllVCSWindows();
232: for (int a = 0; a < 30; a++) {
233: if (getFileSystem().getDisplayName().endsWith(
234: roothis toryshort)) {
235: root = new GenericNode(null, getFileSystem()
236: .getDisplayName().substring(
237: nRootPrefix.length()));
238: root.setHistoryShort(roothis toryshort);
239: root.jcvsNode().select();
240: return;
241: }
242: sleep(1000);
243: }
244: throw new AssertionFailedError("New root not found: Root: "
245: + roothis toryshort);
246: }
247:
248: protected void refresh(GenericNode node) {
249: node.jcvsNode().expand(); // workaround for issue #29598
250: node.jcvsNode().jCVSRefresh();
251: node.waitHistoryShort("status -l");
252: }
253:
254: protected void refreshRecursively(GenericNode node) {
255: node.jcvsNode().expand(); // workaround for issue #29598
256: node.jcvsNode().jCVSRefreshRecursively();
257: node.waitHistoryShort("status");
258: }
259:
260: protected void addDirectory(GenericNode node) {
261: node.jcvsNode().expand(); // workaround for issue #29598
262: node.jcvsNode().jCVSAdd();
263: AddDialog add = new AddDialog();
264: add.runCommand();
265: add.waitClosed();
266: node.waitHistoryShort("add");
267: node.waitStatus(null);
268: }
269:
270: protected void checkout(GenericNode node, String what) {
271: node.jcvsNode().expand(); // workaround for issue #29598
272: node.jcvsNode().jCVSCheckOut();
273: CheckoutDialog cod = new CheckoutDialog();
274: cod.txtCheckout().clearText();
275: cod.txtCheckout().typeText(what);
276: cod.runCommand();
277: cod.waitClosed();
278: node.waitHistoryShort("checkout " + what);
279: }
280:
281: protected void addFile(GenericNode node, String desc) {
282: node.cvsNode().cVSAdd();
283: AddDialog add = new AddDialog();
284: if (desc != null) {
285: add.txtMessage().setCaretPosition(0);
286: add.txtMessage().typeText(desc);
287: }
288: add.runCommand();
289: add.waitClosed();
290: if (desc != null) {
291: if (desc.length() > 9)
292: desc = desc.substring(0, 5) + "...";
293: node.waitHistoryShort("add -m \"" + desc + "\"");
294: } else
295: node.waitHistoryShort("add");
296: node.waitStatus("LAdded; New");
297: }
298:
299: protected void commitFile(GenericNode node, String branch,
300: String desc) {
301: node.cvsNode().cVSCommit();
302: CommitDialog com = new CommitDialog();
303: if (branch != null) {
304: checkCheckBox(com.cbRevisionBranch());
305: com.txtRevisionBranch().clearText();
306: com.txtRevisionBranch().typeText(branch);
307: }
308: if (desc != null) {
309: com.txtMessage().setCaretPosition(0);
310: com.txtMessage().typeText(desc);
311: }
312: com.runCommand();
313: com.waitClosed();
314: String cmd = "commit";
315: if (branch != null)
316: cmd += " -r " + branch;
317: if (desc != null) {
318: if (desc.length() > 9)
319: desc = desc.substring(0, 5) + "...";
320: cmd += " -m \"" + desc + "\"";
321: } else
322: cmd += " -m \"\"";
323: node.waitHistoryShort(cmd);
324: node.jcvsNode().jCVSRefresh(); // workaround for unreported issue - sometimes file annotation is not updated after commit
325: node.waitHistoryShort("status -l"); // workaround for unreported issue - sometimes file annotation is not updated after commit
326: node.waitStatus("Up-to-date", false);
327: }
328:
329: public void createAddCommitFile(GenericNode node, String template) {
330: NewWizardOperator.create(template, node.parent().node(), node
331: .name());
332: node.waitStatus("Local");
333: addFile(node, "Initial");
334: commitFile(node, null, "Initial state");
335: node.waitStatus("Up-to-date; 1.1");
336: }
337:
338: public void dumpTable(JTableOperator table) {
339: out.println("==== Table Dump ====");
340: int rows = table.getRowCount();
341: out.println("Rows: " + rows);
342: int columns = table.getColumnCount();
343: out.println("Columns: " + columns);
344: for (int a = 0; a < rows; a++) {
345: out.print("" + (a + 1) + ".");
346: for (int b = 0; b < columns; b++)
347: out.print(" - " + table.getValueAt(a, b));
348: out.println();
349: }
350: }
351:
352: protected void addTagFile(GenericNode node, String name,
353: boolean branch) {
354: node.jcvsNode().jCVSTag();
355: TagDialog tag = new TagDialog();
356: checkCheckBox(tag.cbBranch(), branch);
357: tag.txtTag().clearText();
358: tag.txtTag().typeText(name);
359: tag.runCommand();
360: tag.waitClosed();
361: if (branch)
362: node.waitHistoryShort("tag -b " + name);
363: else
364: node.waitHistoryShort("tag " + name);
365: }
366:
367: protected void checkCheckBox(JCheckBoxOperator cb) {
368: checkCheckBox(cb, true);
369: }
370:
371: protected void checkCheckBox(JCheckBoxOperator cb, boolean state) {
372: if (cb.isSelected() != state)
373: cb.push();
374: }
375:
376: protected void assertCVSErrorDialog() {
377: NbDialogOperator dia = new NbDialogOperator("CVS Error");
378: dia.close();
379: dia.waitClosed();
380: }
381: }
|