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: package org.netbeans.test.cvsmodule;
042:
043: /**
044: *
045: * @author novakm
046: */
047:
048: import java.io.File;
049: import java.io.InputStream;
050: import junit.textui.TestRunner;
051: import org.netbeans.jellytools.JellyTestCase;
052: import org.netbeans.jellytools.NbDialogOperator;
053: import org.netbeans.jellytools.OutputOperator;
054: import org.netbeans.jellytools.OutputTabOperator;
055: import org.netbeans.jellytools.ProjectsTabOperator;
056: import org.netbeans.jellytools.modules.javacvs.BranchOperator;
057: import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
058: import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
059: import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
060: import org.netbeans.jellytools.modules.javacvs.SwitchToBranchOperator;
061: import org.netbeans.jellytools.nodes.Node;
062: import org.netbeans.jellytools.nodes.SourcePackagesNode;
063: import org.netbeans.jemmy.JemmyProperties;
064: import org.netbeans.jemmy.QueueTool;
065: import org.netbeans.jemmy.TimeoutExpiredException;
066: import org.netbeans.jemmy.operators.JButtonOperator;
067: import org.netbeans.jemmy.operators.JProgressBarOperator;
068: import org.netbeans.jemmy.operators.Operator;
069: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
070: import org.netbeans.junit.NbTestSuite;
071: import org.netbeans.junit.ide.ProjectSupport;
072:
073: /**
074: *
075: * @author novakm
076: */
077: public class BranchCreationAndSwitchTest extends JellyTestCase {
078:
079: /** Creates a new instance of BranchCreationAndSwitchningTest */
080: String os_name;
081: static String sessionCVSroot;
082: final String projectName = "ForImport";
083: final String pathToMain = "forimport|Main.java";
084: final String PROTOCOL_FOLDER = "protocol";
085: static File cacheFolder;
086: Operator.DefaultStringComparator comOperator;
087: Operator.DefaultStringComparator oldOperator;
088:
089: /** Creates a new instance of testIgnoreUnignoreFile */
090: public BranchCreationAndSwitchTest(String name) {
091: super (name);
092: }
093:
094: public static void main(String[] args) {
095: // TODO code application logic here
096: TestRunner.run(suite());
097: }
098:
099: protected void setUp() throws Exception {
100: os_name = System.getProperty("os.name");
101: //System.out.println(os_name);
102: System.out.println("### " + getName() + " ###");
103: }
104:
105: public static NbTestSuite suite() {
106: NbTestSuite suite = new NbTestSuite();
107: suite.addTest(new BranchCreationAndSwitchTest(
108: "testCheckOutProject"));
109: suite.addTest(new BranchCreationAndSwitchTest(
110: "testCreateBranchForProject"));
111: suite.addTest(new BranchCreationAndSwitchTest(
112: "testSwitchProjectToBranch"));
113: suite.addTest(new BranchCreationAndSwitchTest("removeAllData"));
114: return suite;
115: }
116:
117: public void testCheckOutProject() throws Exception {
118: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
119: //JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
120:
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:
132: //prepare stream for successful authentification and run PseudoCVSServer
133: InputStream in = TestKit.getStream(getDataDir()
134: .getCanonicalFile().toString()
135: + File.separator + PROTOCOL_FOLDER, "authorized.in");
136: PseudoCvsServer cvss = new PseudoCvsServer(in);
137: new Thread(cvss).start();
138: cvss.ignoreProbe();
139: String CVSroot = cvss.getCvsRoot();
140: sessionCVSroot = CVSroot;
141: crso.setCVSRoot(CVSroot);
142: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
143: CVSroot);
144: crso.next();
145:
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: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
190: }
191:
192: public void testCreateBranchForProject() throws Exception {
193: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
194: PseudoCvsServer cvss;
195: InputStream in;
196: OutputTabOperator oto;
197: String CVSroot;
198: oto = new OutputTabOperator(sessionCVSroot);
199: oto.getTimeouts().setTimeout(
200: "ComponentOperator.WaitStateTimeout", 30000);
201: Node rootNode = new ProjectsTabOperator()
202: .getProjectRootNode(projectName);
203: in = TestKit.getStream(getDataDir().getCanonicalFile()
204: .toString()
205: + File.separator + PROTOCOL_FOLDER,
206: "cvs_60_create_branch.in");
207: cvss = new PseudoCvsServer(in);
208: new Thread(cvss).start();
209: CVSroot = cvss.getCvsRoot();
210: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
211: CVSroot);
212: BranchOperator bo = BranchOperator.invoke(rootNode);
213: bo.setBranchName("MyNewBranch");
214: bo.checkSwitchToThisBranchAftewards(false);
215: bo.checkTagBeforeBranching(false);
216: oto = new OutputTabOperator(sessionCVSroot);
217: oto.getTimeouts().setTimeout(
218: "ComponentOperator.WaitStateTimeout", 30000);
219: bo.branch();
220: Thread.sleep(1000);
221: oto.waitText("Branch");
222: oto.waitText("ForImport");
223: oto.waitText("finished");
224: cvss.stop();
225: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
226: }
227:
228: public void testSwitchProjectToBranch() throws Exception {
229: //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
230: PseudoCvsServer cvss;
231: InputStream in;
232: OutputTabOperator oto;
233: org.openide.nodes.Node nodeIDE;
234: String cvsRoot;
235: oto = new OutputTabOperator(sessionCVSroot);
236: oto.getTimeouts().setTimeout(
237: "ComponentOperator.WaitStateTimeout", 30000);
238: Node rootNode = new ProjectsTabOperator()
239: .getProjectRootNode(projectName);
240: in = TestKit.getStream(getDataDir().getCanonicalFile()
241: .toString()
242: + File.separator + PROTOCOL_FOLDER,
243: "cvs_60_switch_branch.in");
244: cvss = new PseudoCvsServer(in);
245: new Thread(cvss).start();
246: cvsRoot = cvss.getCvsRoot();
247: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT",
248: cvsRoot);
249: oto = new OutputTabOperator(sessionCVSroot);
250: oto.getTimeouts().setTimeout(
251: "ComponentOperator.WaitStateTimeout", 30000);
252: SwitchToBranchOperator sbo = SwitchToBranchOperator
253: .invoke(rootNode);
254: sbo.switchToBranch();
255: sbo.setBranch("MyNewBranch");
256: sbo.pushSwitch();
257: Thread.sleep(1000);
258: oto.waitText(" to Branch finished");
259: cvss.stop();
260: // test branch annotation
261: TestKit.showStatusLabels();
262: Node nodeFile = new Node(new SourcePackagesNode(projectName),
263: "ForImport" + "|Main.java");
264: nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
265: String status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
266: boolean comparison = status.equals("[; MyNewBranch]");
267: assertEquals("Wrong annotation of node!!!", true, comparison);
268: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
269: }
270:
271: public void removeAllData() throws Exception {
272: TestKit.closeProject(projectName);
273: System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
274: }
275: }
|