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