KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > main > checkout > ImportUITest


1 /*
2  * ImportUITest.java
3  *
4  * Created on 10 May 2006, 15:50
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.checkout;
11
12 import java.io.File JavaDoc;
13 import javax.swing.table.TableModel JavaDoc;
14 import junit.textui.TestRunner;
15 import org.netbeans.jellytools.JellyTestCase;
16 import org.netbeans.jellytools.ProjectsTabOperator;
17 import org.netbeans.jellytools.nodes.Node;
18 import org.netbeans.jemmy.JemmyProperties;
19 import org.netbeans.jemmy.operators.JTableOperator;
20 import org.netbeans.jemmy.operators.Operator;
21 import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
22 import org.netbeans.junit.NbTestSuite;
23 import org.netbeans.test.subversion.operators.CommitStepOperator;
24 import org.netbeans.test.subversion.operators.CreateNewFolderOperator;
25 import org.netbeans.test.subversion.operators.FolderToImportStepOperator;
26 import org.netbeans.test.subversion.operators.ImportWizardOperator;
27 import org.netbeans.test.subversion.operators.RepositoryBrowserImpOperator;
28 import org.netbeans.test.subversion.operators.RepositoryStepOperator;
29 import org.netbeans.test.subversion.utils.RepositoryMaintenance;
30 import org.netbeans.test.subversion.utils.TestKit;
31
32 /**
33  *
34  * @author peter
35  */

36 public class ImportUITest extends JellyTestCase {
37   
38     public static final String JavaDoc TMP_PATH = "/tmp";
39     public static final String JavaDoc REPO_PATH = "repo";
40     public static final String JavaDoc WORK_PATH = "work";
41     public static final String JavaDoc PROJECT_NAME = "SVNApplication";
42     public File JavaDoc projectPath;
43     String JavaDoc os_name;
44     Operator.DefaultStringComparator comOperator;
45     Operator.DefaultStringComparator oldOperator;
46     
47     /** Creates a new instance of ImportUITest */
48     public ImportUITest(String JavaDoc name) {
49         super(name);
50     }
51     
52     protected void setUp() throws Exception JavaDoc {
53         os_name = System.getProperty("os.name");
54         //System.out.println(os_name);
55
System.out.println("### "+getName()+" ###");
56         
57     }
58     
59     protected boolean isUnix() {
60         boolean unix = false;
61         if (os_name.indexOf("Windows") == -1) {
62             unix = true;
63         }
64         return unix;
65     }
66     
67     public static void main(String JavaDoc[] args) {
68         // TODO code application logic here
69
TestRunner.run(suite());
70     }
71     
72     public static NbTestSuite suite() {
73         NbTestSuite suite = new NbTestSuite();
74         suite.addTest(new ImportUITest("testInvoke"));
75         suite.addTest(new ImportUITest("testWarningMessage"));
76         suite.addTest(new ImportUITest("testRepositoryFolderLoad"));
77         suite.addTest(new ImportUITest("testCommitStep"));
78         return suite;
79     }
80     
81     public void testInvoke() throws Exception JavaDoc {
82         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
83
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
84
try {
85             TestKit.closeProject(PROJECT_NAME);
86             
87             new File JavaDoc(TMP_PATH).mkdirs();
88             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
89             RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
90             projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME);
91             comOperator = new Operator.DefaultStringComparator(true, true);
92             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
93             Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME);
94             Operator.setDefaultStringComparator(comOperator);
95             ImportWizardOperator iwo = ImportWizardOperator.invoke(node);
96             Operator.setDefaultStringComparator(oldOperator);
97             iwo.cancel();
98             
99         } catch (Exception JavaDoc e) {
100             throw new Exception JavaDoc("Test failed: " + e);
101         } finally {
102             TestKit.closeProject(PROJECT_NAME);
103         }
104     }
105     
106     public void testWarningMessage() throws Exception JavaDoc {
107         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
108
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
109
try {
110             TestKit.closeProject(PROJECT_NAME);
111             
112             new File JavaDoc(TMP_PATH).mkdirs();
113             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
114             RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
115             projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME);
116             
117             comOperator = new Operator.DefaultStringComparator(true, true);
118             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
119             Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME);
120             Operator.setDefaultStringComparator(comOperator);
121             ImportWizardOperator iwo = ImportWizardOperator.invoke(node);
122             Operator.setDefaultStringComparator(oldOperator);
123             RepositoryStepOperator rso = new RepositoryStepOperator();
124             //rso.verify();
125
rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
126             rso.next();
127             Thread.sleep(2000);
128             
129             FolderToImportStepOperator ftiso = new FolderToImportStepOperator();
130             ftiso.verify();
131             
132             //Warning message for empty REPOSITORY FOLDER
133
ftiso.setRepositoryFolder("");
134             assertEquals("Repository Folder must be specified", "Repository Folder must be specified", ftiso.lblImportMessageRequired().getText());
135             assertFalse("Next button should be disabled", ftiso.btNext().isEnabled());
136             assertFalse("Finish button should be disabled", ftiso.btFinish().isEnabled());
137             
138             //Warning message for empty import message
139
ftiso.setRepositoryFolder(PROJECT_NAME);
140             ftiso.setImportMessage("");
141             assertEquals("Import message required", "Import Message required", ftiso.lblImportMessageRequired().getText());
142             assertFalse("Next button should be disabled", ftiso.btNext().isEnabled());
143             assertFalse("Finish button should be disabled", ftiso.btFinish().isEnabled());
144             
145             //NO Warning message if both are setup correctly.
146
ftiso.setRepositoryFolder(PROJECT_NAME);
147             ftiso.setImportMessage("initial import");
148             assertEquals("No Warning message", " ", ftiso.lblImportMessageRequired().getText());
149             assertTrue("Next button should be enabled", ftiso.btNext().isEnabled());
150             //Finish button should be enabled.
151
//System.out.println("Issue should be fixed: http://www.netbeans.org/issues/show_bug.cgi?id=76165!!!");
152
assertTrue("Finish button should be enabled", ftiso.btFinish().isEnabled());
153             iwo.cancel();
154             
155         } catch (Exception JavaDoc e) {
156             throw new Exception JavaDoc("Test failed: " + e);
157         } finally {
158             TestKit.closeProject(PROJECT_NAME);
159         }
160     }
161     
162     public void testRepositoryFolderLoad() throws Exception JavaDoc {
163         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
164
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
165
TestKit.closeProject(PROJECT_NAME);
166         try {
167             
168             new File JavaDoc(TMP_PATH).mkdirs();
169             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
170             RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
171             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
172             projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME);
173             
174             comOperator = new Operator.DefaultStringComparator(true, true);
175             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
176             Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME);
177             Operator.setDefaultStringComparator(comOperator);
178             ImportWizardOperator iwo = ImportWizardOperator.invoke(node);
179             Operator.setDefaultStringComparator(oldOperator);
180             RepositoryStepOperator rso = new RepositoryStepOperator();
181             //rso.verify();
182
rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
183             rso.next();
184             Thread.sleep(2000);
185             
186             FolderToImportStepOperator ftiso = new FolderToImportStepOperator();
187             
188             //
189
RepositoryBrowserImpOperator rbo = ftiso.browseRepository();
190             rbo.selectFolder("branches");
191             rbo.selectFolder("tags");
192             rbo.selectFolder("trunk");
193             rbo.selectFolder("trunk|JavaApp|src|javaapp");
194             rbo.ok();
195             assertEquals("Wrong folder selection!!!", "trunk/JavaApp/src/javaapp", ftiso.getRepositoryFolder());
196             
197         /*
198         ftiso.setRepositoryFolder("trunk/" + PROJECT_NAME);
199         rbo = ftiso.browseRepository();
200         rbo.selectFolder("trunk|" + PROJECT_NAME);
201         rbo.selectFolder("branches|release01|" + PROJECT_NAME);
202         rbo.ok();
203         assertEquals("Wrong folder selection!!!", "branches/release01/" + PROJECT_NAME, ftiso.getRepositoryFolder());*/

204             
205             //
206
ftiso.setRepositoryFolder("trunk");
207             rbo = ftiso.browseRepository();
208             rbo.selectFolder("trunk");
209             CreateNewFolderOperator cnfo = rbo.createNewFolder();
210             cnfo.setFolderName(PROJECT_NAME);
211             cnfo.ok();
212             rbo.selectFolder("trunk|" + PROJECT_NAME);
213             rbo.ok();
214             assertEquals("Wrong folder selection!!!", "trunk/" + PROJECT_NAME, ftiso.getRepositoryFolder());
215             
216             //
217
ftiso.setRepositoryFolder("trunk");
218             rbo = ftiso.browseRepository();
219             rbo.selectFolder("branches");
220             cnfo = rbo.createNewFolder();
221             cnfo.setFolderName("release_01");
222             cnfo.ok();
223             rbo.selectFolder("branches|release_01");
224             cnfo = rbo.createNewFolder();
225             cnfo.setFolderName(PROJECT_NAME);
226             cnfo.ok();
227             rbo.selectFolder("branches|release_01|" + PROJECT_NAME);
228             rbo.ok();
229             assertEquals("Wrong folder selection!!!", "branches/release_01/" + PROJECT_NAME, ftiso.getRepositoryFolder());
230             
231             iwo.cancel();
232            
233         } catch (Exception JavaDoc e) {
234             throw new Exception JavaDoc("Test failed: " + e);
235         } finally {
236             TestKit.closeProject(PROJECT_NAME);
237         }
238     }
239     
240     public void testCommitStep() throws Exception JavaDoc {
241         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
242
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
243
try {
244             TestKit.closeProject(PROJECT_NAME);
245             
246             new File JavaDoc(TMP_PATH).mkdirs();
247             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
248             RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
249             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
250             projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME);
251             
252             comOperator = new Operator.DefaultStringComparator(true, true);
253             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
254             Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME);
255             Operator.setDefaultStringComparator(comOperator);
256             ImportWizardOperator iwo = ImportWizardOperator.invoke(node);
257             Operator.setDefaultStringComparator(oldOperator);
258             RepositoryStepOperator rso = new RepositoryStepOperator();
259             //rso.verify();
260
rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
261             rso.next();
262             Thread.sleep(1000);
263             
264             FolderToImportStepOperator ftiso = new FolderToImportStepOperator();
265             ftiso.setRepositoryFolder("trunk/" + PROJECT_NAME);
266             ftiso.setImportMessage("initial import");
267             ftiso.next();
268             Thread.sleep(1000);
269             CommitStepOperator cso = new CommitStepOperator();
270             cso.verify();
271             
272             JTableOperator table = cso.tabFiles();
273             TableModel JavaDoc model = table.getModel();
274             String JavaDoc[] expected = {"genfiles.properties", "build-impl.xml", "Main.java", "manifest.mf", "src", "project.xml", PROJECT_NAME.toLowerCase(), "nbproject", "project.properties", "test", "build.xml"};
275             String JavaDoc[] actual = new String JavaDoc[model.getRowCount()];
276             for (int i = 0; i < actual.length; i++) {
277                 actual[i] = model.getValueAt(i, 0).toString();
278             }
279             assertEquals("Incorrect count of records for addition!!!", 11, model.getRowCount());
280             assertEquals("Some records were omitted from addition", 11, TestKit.compareThem(expected, actual, false));
281             //try to change commit actions
282
cso.selectCommitAction("project.xml", "Add As Text");
283             cso.selectCommitAction("project.xml", "Add As Binary");
284             cso.selectCommitAction("project.xml", "Exclude from Commit");
285             cso.selectCommitAction("test", "Add Directory");
286             cso.selectCommitAction("test", "Exclude from Commit");
287             iwo.cancel();
288             
289         } catch (Exception JavaDoc e) {
290             throw new Exception JavaDoc("Test failed: " + e);
291         } finally {
292             TestKit.closeProject(PROJECT_NAME);
293         }
294     }
295     
296     public void testStopProcess() throws Exception JavaDoc {
297         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 3000);
298
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 3000);
299
try {
300             TestKit.closeProject(PROJECT_NAME);
301             
302             new File JavaDoc(TMP_PATH).mkdirs();
303             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
304             RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
305             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
306             projectPath = TestKit.prepareProject("General", "Java Application", PROJECT_NAME);
307             
308             comOperator = new Operator.DefaultStringComparator(true, true);
309             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
310             Node node = new ProjectsTabOperator().getProjectRootNode(PROJECT_NAME);
311             Operator.setDefaultStringComparator(comOperator);
312             ImportWizardOperator iwo = ImportWizardOperator.invoke(node);
313             Operator.setDefaultStringComparator(oldOperator);
314             RepositoryStepOperator rso = new RepositoryStepOperator();
315             //rso.verify();
316
rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
317             rso.next();
318             //Stop process in 1st step of Import wizard
319
rso.btStop().push();
320             assertEquals("Warning message - process was cancelled by user", "Action canceled by user", rso.lblWarning().getText());
321             rso.setRepositoryURL(RepositoryStepOperator.ITEM_HTTPS);
322             rso = new RepositoryStepOperator();
323             //rso.verify();
324

325             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
326             rso.next();
327             
328             FolderToImportStepOperator ftiso = new FolderToImportStepOperator();
329             ftiso.setRepositoryFolder("trunk/" + PROJECT_NAME);
330             ftiso.setImportMessage("initial import");
331             ftiso.next();
332             //Stop process in 2st step of Import wizard
333
ftiso.btStop().push();
334             
335             ftiso = new FolderToImportStepOperator();
336             //ftiso.verify();
337
ftiso.back();
338             
339             rso = new RepositoryStepOperator();
340             rso.setRepositoryURL(RepositoryStepOperator.ITEM_HTTPS);
341             rso = new RepositoryStepOperator();
342             rso.verify();
343             
344         } catch (Exception JavaDoc e) {
345             throw new Exception JavaDoc("Test failed: " + e);
346         } finally {
347             TestKit.closeProject(PROJECT_NAME);
348         }
349     }
350 }
351
Popular Tags