KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > main > delete > DeleteTest


1 /*
2  * DeleteTest.java
3  *
4  * Created on August 17, 2006, 10:56 AM
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.subversion.main.delete;
11
12 import java.io.File JavaDoc;
13 import java.io.PrintStream JavaDoc;
14 import junit.textui.TestRunner;
15 import org.netbeans.jellytools.JellyTestCase;
16 import org.netbeans.jellytools.NbDialogOperator;
17 import org.netbeans.jellytools.OutputTabOperator;
18 import org.netbeans.jellytools.nodes.Node;
19 import org.netbeans.jellytools.nodes.SourcePackagesNode;
20 import org.netbeans.jemmy.JemmyProperties;
21 import org.netbeans.jemmy.QueueTool;
22 import org.netbeans.jemmy.operators.JButtonOperator;
23 import org.netbeans.jemmy.operators.JTableOperator;
24 import org.netbeans.jemmy.operators.Operator;
25 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
26 import org.netbeans.junit.NbTestSuite;
27 import org.netbeans.junit.ide.ProjectSupport;
28 import org.netbeans.test.subversion.operators.CheckoutWizardOperator;
29 import org.netbeans.test.subversion.operators.CommitOperator;
30 import org.netbeans.test.subversion.operators.RepositoryStepOperator;
31 import org.netbeans.test.subversion.operators.RevertModificationsOperator;
32 import org.netbeans.test.subversion.operators.VersioningOperator;
33 import org.netbeans.test.subversion.operators.WorkDirStepOperator;
34 import org.netbeans.test.subversion.utils.RepositoryMaintenance;
35 import org.netbeans.test.subversion.utils.TestKit;
36
37 /**
38  *
39  * @author pvcs
40  */

41 public class DeleteTest extends JellyTestCase {
42     
43     public static final String JavaDoc TMP_PATH = "/tmp";
44     public static final String JavaDoc REPO_PATH = "repo";
45     public static final String JavaDoc WORK_PATH = "work";
46     public static final String JavaDoc PROJECT_NAME = "JavaApp";
47     public File JavaDoc projectPath;
48     public PrintStream JavaDoc stream;
49     String JavaDoc os_name;
50     Operator.DefaultStringComparator comOperator;
51     Operator.DefaultStringComparator oldOperator;
52     
53     /** Creates a new instance of DeleteTest */
54     public DeleteTest(String JavaDoc name) {
55         super(name);
56     }
57     
58     protected void setUp() throws Exception JavaDoc {
59         os_name = System.getProperty("os.name");
60         //System.out.println(os_name);
61
System.out.println("### "+getName()+" ###");
62         
63     }
64     
65     protected boolean isUnix() {
66         boolean unix = false;
67         if (os_name.indexOf("Windows") == -1) {
68             unix = true;
69         }
70         return unix;
71     }
72     
73     public static void main(String JavaDoc[] args) {
74         // TODO code application logic here
75
TestRunner.run(suite());
76     }
77     
78     public static NbTestSuite suite() {
79         NbTestSuite suite = new NbTestSuite();
80         suite.addTest(new DeleteTest("testDeleteRevert"));
81         suite.addTest(new DeleteTest("testDeleteCommit"));
82         return suite;
83     }
84     
85     public void testDeleteRevert() throws Exception JavaDoc {
86         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
87
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
88
try {
89             TestKit.closeProject(PROJECT_NAME);
90             
91             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
92             VersioningOperator vo = VersioningOperator.invoke();
93             comOperator = new Operator.DefaultStringComparator(true, true);
94             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
95             Operator.setDefaultStringComparator(comOperator);
96             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
97             Operator.setDefaultStringComparator(oldOperator);
98             RepositoryStepOperator rso = new RepositoryStepOperator();
99             
100             //create repository...
101
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
102             new File JavaDoc(TMP_PATH).mkdirs();
103             work.mkdirs();
104             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
105             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
106
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
107             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
108             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
109             
110             rso.next();
111             WorkDirStepOperator wdso = new WorkDirStepOperator();
112             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
113             wdso.setLocalFolder(work.getCanonicalPath());
114             wdso.checkCheckoutContentOnly(false);
115             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
116             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
117             oto.clear();
118             wdso.finish();
119             //open project
120
oto.waitText("Checking out... finished.");
121             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
122             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
123             open.push();
124             
125             ProjectSupport.waitScanFinished();
126             new QueueTool().waitEmpty(1000);
127             ProjectSupport.waitScanFinished();
128             
129             oto = new OutputTabOperator("file:///tmp/repo");
130             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
131             oto.clear();
132             Node node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
133             node.performPopupAction("Subversion|Show Changes");
134             oto.waitText("Refreshing... finished.");
135             node.performPopupActionNoBlock("Delete");
136             NbDialogOperator dialog = new NbDialogOperator("Confirm Object Deletion");
137             dialog.yes();
138             
139             Thread.sleep(1000);
140             vo = VersioningOperator.invoke();
141             JTableOperator table;
142             Exception JavaDoc e = null;
143             try {
144                 table = vo.tabFiles();
145                 assertEquals("Files should have been [Locally Deleted]", "Locally Deleted", table.getValueAt(0, 1).toString());
146             } catch (Exception JavaDoc ex) {
147                 e = ex;
148             }
149             assertNull("Unexpected behavior - file should appear in Versioning view!!!", e);
150             
151             e = null;
152             try {
153                 node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java");
154             } catch (Exception JavaDoc ex) {
155                 e = ex;
156             }
157             assertNotNull("TimeoutExpiredException should have been thrown. Deleted file can't be visible!!!", e);
158             
159             //revert local changes
160

161             oto = new OutputTabOperator("file:///tmp/repo");
162             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
163             oto.clear();
164             node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
165             RevertModificationsOperator rmo = RevertModificationsOperator.invoke(node);
166             rmo.rbLocalChanges().push();
167             rmo.revert();
168             oto.waitText("Modifications finished.");
169             
170             e = null;
171             try {
172                 vo = VersioningOperator.invoke();
173                 table = vo.tabFiles();
174             } catch (Exception JavaDoc ex) {
175                 e = ex;
176             }
177             assertNotNull("Unexpected behavior - file should disappear in Versioning view!!!", e);
178             
179             e = null;
180             try {
181                 node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java");
182             } catch (Exception JavaDoc ex) {
183                 e = ex;
184             }
185             assertNull("Reverted file should be visible!!!", e);
186             
187         } catch (Exception JavaDoc e) {
188             throw new Exception JavaDoc("Test failed: " + e);
189         } finally {
190             TestKit.closeProject(PROJECT_NAME);
191         }
192     }
193     
194     public void testDeleteCommit() throws Exception JavaDoc {
195         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
196
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
197
try {
198             TestKit.closeProject(PROJECT_NAME);
199             
200             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
201             VersioningOperator vo = VersioningOperator.invoke();
202             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
203             RepositoryStepOperator rso = new RepositoryStepOperator();
204             
205             //create repository...
206
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
207             new File JavaDoc(TMP_PATH).mkdirs();
208             work.mkdirs();
209             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
210             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
211
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
212             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
213             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
214             
215             rso.next();
216             WorkDirStepOperator wdso = new WorkDirStepOperator();
217             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
218             wdso.setLocalFolder(work.getCanonicalPath());
219             wdso.checkCheckoutContentOnly(false);
220             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
221             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
222             oto.clear();
223             wdso.finish();
224             //open project
225
oto.waitText("Checking out... finished.");
226             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
227             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
228             open.push();
229             
230             ProjectSupport.waitScanFinished();
231             new QueueTool().waitEmpty(1000);
232             ProjectSupport.waitScanFinished();
233             
234             oto = new OutputTabOperator("file:///tmp/repo");
235             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
236             oto.clear();
237             Node node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
238             node.performPopupAction("Subversion|Show Changes");
239             oto.waitText("Refreshing... finished.");
240             node.performPopupActionNoBlock("Delete");
241             NbDialogOperator dialog = new NbDialogOperator("Confirm Object Deletion");
242             dialog.yes();
243             
244             Thread.sleep(1000);
245             vo = VersioningOperator.invoke();
246             JTableOperator table;
247             Exception JavaDoc e = null;
248             try {
249                 table = vo.tabFiles();
250                 assertEquals("Files should have been [Locally Deleted]", "Locally Deleted", table.getValueAt(0, 1).toString());
251             } catch (Exception JavaDoc ex) {
252                 e = ex;
253             }
254             assertNull("Unexpected behavior - file should appear in Versioning view!!!", e);
255             
256             e = null;
257             try {
258                 node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java");
259             } catch (Exception JavaDoc ex) {
260                 e = ex;
261             }
262             assertNotNull("TimeoutExpiredException should have been thrown. Deleted file can't be visible!!!", e);
263             
264             //commit deleted file
265
oto = new OutputTabOperator("file:///tmp/repo");
266             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
267             oto.clear();
268             node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
269             CommitOperator cmo = CommitOperator.invoke(node);
270             assertEquals("There should be \"Main.java\" file in Commit dialog!!!", cmo.tabFiles().getValueAt(0, 0), "Main.java");
271             cmo.commit();
272             oto.waitText("finished.");
273             
274             e = null;
275             try {
276                 vo = VersioningOperator.invoke();
277                 table = vo.tabFiles();
278             } catch (Exception JavaDoc ex) {
279                 e = ex;
280             }
281             assertNotNull("Unexpected behavior - file should disappear in Versioning view!!!", e);
282             
283             e = null;
284             try {
285                 node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java");
286             } catch (Exception JavaDoc ex) {
287                 e = ex;
288             }
289             assertNotNull("Deleteted file should be visible!!!", e);
290             
291         } catch (Exception JavaDoc e) {
292             throw new Exception JavaDoc("Test failed: " + e);
293         } finally {
294             TestKit.closeProject(PROJECT_NAME);
295         }
296     }
297 }
298
Popular Tags