KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * DeleteTest.java
3  *
4  * Created on 27 June 2006, 20:01
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.JellyTestCase;
16 import org.netbeans.jellytools.NbDialogOperator;
17 import org.netbeans.jellytools.OutputOperator;
18 import org.netbeans.jellytools.OutputTabOperator;
19 import org.netbeans.jellytools.modules.javacvs.CVSRootStepOperator;
20 import org.netbeans.jellytools.modules.javacvs.CheckoutWizardOperator;
21 import org.netbeans.jellytools.modules.javacvs.ModuleToCheckoutStepOperator;
22 import org.netbeans.jellytools.modules.javacvs.VersioningOperator;
23 import org.netbeans.jellytools.nodes.Node;
24 import org.netbeans.jellytools.nodes.SourcePackagesNode;
25 import org.netbeans.jemmy.JemmyProperties;
26 import org.netbeans.jemmy.QueueTool;
27 import org.netbeans.jemmy.TimeoutExpiredException;
28 import org.netbeans.jemmy.operators.JButtonOperator;
29 import org.netbeans.jemmy.operators.JProgressBarOperator;
30 import org.netbeans.jemmy.operators.JTableOperator;
31 import org.netbeans.jemmy.operators.Operator;
32 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
33 import org.netbeans.junit.NbTestSuite;
34 import org.netbeans.junit.ide.ProjectSupport;
35
36 /**
37  *
38  * @author peter
39  */

40 public class DeleteTest extends JellyTestCase {
41     
42     String JavaDoc os_name;
43     static String JavaDoc sessionCVSroot;
44     final String JavaDoc projectName = "ForImport";
45     final String JavaDoc pathToMain = "forimport|Main.java";
46     final String JavaDoc PROTOCOL_FOLDER = "protocol";
47     static File JavaDoc cacheFolder;
48     Operator.DefaultStringComparator comOperator;
49     Operator.DefaultStringComparator oldOperator;
50     
51     /** Creates a new instance of DeleteTest */
52     public DeleteTest(String JavaDoc name) {
53         super(name);
54     }
55     
56     /**
57      * @param args the command line arguments
58      */

59     public static void main(String JavaDoc[] args) {
60         // TODO code application logic here
61
TestRunner.run(suite());
62     }
63     
64     public static NbTestSuite suite() {
65         NbTestSuite suite = new NbTestSuite();
66         suite.addTest(new DeleteTest("testCheckOutProject"));
67         suite.addTest(new DeleteTest("testDeleteFile"));
68         suite.addTest(new DeleteTest("removeAllData"));
69         return suite;
70      }
71     
72     protected void setUp() throws Exception JavaDoc {
73         
74         os_name = System.getProperty("os.name");
75         //System.out.println(os_name);
76
System.out.println("### "+getName()+" ###");
77         
78     }
79     
80     protected boolean isUnix() {
81         boolean unix = false;
82         if (os_name.indexOf("Windows") == -1) {
83             unix = true;
84         }
85         return unix;
86     }
87     
88     public void testCheckOutProject() throws Exception JavaDoc {
89         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 36000);
90
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 36000);
91
TestKit.closeProject(projectName);
92         OutputOperator oo = OutputOperator.invoke();
93         comOperator = new Operator.DefaultStringComparator(true, true);
94         oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
95         Operator.setDefaultStringComparator(comOperator);
96         CheckoutWizardOperator cwo = CheckoutWizardOperator.invoke();
97         Operator.setDefaultStringComparator(oldOperator);
98         CVSRootStepOperator crso = new CVSRootStepOperator();
99         //JComboBoxOperator combo = new JComboBoxOperator(crso, 0);
100
crso.setCVSRoot(":pserver:anoncvs@localhost:/cvs");
101         //crso.setPassword("");
102
//crso.setPassword("test");
103

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

126         File JavaDoc tmp = new File JavaDoc("/tmp"); // NOI18N
127
File JavaDoc work = new File JavaDoc(tmp, "" + File.separator + System.currentTimeMillis());
128         cacheFolder = new File JavaDoc(work, projectName + File.separator + "src" + File.separator + "forimport" + File.separator + "CVS" + File.separator + "RevisionCache");
129         tmp.mkdirs();
130         work.mkdirs();
131         tmp.deleteOnExit();
132         ModuleToCheckoutStepOperator moduleCheck = new ModuleToCheckoutStepOperator();
133         cvss.stop();
134         in.close();
135         moduleCheck.setModule("ForImport");
136         moduleCheck.setLocalFolder(work.getAbsolutePath()); // NOI18N
137

138         //Pseudo CVS server for finishing check out wizard
139
in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "checkout_finish_2.in");
140         cvss = new PseudoCvsServer(in);
141         new Thread JavaDoc(cvss).start();
142         CVSroot = cvss.getCvsRoot();
143         //cvss.ignoreProbe();
144

145         //crso.setCVSRoot(CVSroot);
146
//combo.setSelectedItem(CVSroot);
147
System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
148         cwo.finish();
149         
150         //System.out.println(CVSroot);
151

152         OutputTabOperator oto = new OutputTabOperator(sessionCVSroot);
153         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
154         oto.waitText("Checking out finished");
155         cvss.stop();
156         in.close();
157         NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
158         JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
159         open.push();
160         
161         ProjectSupport.waitScanFinished();
162         new QueueTool().waitEmpty(1000);
163         ProjectSupport.waitScanFinished();
164         
165         //create new elements for testing
166
//TestKit.createNewElements(projectName);
167
System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
168     }
169     
170     public void testDeleteFile() throws Exception JavaDoc {
171         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 18000);
172
PseudoCvsServer cvss, cvss2, cvss3;
173         InputStream JavaDoc in, in2, in3;
174         //OutputOperator oo;
175
OutputTabOperator oto;
176         org.openide.nodes.Node nodeIDE;
177         String JavaDoc color, CVSroot;
178         VersioningOperator vo;
179         JTableOperator table;
180         
181         oto = new OutputTabOperator(sessionCVSroot);
182         oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
183         
184         TestKit.deleteRecursively(cacheFolder);
185         Node nodeMain = new Node(new SourcePackagesNode(projectName), "forimport");
186         in = TestKit.getStream(getDataDir().getCanonicalFile().toString() + File.separator + PROTOCOL_FOLDER, "show_changes_package_1.in");
187         cvss = new PseudoCvsServer(in);
188         new Thread JavaDoc(cvss).start();
189         CVSroot = cvss.getCvsRoot();
190         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", CVSroot);
191         nodeMain.performPopupAction("CVS|Show Changes");
192         Thread.sleep(1000);
193         vo = VersioningOperator.invoke();
194         cvss.stop();
195         
196         //delete file again and commit deletion
197
nodeMain = new Node(new SourcePackagesNode(projectName), pathToMain);
198         nodeMain.performPopupActionNoBlock("Delete");
199         NbDialogOperator dialog = new NbDialogOperator("Confirm Object Deletion");
200         dialog.yes();
201         Thread.sleep(1000);
202         Exception JavaDoc e = null;
203         try {
204             table = vo.tabFiles();
205             assertEquals("Files should have been [Locally Deleted]", "Locally Deleted", table.getValueAt(0, 1).toString());
206         }
207         catch (Exception JavaDoc ex) {
208             e = ex;
209         }
210         assertNull("Unexpected behavior - file should appear in Versioning view!!!", e);
211     }
212     
213     public void removeAllData() {
214         TestKit.closeProject(projectName);
215         System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
216     }
217 }
218
219
Popular Tags