KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * UpdateErrorTest.java
3  *
4  * Created on 25 August 2006, 16:42
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.test.cvsmodule;
11
12 import java.io.File JavaDoc;
13 import java.io.InputStream JavaDoc;
14 import junit.textui.TestRunner;
15 import org.netbeans.jellytools.EditorOperator;
16 import org.netbeans.jellytools.JellyTestCase;
17 import org.netbeans.jellytools.NbDialogOperator;
18 import org.netbeans.jellytools.OutputOperator;
19 import org.netbeans.jellytools.OutputTabOperator;
20 import org.netbeans.jellytools.ProjectsTabOperator;
21 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
22 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
23 import org.netbeans.jellytools.modules.javacvs.CommitOperator;
24 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
25 import org.netbeans.jellytools.modules.javacvs.VersioningOperator;
26 import org.netbeans.jellytools.nodes.Node;
27 import org.netbeans.jellytools.nodes.SourcePackagesNode;
28 import org.netbeans.jemmy.JemmyProperties;
29 import org.netbeans.jemmy.QueueTool;
30 import org.netbeans.jemmy.TimeoutExpiredException;
31 import org.netbeans.jemmy.operators.JButtonOperator;
32 import org.netbeans.jemmy.operators.JProgressBarOperator;
33 import org.netbeans.jemmy.operators.JTableOperator;
34 import org.netbeans.jemmy.operators.Operator;
35 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
36 import org.netbeans.junit.NbTestSuite;
37 import org.netbeans.junit.ide.ProjectSupport;
38
39 /**
40  *
41  * @author peter
42  */

43 public class UpdateErrorTest extends JellyTestCase {
44     
45     String JavaDoc os_name;
46     static String JavaDoc sessionCVSroot;
47     final String JavaDoc projectName = "ForImport";
48     final String JavaDoc pathToMain = "forimport|Main.java";
49     static File JavaDoc cacheFolder;
50     String JavaDoc PROTOCOL_FOLDER = "protocol";
51     Operator.DefaultStringComparator comOperator;
52     Operator.DefaultStringComparator oldOperator;
53     
54     /**
55      * Creates a new instance of UpdateErrorTest
56      */

57     public UpdateErrorTest(String JavaDoc name) {
58         super(name);
59     }
60     
61     public static void main(String JavaDoc[] args) {
62         // TODO code application logic here
63
TestRunner.run(suite());
64     }
65     
66     protected void setUp() throws Exception JavaDoc {
67         os_name = System.getProperty("os.name");
68         //System.out.println(os_name);
69
System.out.println("### " + getName() + " ###");
70     }
71
72     public static NbTestSuite suite() {
73         NbTestSuite suite = new NbTestSuite();
74         suite.addTest(new UpdateErrorTest("testCheckOutProject"));
75         suite.addTest(new UpdateErrorTest("testUpdate"));
76         suite.addTest(new UpdateErrorTest("removeAllData"));
77         return suite;
78     }
79     
80     public void testCheckOutProject() throws Exception JavaDoc {
81         PROTOCOL_FOLDER = "protocol";
82         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
83
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 18000);
84
TestKit.closeProject(projectName);
85         comOperator = new Operator.DefaultStringComparator(true, true);
86         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
87         Operator.setDefaultStringComparator(comOperator);
88         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
89         Operator.setDefaultStringComparator(oldOperator);
90         CVSRootStepOperator crso = new CVSRootStepOperator();
91         //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
92
crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
93         //crso.setPassword("");
94
//crso.setPassword("test");
95

96         //prepare stream for successful authentification and run PseudoCVSServer
97
InputStream JavaDoc in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "authorized.in");
98         PseudoCvsServer cvss = new PseudoCvsServer(in);
99         new Thread JavaDoc(cvss).start();
100         cvss.ignoreProbe();
101         String JavaDoc CVSroot = cvss.getCvsRoot();
102         sessionCVSroot = CVSroot;
103         //System.out.println(sessionCVSroot);
104
crso.setCVSRoot(CVSroot);
105         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
106         crso.next();
107               
108         try {
109            JProgressBarOperator progress = new JProgressBarOperator(crso);
110            JButtonOperator btnStop = new JButtonOperator(crso);
111         } catch (TimeoutExpiredException e) {
112             throw e;
113         }
114         
115         //second step of checkoutwizard
116
//2nd step of CheckOutWizard
117

118         File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
119
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
120         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
121         tmp.mkdirs();
122         work.mkdirs();
123         tmp.deleteOnExit();
124         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
125         cvss.stop();
126         in.close();
127         moduleCheck.setModule("ForImport");
128         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
129

130         //Pseudo CVS server for finishing check out wizard
131
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
132         cvss = new PseudoCvsServer(in);
133         new Thread JavaDoc(cvss).start();
134         CVSroot = cvss.getCvsRoot();
135         //cvss.ignoreProbe();
136

137         //crso.setCVSRoot(CVSroot);
138
//combo.setSelectedItem(CVSroot);
139
System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
140         cwo.finish();
141         
142         OutputOperator oo = OutputOperator.invoke();
143         //System.out.println(CVSroot);
144

145         OutputTabOperator oto = oo.getOutputTab(sessionCVSroot);
146         oto.waitText("Checking out finished");
147         cvss.stop();
148         in.close();
149         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
150         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
151         open.push();
152         
153         ProjectSupport.waitScanFinished();
154         new QueueTool().waitEmpty(1000);
155         ProjectSupport.waitScanFinished();
156         
157         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
158     }
159     
160     public void testUpdate() throws Exception JavaDoc {
161         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
162
PseudoCvsServer cvss, cvss2, cvss3;
163         InputStream JavaDoc in, in2, in3;
164         CommitOperator co;
165         String JavaDoc CVSroot, color;
166         JTableOperator table;
167         OutputOperator oo;
168         OutputTabOperator oto;
169         VersioningOperator vo;
170         String JavaDoc[] expected;
171         String JavaDoc[] actual;
172         String JavaDoc allCVSRoots;
173         org.openide.nodes.Node nodeIDE;
174         PROTOCOL_FOLDER = "protocol" + File.separator + "update_access_denied";
175         
176         vo = VersioningOperator.invoke();
177         oo = OutputOperator.invoke();
178         oto = oo.getOutputTab(sessionCVSroot);
179         
180         Node node = new Node(new SourcePackagesNode("ForImport"), "forimport|Main.java");
181         node.performPopupAction("Open");
182         EditorOperator eo = new EditorOperator("Main.java");
183         eo.deleteLine(2);
184         eo.insert(" a", 3, 4);
185         eo.save();
186         //
187
oto = oo.getOutputTab(sessionCVSroot);
188         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
189         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_package.in");
190         cvss = new PseudoCvsServer(in);
191         new Thread JavaDoc(cvss).start();
192         CVSroot = cvss.getCvsRoot();
193         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
194         node = new Node(new SourcePackagesNode("ForImport"), "forimport");
195         node.performPopupAction("CVS|Show Changes");
196         Thread.sleep(1000);
197         oto.waitText("Refreshing");
198         oto.waitText("finished");
199         cvss.stop();
200         
201         assertEquals("File should be listed in Versioning view", "Main.java", vo.tabFiles().getValueAt(0, 0).toString());
202         
203         node = new Node(new SourcePackagesNode("ForImport"), "forimport|Main.java");
204         nodeIDE = (org.openide.nodes.Node) node.getOpenideNode();
205         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
206         assertEquals("Wrong color of node!!!", TestKit.MODIFIED_COLOR, color);
207         
208         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "update_access_denied.in");
209         cvss = new PseudoCvsServer(in);
210         new Thread JavaDoc(cvss).start();
211         CVSroot = cvss.getCvsRoot();
212         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
213         node = ProjectsTabOperator.invoke().getProjectRootNode("ForImport");
214         //oto = oo.getOutputTab(sessionCVSroot);
215
oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
216         node.performPopupAction("CVS|Update");
217         Thread.sleep(1000);
218         cvss.stop();
219         oto.waitText("Updating");
220         oto.waitText("finished");
221         
222         NbDialogOperator dialog = new NbDialogOperator("Command");
223         JButtonOperator btn = new JButtonOperator(dialog, "Ok");
224         btn.push();
225         
226         Thread.sleep(1000);
227         node = new Node(new SourcePackagesNode("ForImport"), "forimport|Main.java");
228         nodeIDE = (org.openide.nodes.Node) node.getOpenideNode();
229         color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
230         assertEquals("Wrong color of node. Modified file can't be changed to up-to-date. See issue http://www.netbeans.org/issues/show_bug.cgi?id=83476!!!", TestKit.MODIFIED_COLOR, color);
231         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
232         
233     }
234     
235     public void removeAllData() throws Exception JavaDoc {
236         TestKit.closeProject(projectName);
237         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
238     }
239     
240 }
241
Popular Tags