KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > main > commit > CommitDataTest


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

43 public class CommitDataTest extends JellyTestCase {
44     
45     public static final String JavaDoc TMP_PATH = "/tmp";
46     public static final String JavaDoc REPO_PATH = "repo";
47     public static final String JavaDoc WORK_PATH = "work";
48     public static final String JavaDoc PROJECT_NAME = "JavaApp";
49     public File JavaDoc projectPath;
50     public PrintStream JavaDoc stream;
51     String JavaDoc os_name;
52     Operator.DefaultStringComparator comOperator;
53     Operator.DefaultStringComparator oldOperator;
54     
55     /** Creates a new instance of CommitDataTest */
56     public CommitDataTest(String JavaDoc name) {
57         super(name);
58     }
59     
60     protected void setUp() throws Exception JavaDoc {
61         os_name = System.getProperty("os.name");
62         //System.out.println(os_name);
63
System.out.println("### "+getName()+" ###");
64         
65     }
66     
67     protected boolean isUnix() {
68         boolean unix = false;
69         if (os_name.indexOf("Windows") == -1) {
70             unix = true;
71         }
72         return unix;
73     }
74     
75     public static void main(String JavaDoc[] args) {
76         // TODO code application logic here
77
TestRunner.run(suite());
78     }
79     
80     public static NbTestSuite suite() {
81         NbTestSuite suite = new NbTestSuite();
82         suite.addTest(new CommitDataTest("testCommitFile"));
83         suite.addTest(new CommitDataTest("testCommitPackage"));
84         suite.addTest(new CommitDataTest("testRecognizeMimeType"));
85         return suite;
86     }
87     
88     public void testCommitFile() throws Exception JavaDoc {
89         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
90
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
91
try {
92             TestKit.closeProject(PROJECT_NAME);
93             org.openide.nodes.Node nodeIDE;
94             long start;
95             long end;
96             String JavaDoc color;
97             String JavaDoc status;
98             JTableOperator table;
99             TableModel JavaDoc model;
100             VersioningOperator vo;
101             
102             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
103             comOperator = new Operator.DefaultStringComparator(true, true);
104             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
105             Operator.setDefaultStringComparator(comOperator);
106             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
107             Operator.setDefaultStringComparator(oldOperator);
108             RepositoryStepOperator rso = new RepositoryStepOperator();
109             
110             //create repository...
111
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
112             new File JavaDoc(TMP_PATH).mkdirs();
113             work.mkdirs();
114             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
115             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
116
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
117             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
118             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
119             
120             rso.next();
121             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
122             oto.clear();
123             WorkDirStepOperator wdso = new WorkDirStepOperator();
124             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
125             wdso.setLocalFolder(work.getCanonicalPath());
126             wdso.checkCheckoutContentOnly(false);
127             wdso.finish();
128             //open project
129
oto = new OutputTabOperator("file:///tmp/repo");
130             oto.waitText("Checking out... finished.");
131             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
132             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
133             open.push();
134             
135             ProjectSupport.waitScanFinished();
136             new QueueTool().waitEmpty(1000);
137             ProjectSupport.waitScanFinished();
138             //Node projNode = new Node(new ProjectsTabOperator().tree(), "JavaApp");
139

140             TestKit.createNewElement(PROJECT_NAME, "javaapp", "NewClass");
141             Node nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java");
142             nodeFile.performPopupAction("Subversion|Show Changes");
143             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
144             color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
145             vo = VersioningOperator.invoke();
146             table = vo.tabFiles();
147             assertEquals("Wrong row count of table.", 1, table.getRowCount());
148             assertEquals("Wrong color of node!!!", TestKit.NEW_COLOR, color);
149             
150             //invoke commit action but exlude the file from commit
151
start = System.currentTimeMillis();
152             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java");
153             CommitOperator cmo = CommitOperator.invoke(nodeFile);
154             end = System.currentTimeMillis();
155             //System.out.println("Duration of invoking Commit dialog: " + (end - start));
156
//print message to log file.
157
TestKit.printLogStream(stream, "Duration of invoking Commit dialog: " + (end - start));
158             cmo.selectCommitAction("NewClass.java", "Exclude from Commit");
159             TimeoutExpiredException tee = null;
160             assertFalse(cmo.btCommit().isEnabled());
161             cmo.cancel();
162             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java");
163             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
164             color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
165             table = vo.tabFiles();
166             Thread.sleep(1000);
167             assertEquals("Wrong row count of table.", 1, table.getRowCount());
168             assertEquals("Expected file is missing.", "NewClass.java", table.getModel().getValueAt(0, 0).toString());
169             assertEquals("Wrong color of node!!!", TestKit.NEW_COLOR, color);
170             
171             oto = new OutputTabOperator("file:///tmp/repo");
172             oto.clear();
173             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java");
174             cmo = CommitOperator.invoke(nodeFile);
175             cmo.selectCommitAction("NewClass.java", "Add as Text");
176             start = System.currentTimeMillis();
177             cmo.commit();
178             oto.waitText("Committing... finished.");
179             end = System.currentTimeMillis();
180             
181             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|NewClass.java");
182             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
183             //System.out.println("Duration of invoking Commit dialog: " + (end - start));
184
TestKit.printLogStream(stream, "Duration of invoking Commit dialog: " + (end - start));
185             //color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
186
Thread.sleep(1000);
187             vo = VersioningOperator.invoke();
188             // TimeoutExpiredException tee = null;
189
try {
190                 vo.tabFiles();
191             } catch (Exception JavaDoc e) {
192                 tee = (TimeoutExpiredException) e;
193             }
194             assertNotNull("There shouldn't be any table in Versioning view", tee);
195             stream.flush();
196             stream.close();
197             
198         } catch (Exception JavaDoc e) {
199             throw new Exception JavaDoc("Test failed: " + e);
200         } finally {
201             TestKit.closeProject(PROJECT_NAME);
202         }
203     }
204     
205     public void testCommitPackage() throws Exception JavaDoc {
206         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
207
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
208
try {
209             TestKit.closeProject(PROJECT_NAME);
210             org.openide.nodes.Node nodeIDE;
211             JTableOperator table;
212             long start;
213             long end;
214             String JavaDoc color;
215             String JavaDoc status;
216             VersioningOperator vo = VersioningOperator.invoke();
217             
218             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
219             comOperator = new Operator.DefaultStringComparator(true, true);
220             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
221             Operator.setDefaultStringComparator(comOperator);
222             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
223             Operator.setDefaultStringComparator(oldOperator);
224             RepositoryStepOperator rso = new RepositoryStepOperator();
225             
226             //create repository...
227
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
228             new File JavaDoc(TMP_PATH).mkdirs();
229             work.mkdirs();
230             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
231             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
232
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
233             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
234             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
235             
236             rso.next();
237             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
238             oto.clear();
239             WorkDirStepOperator wdso = new WorkDirStepOperator();
240             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
241             wdso.setLocalFolder(work.getCanonicalPath());
242             wdso.checkCheckoutContentOnly(false);
243             wdso.finish();
244             //open project
245
oto.waitText("Checking out... finished.");
246             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
247             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
248             open.push();
249             
250             ProjectSupport.waitScanFinished();
251             new QueueTool().waitEmpty(1000);
252             ProjectSupport.waitScanFinished();
253             
254             Node projNode = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME);
255             
256             TestKit.createNewPackage(PROJECT_NAME, "xx");
257             Node nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx");
258             nodePack.performPopupAction("Subversion|Show Changes");
259             nodeIDE = (org.openide.nodes.Node) nodePack.getOpenideNode();
260             status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
261             //System.out.println("status" + status);
262
Thread.sleep(1000);
263             vo = VersioningOperator.invoke();
264             table = vo.tabFiles();
265             assertEquals("Wrong status of node!!!", TestKit.NEW_STATUS, status);
266             assertEquals("Wrong row count of table.", 1, table.getRowCount());
267             assertEquals("Expected folder is missing.", "xx", table.getModel().getValueAt(0, 0).toString());
268             
269             //invoke commit action but exlude the file from commit
270
start = System.currentTimeMillis();
271             nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx");
272             CommitOperator cmo = CommitOperator.invoke(nodePack);
273             end = System.currentTimeMillis();
274             //System.out.println("Duration of invoking Commit dialog: " + (end - start));
275
//print log message
276
TestKit.printLogStream(stream, "Duration of invoking Commit dialog: " + (end - start));
277             cmo.selectCommitAction("xx", "Exclude from Commit");
278             assertFalse(cmo.btCommit().isEnabled());
279             cmo.cancel();
280             nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx");
281             nodeIDE = (org.openide.nodes.Node) nodePack.getOpenideNode();
282             status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
283             assertEquals("Wrong status of node!!!", TestKit.NEW_STATUS, status);
284             
285             oto = new OutputTabOperator("file:///tmp/repo");
286             oto.clear();
287             nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx");
288             cmo = CommitOperator.invoke(nodePack);
289             cmo.selectCommitAction("xx", "Add Directory");
290             start = System.currentTimeMillis();
291             cmo.commit();
292             oto.waitText("Committing... finished.");
293             end = System.currentTimeMillis();
294             
295             nodePack = new Node(new SourcePackagesNode(PROJECT_NAME), "xx");
296             nodeIDE = (org.openide.nodes.Node) nodePack.getOpenideNode();
297             //System.out.println("Duration of committing file: " + (end - start));
298
TestKit.printLogStream(stream, "Duration of committing folder: " + (end - start));
299             status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
300             assertEquals("Wrong status of node!!!", TestKit.UPTODATE_STATUS, status);
301             Thread.sleep(1000);
302             vo = VersioningOperator.invoke();
303             TimeoutExpiredException tee = null;
304             try {
305                 vo.tabFiles();
306             } catch (Exception JavaDoc e) {
307                 tee = (TimeoutExpiredException) e;
308             }
309             assertNotNull("There shouldn't be any table in Versioning view", tee);
310             //TestKit.removeAllData(PROJECT_NAME);
311
stream.flush();
312             stream.close();
313             
314         } catch (Exception JavaDoc e) {
315             throw new Exception JavaDoc("Test failed: " + e);
316         } finally {
317             TestKit.closeProject(PROJECT_NAME);
318         }
319     }
320     
321     public void testRecognizeMimeType() throws Exception JavaDoc {
322         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
323
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
324
try {
325             TestKit.closeProject(PROJECT_NAME);
326             org.openide.nodes.Node nodeIDE;
327             JTableOperator table;
328             long start;
329             long end;
330             String JavaDoc color;
331             String JavaDoc status;
332             String JavaDoc[] expected = {"pp.bmp", "pp.dib", "pp.GIF", "pp.JFIF", "pp.JPE", "pp.JPEG", "pp.JPG", "pp.PNG", "pp.TIF", "pp.TIFF", "pp.zip", "text.txt", "test.jar"};
333             
334             VersioningOperator vo = VersioningOperator.invoke();
335             
336             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
337             comOperator = new Operator.DefaultStringComparator(true, true);
338             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
339             Operator.setDefaultStringComparator(comOperator);
340             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
341             Operator.setDefaultStringComparator(oldOperator);
342             RepositoryStepOperator rso = new RepositoryStepOperator();
343             
344             //create repository...
345
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
346             new File JavaDoc(TMP_PATH).mkdirs();
347             work.mkdirs();
348             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
349             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
350
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
351             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
352             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
353             
354             rso.next();
355             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
356             oto.clear();
357             WorkDirStepOperator wdso = new WorkDirStepOperator();
358             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
359             wdso.setLocalFolder(work.getCanonicalPath());
360             wdso.checkCheckoutContentOnly(false);
361             wdso.finish();
362             //open project
363
oto.waitText("Checking out... finished.");
364             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
365             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
366             open.push();
367             
368             ProjectSupport.waitScanFinished();
369             new QueueTool().waitEmpty(1000);
370             ProjectSupport.waitScanFinished();
371             
372             //create various types of files
373
String JavaDoc src = getDataDir().getCanonicalPath() + File.separator + "files" + File.separator;
374             String JavaDoc dest = work.getCanonicalPath() + File.separator + PROJECT_NAME + File.separator + "src" + File.separator + "javaapp" + File.separator;
375             
376             for (int i = 0; i < expected.length; i++) {
377                 TestKit.copyTo(src + expected[i], dest + expected[i]);
378             }
379             
380             oto = new OutputTabOperator("file:///tmp/repo");
381             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
382             oto.clear();
383             
384             Node nodeSrc = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
385             nodeSrc.performPopupAction("Subversion|Show Changes");
386             oto.waitText("Refreshing... finished.");
387             
388             Node nodeTest;
389             for (int i = 0; i < expected.length; i++) {
390                 nodeTest = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|" + expected[i]);
391                 nodeIDE = (org.openide.nodes.Node) nodeTest.getOpenideNode();
392                 status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
393                 color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
394                 assertEquals("Wrong status of node!!!", TestKit.NEW_STATUS, status);
395                 assertEquals("Wrong color of node!!!", TestKit.NEW_COLOR, color);
396             }
397             
398             vo = VersioningOperator.invoke();
399             TableModel JavaDoc model = vo.tabFiles().getModel();
400             String JavaDoc[] actual = new String JavaDoc[model.getRowCount()];;
401             for (int i = 0; i < actual.length; i++) {
402                 actual[i] = model.getValueAt(i, 0).toString();
403             }
404             int result = TestKit.compareThem(expected, actual, false);
405             assertEquals("Not All files listed in Commit dialog", expected.length, result);
406             
407             oto = new OutputTabOperator("file:///tmp/repo");
408             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
409             oto.clear();
410             nodeSrc = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
411             CommitOperator cmo = CommitOperator.invoke(nodeSrc);
412             table = cmo.tabFiles();
413             model = table.getModel();
414             actual = new String JavaDoc[model.getRowCount()];
415             for (int i = 0; i < actual.length; i++) {
416                 actual[i] = model.getValueAt(i, 0).toString();
417                 if (actual[i].endsWith(".txt")) {
418                     assertEquals("Expected text file.", "Add as Text", model.getValueAt(i, 2).toString());
419                     //System.out.println("Issue should be fixed: http://www.netbeans.org/issues/show_bug.cgi?id=77046!!!");
420
} else {
421                     assertEquals("Expected text file.", "Add as Binary", model.getValueAt(i, 2).toString());
422                 }
423             }
424             result = TestKit.compareThem(expected, actual, false);
425             assertEquals("Not All files listed in Commit dialog", expected.length, result);
426             cmo.commit();
427             for (int i = 0; i < expected.length; i++) {
428                 oto.waitText("add -N");
429                 oto.waitText(expected[i]);
430             }
431             oto.waitText("Committing... finished.");
432             //System.out.println("Issue should be fixed: http://www.netbeans.org/issues/show_bug.cgi?id=77060!!!");
433

434             //files have been committed,
435
//verify explorer node
436
for (int i = 0; i < expected.length; i++) {
437                 nodeTest = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|" + expected[i]);
438                 nodeIDE = (org.openide.nodes.Node) nodeTest.getOpenideNode();
439                 assertNull("Wrong status or color of node!!!", nodeIDE.getHtmlDisplayName());
440             }
441             //verify versioning view
442
vo = VersioningOperator.invoke();
443             TimeoutExpiredException tee = null;
444             try {
445                 vo.tabFiles();
446             } catch (Exception JavaDoc e) {
447                 tee = (TimeoutExpiredException) e;
448             }
449             assertNotNull("There shouldn't be any table in Versioning view", tee);
450             //TestKit.removeAllData(PROJECT_NAME);
451
stream.flush();
452             stream.close();
453             
454         } catch (Exception JavaDoc e) {
455             throw new Exception JavaDoc("Test failed: " + e);
456         } finally {
457             TestKit.closeProject(PROJECT_NAME);
458         }
459     }
460 }
461
Popular Tags