KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 /*
21  * ResolveConflictsAndRevertTest.java
22  *
23  * Created on 18. prosinec 2006, 11:21
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

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

58 public class ResolveConflictsAndRevertTest extends JellyTestCase {
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 ResolveConflictsAndRevertTest */
69     public ResolveConflictsAndRevertTest(String JavaDoc name) {
70         super(name);
71     }
72     public static void main(String JavaDoc[] args) {
73         // TODO code application logic here
74
TestRunner.run(suite());
75     }
76     
77     protected void setUp() throws Exception JavaDoc {
78         os_name = System.getProperty("os.name");
79         //System.out.println(os_name);
80
System.out.println("### " + getName() + " ###");
81     }
82     
83     public static NbTestSuite suite() {
84         NbTestSuite suite = new NbTestSuite();
85         suite.addTest(new ResolveConflictsAndRevertTest("testCheckOutProject"));
86         suite.addTest(new ResolveConflictsAndRevertTest("testResolveConflicts"));
87         suite.addTest(new ResolveConflictsAndRevertTest("testRevertModifications"));
88         // suite.addTest(new ResolveConflictsAndRevertTest("removeAllData"));
89
return suite;
90     }
91     
92     public void testCheckOutProject() throws Exception JavaDoc {
93         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
94
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
95
TestKit.closeProject(projectName);
96         comOperator = new Operator.DefaultStringComparator(true, true);
97         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
98         Operator.setDefaultStringComparator(comOperator);
99         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
100         Operator.setDefaultStringComparator(oldOperator);
101         CVSRootStepOperator crso = new CVSRootStepOperator();
102         crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
103         //prepare stream for successful authentification and run PseudoCVSServer
104
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
105         PseudoCvsServer cvss = new PseudoCvsServer(in);
106         new Thread JavaDoc(cvss).start();
107         cvss.ignoreProbe();
108         String JavaDoc CVSroot = cvss.getCvsRoot();
109         sessionCVSroot = CVSroot;
110         crso.setCVSRoot(CVSroot);
111         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
112         crso.next();
113         try {
114             JProgressBarOperator progress = new JProgressBarOperator(crso);
115             JButtonOperator btnStop = new JButtonOperator(crso);
116         } catch (TimeoutExpiredException e) {
117             throw e;
118         }
119         //2nd step of CheckOutWizard
120
File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
121
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
122         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
123         tmp.mkdirs();
124         work.mkdirs();
125         tmp.deleteOnExit();
126         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
127         cvss.stop();
128         in.close();
129         moduleCheck.setModule("ForImport");
130         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
131
//Pseudo CVS server for finishing check out wizard
132
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
133         cvss = new PseudoCvsServer(in);
134         new Thread JavaDoc(cvss).start();
135         CVSroot = cvss.getCvsRoot();
136         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
137         cwo.finish();
138         OutputOperator oo = OutputOperator.invoke();
139         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
140         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
141         oto.waitText("Checking out finished");
142         cvss.stop();
143         in.close();
144         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
145         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
146         open.push();
147         
148         ProjectSupport.waitScanFinished();
149         new QueueTool().waitEmpty(1000);
150         ProjectSupport.waitScanFinished();
151         
152         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
153     }
154     
155     public void testResolveConflicts() throws Exception JavaDoc {
156         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
157
PseudoCvsServer cvss;
158         InputStream JavaDoc in;
159         OutputTabOperator oto;
160         org.openide.nodes.Node nodeIDE;
161         String JavaDoc color;
162         
163         oto = new OutputTabOperator(sessionCVSroot);
164         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
165         oto.clear();
166         
167         Node nodeClass = new Node(new SourcePackagesNode(projectName), pathToMain);
168         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "diff/create_conflict.in");
169         cvss = new PseudoCvsServer(in);
170         new Thread JavaDoc(cvss).start();
171         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
172         nodeClass.performPopupActionNoBlock("CVS|Update");
173         NbDialogOperator dialog = new NbDialogOperator("Warning");
174         dialog.ok();
175         oto.waitText("cvs server: conflicts found in Main.java");
176         oto.waitText("Updating \"Main.java\" finished");
177         Thread.sleep(1000);
178         cvss.stop();
179         
180         nodeClass = new Node(new SourcePackagesNode(projectName), pathToMain);
181         nodeIDE = (org.openide.nodes.Node) nodeClass.getOpenideNode();
182         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
183         assertEquals("Wrong color for file in conflict", TestKit.CONFLICT_COLOR, color);
184         // todo - resolvnout pomoci accept&next , zkontrolovat pocet konfilktu a OK
185
// nodeClass.performPopupActionNoBlock("CVS|Resolve Conflicts...");
186
// pri revert modifications pri otevrenem conflict resolveru lita vyjimka!
187
System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
188     }
189     
190     public void testRevertModifications() throws Exception JavaDoc {
191         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
192
PseudoCvsServer cvss;
193         InputStream JavaDoc in;
194         OutputTabOperator oto;
195         org.openide.nodes.Node nodeIDE;
196         oto = new OutputTabOperator(sessionCVSroot);
197         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
198         oto.clear();
199         //delete RevsionCache folder. It can contain checked out revisions
200
TestKit.deleteRecursively(cacheFolder);
201         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "revert_modifications.in");
202         cvss = new PseudoCvsServer(in);
203         new Thread JavaDoc(cvss).start();
204         Node nodeMain = new Node(new SourcePackagesNode("ForImport"), "forimport|Main.java");
205         nodeMain.performPopupActionNoBlock("CVS|Revert Modifications");
206         NbDialogOperator nbDialog = new NbDialogOperator("Confirm overwrite");
207         JButtonOperator btnYes = new JButtonOperator(nbDialog, "Yes");
208         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", cvss.getCvsRoot());
209         btnYes.push();
210         Thread.sleep(1000);
211         oto = new OutputTabOperator(sessionCVSroot);
212         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
213         oto.waitText("Reverting finished");
214         cvss.stop();
215         nodeIDE = (org.openide.nodes.Node) nodeMain.getOpenideNode();
216         assertNull("No color for node expected", nodeIDE.getHtmlDisplayName());
217         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
218     }
219     
220     public void removeAllData() throws Exception JavaDoc {
221         TestKit.closeProject(projectName);
222         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
223     }
224 }
225
Popular Tags