KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > cvsmodule > BranchCreationAndSwitchTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.test.cvsmodule;
20
21 /**
22  *
23  * @author novakm
24  */

25
26 import java.io.File JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import junit.textui.TestRunner;
29 import org.netbeans.jellytools.JellyTestCase;
30 import org.netbeans.jellytools.NbDialogOperator;
31 import org.netbeans.jellytools.OutputOperator;
32 import org.netbeans.jellytools.OutputTabOperator;
33 import org.netbeans.jellytools.ProjectsTabOperator;
34 import org.netbeans.jellytools.modules.javacvs.BranchOperator;
35 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
36 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
37 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
38 import org.netbeans.jellytools.modules.javacvs.SwitchToBranchOperator;
39 import org.netbeans.jellytools.nodes.Node;
40 import org.netbeans.jellytools.nodes.SourcePackagesNode;
41 import org.netbeans.jemmy.JemmyProperties;
42 import org.netbeans.jemmy.QueueTool;
43 import org.netbeans.jemmy.TimeoutExpiredException;
44 import org.netbeans.jemmy.operators.JButtonOperator;
45 import org.netbeans.jemmy.operators.JProgressBarOperator;
46 import org.netbeans.jemmy.operators.Operator;
47 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
48 import org.netbeans.junit.NbTestSuite;
49 import org.netbeans.junit.ide.ProjectSupport;
50
51
52 /**
53  *
54  * @author novakm
55  */

56 public class BranchCreationAndSwitchTest extends JellyTestCase {
57     
58     /** Creates a new instance of BranchCreationAndSwitchningTest */
59     String JavaDoc os_name;
60     static String JavaDoc sessionCVSroot;
61     final String JavaDoc projectName = "ForImport";
62     final String JavaDoc pathToMain = "forimport|Main.java";
63     final String JavaDoc PROTOCOL_FOLDER = "protocol";
64     static File JavaDoc cacheFolder;
65     Operator.DefaultStringComparator comOperator;
66     Operator.DefaultStringComparator oldOperator;
67     
68     /** Creates a new instance of testIgnoreUnignoreFile */
69     public BranchCreationAndSwitchTest(String JavaDoc name) {
70         super(name);
71     }
72     
73     public static void main(String JavaDoc[] args) {
74         // TODO code application logic here
75
TestRunner.run(suite());
76     }
77     
78     protected void setUp() throws Exception JavaDoc {
79         os_name = System.getProperty("os.name");
80         //System.out.println(os_name);
81
System.out.println("### " + getName() + " ###");
82     }
83     
84     public static NbTestSuite suite() {
85         NbTestSuite suite = new NbTestSuite();
86         suite.addTest(new BranchCreationAndSwitchTest("testCheckOutProject"));
87         suite.addTest(new BranchCreationAndSwitchTest("testCreateBranchForProject"));
88         suite.addTest(new BranchCreationAndSwitchTest("testSwitchProjectToBranch"));
89         suite.addTest(new BranchCreationAndSwitchTest("removeAllData"));
90         return suite;
91     }
92     
93     public void testCheckOutProject() throws Exception JavaDoc {
94         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
95
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
96

97         TestKit.closeProject(projectName);
98         comOperator = new Operator.DefaultStringComparator(true, true);
99         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
100         Operator.setDefaultStringComparator(comOperator);
101         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
102         Operator.setDefaultStringComparator(oldOperator);
103         CVSRootStepOperator crso = new CVSRootStepOperator();
104         crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
105         
106         //prepare stream for successful authentification and run PseudoCVSServer
107
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
108         PseudoCvsServer cvss = new PseudoCvsServer(in);
109         new Thread JavaDoc(cvss).start();
110         cvss.ignoreProbe();
111         String JavaDoc CVSroot = cvss.getCvsRoot();
112         sessionCVSroot = CVSroot;
113         crso.setCVSRoot(CVSroot);
114         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
115         crso.next();
116         try {
117             JProgressBarOperator progress = new JProgressBarOperator(crso);
118             JButtonOperator btnStop = new JButtonOperator(crso);
119         } catch (TimeoutExpiredException e) {
120             throw e;
121         }
122         //2nd step of CheckOutWizard
123
File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
124
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
125         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
126         tmp.mkdirs();
127         work.mkdirs();
128         tmp.deleteOnExit();
129         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
130         cvss.stop();
131         in.close();
132         moduleCheck.setModule("ForImport");
133         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
134
//Pseudo CVS server for finishing check out wizard
135
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
136         cvss = new PseudoCvsServer(in);
137         new Thread JavaDoc(cvss).start();
138         CVSroot = cvss.getCvsRoot();
139         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
140         cwo.finish();
141         OutputOperator oo = OutputOperator.invoke();
142         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
143         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
144         oto.waitText("Checking out finished");
145         cvss.stop();
146         in.close();
147         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
148         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
149         open.push();
150         
151         ProjectSupport.waitScanFinished();
152         new QueueTool().waitEmpty(1000);
153         ProjectSupport.waitScanFinished();
154         
155         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
156     }
157     
158     public void testCreateBranchForProject() throws Exception JavaDoc {
159         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
160
PseudoCvsServer cvss;
161         InputStream JavaDoc in;
162         OutputTabOperator oto;
163         String JavaDoc CVSroot;
164         oto = new OutputTabOperator(sessionCVSroot);
165         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
166         Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName);
167         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "cvs_60_create_branch.in");
168         cvss = new PseudoCvsServer(in);
169         new Thread JavaDoc(cvss).start();
170         CVSroot = cvss.getCvsRoot();
171         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
172         BranchOperator bo = BranchOperator.invoke(rootNode);
173         bo.setBranchName("MyNewBranch");
174         bo.checkSwitchToThisBranchAftewards(false);
175         bo.checkTagBeforeBranching(false);
176         oto = new OutputTabOperator(sessionCVSroot);
177         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
178         bo.branch();
179         Thread.sleep(1000);
180         oto.waitText("Branch");
181         oto.waitText("ForImport");
182         oto.waitText("finished");
183         cvss.stop();
184         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
185     }
186     public void testSwitchProjectToBranch() throws Exception JavaDoc {
187         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
188
PseudoCvsServer cvss;
189         InputStream JavaDoc in;
190         OutputTabOperator oto;
191         org.openide.nodes.Node nodeIDE;
192         String JavaDoc cvsRoot;
193         oto = new OutputTabOperator(sessionCVSroot);
194         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
195         Node rootNode = new ProjectsTabOperator().getProjectRootNode(projectName);
196         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "cvs_60_switch_branch.in");
197         cvss = new PseudoCvsServer(in);
198         new Thread JavaDoc(cvss).start();
199         cvsRoot = cvss.getCvsRoot();
200         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvsRoot);
201         oto = new OutputTabOperator(sessionCVSroot);
202         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
203         SwitchToBranchOperator sbo = SwitchToBranchOperator.invoke(rootNode);
204         sbo.switchToBranch();
205         sbo.setBranch("MyNewBranch");
206         sbo.pushSwitch();
207         Thread.sleep(1000);
208         oto.waitText(" to Branch finished");
209         cvss.stop();
210         // test branch annotation
211
TestKit.showStatusLabels();
212         Node nodeFile = new Node(new SourcePackagesNode(projectName), "ForImport" + "|Main.java");
213         nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
214         String JavaDoc status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
215         boolean comparison = status.equals("[; MyNewBranch]");
216         assertEquals("Wrong annotation of node!!!", true, comparison);
217         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
218     }
219     
220     
221     public void removeAllData() throws Exception JavaDoc {
222         TestKit.closeProject(projectName);
223         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
224     }
225 }
Popular Tags