KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > main > branches > CopyTest


1 /*
2  * CopyTest.java
3  *
4  * Created on June 6, 2006, 3:58 PM
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.branches;
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.ProjectsTabOperator;
19 import org.netbeans.jellytools.nodes.Node;
20 import org.netbeans.jellytools.nodes.SourcePackagesNode;
21 import org.netbeans.jemmy.JemmyProperties;
22 import org.netbeans.jemmy.QueueTool;
23 import org.netbeans.jemmy.operators.JButtonOperator;
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.CopyToOperator;
30 import org.netbeans.test.subversion.operators.RepositoryStepOperator;
31 import org.netbeans.test.subversion.operators.SwitchOperator;
32 import org.netbeans.test.subversion.operators.WorkDirStepOperator;
33 import org.netbeans.test.subversion.utils.RepositoryMaintenance;
34 import org.netbeans.test.subversion.utils.TestKit;
35
36 /**
37  *
38  * @author peter pis
39  */

40 public class CopyTest extends JellyTestCase {
41     
42     public static final String JavaDoc TMP_PATH = "/tmp";
43     public static final String JavaDoc REPO_PATH = "repo";
44     public static final String JavaDoc WORK_PATH = "work";
45     public static final String JavaDoc PROJECT_NAME = "JavaApp";
46     public File JavaDoc projectPath;
47     public PrintStream JavaDoc stream;
48     Operator.DefaultStringComparator comOperator;
49     Operator.DefaultStringComparator oldOperator;
50     
51     String JavaDoc os_name;
52     
53     /** Creates a new instance of CopyTest */
54     public CopyTest(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 CopyTest("testCreateNewCopySwitch"));
81         suite.addTest(new CopyTest("testCreateNewCopy"));
82         return suite;
83     }
84     
85     public void testCreateNewCopySwitch() 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             comOperator = new Operator.DefaultStringComparator(true, true);
93             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
94             Operator.setDefaultStringComparator(comOperator);
95             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
96             Operator.setDefaultStringComparator(oldOperator);
97             RepositoryStepOperator rso = new RepositoryStepOperator();
98
99             //create repository...
100
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
101             new File JavaDoc(TMP_PATH).mkdirs();
102             work.mkdirs();
103             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
104             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
105
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
106             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
107             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
108
109             rso.next();
110             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
111             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
112             oto.clear();
113             WorkDirStepOperator wdso = new WorkDirStepOperator();
114             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
115             wdso.setLocalFolder(work.getCanonicalPath());
116             wdso.checkCheckoutContentOnly(false);
117             wdso.finish();
118             //open project
119
oto.waitText("Checking out... finished.");
120             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
121             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
122             open.push();
123
124             ProjectSupport.waitScanFinished();
125             new QueueTool().waitEmpty(1000);
126             ProjectSupport.waitScanFinished();
127
128             oto = new OutputTabOperator("file:///tmp/repo");
129             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
130             oto.clear();
131             Node projNode = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME);
132             CopyToOperator cto = CopyToOperator.invoke(projNode);
133             cto.setRepositoryFolder("branches/release01/" + PROJECT_NAME);
134             cto.setCopyPurpose("New branch for project.");
135             cto.checkSwitchToCopy(true);
136             cto.copy();
137             Thread.sleep(2000);
138             oto.waitText("Copy");
139             oto.waitText("finished.");
140
141             Node nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|Main.java");
142             org.openide.nodes.Node nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
143             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
144
String JavaDoc status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
145             assertEquals("Wrong annotation of node!!!", "[ release01]", status);
146
147             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
148             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
149             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
150
status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
151             assertEquals("Wrong annotation of node!!!", "[ release01]", status);
152             //to do
153
stream.flush();
154             stream.close();
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 testCreateNewCopy() throws Exception JavaDoc {
163         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
164
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
165
try {
166             TestKit.closeProject(PROJECT_NAME);
167
168             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
169             comOperator = new Operator.DefaultStringComparator(true, true);
170             oldOperator = (DefaultStringComparator) Operator.getDefaultStringComparator();
171             Operator.setDefaultStringComparator(comOperator);
172             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
173             Operator.setDefaultStringComparator(oldOperator);
174             RepositoryStepOperator rso = new RepositoryStepOperator();
175
176             //create repository...
177
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
178             new File JavaDoc(TMP_PATH).mkdirs();
179             work.mkdirs();
180             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
181             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
182
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
183             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
184             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
185
186             rso.next();
187             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
188             oto.clear();
189             WorkDirStepOperator wdso = new WorkDirStepOperator();
190             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
191             wdso.setLocalFolder(work.getCanonicalPath());
192             wdso.checkCheckoutContentOnly(false);
193             wdso.finish();
194             //open project
195
oto.waitText("Checking out... finished.");
196             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
197             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
198             open.push();
199
200             ProjectSupport.waitScanFinished();
201             new QueueTool().waitEmpty(1000);
202             ProjectSupport.waitScanFinished();
203
204             oto = new OutputTabOperator("file:///tmp/repo");
205             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
206             oto.clear();
207             Node projNode = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME);
208             CopyToOperator cto = CopyToOperator.invoke(projNode);
209             cto.setRepositoryFolder("branches/release01");
210             cto.setCopyPurpose("New branch for project.");
211             cto.checkSwitchToCopy(false);
212             cto.copy();
213             oto.waitText("Copy");
214             oto.waitText("finished.");
215
216             Node nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|Main.java");
217             org.openide.nodes.Node nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
218             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
219
String JavaDoc status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
220             assertEquals("Wrong annotation of node!!!", TestKit.UPTODATE_STATUS, status);
221
222             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
223             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
224             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
225
status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
226             assertEquals("Wrong annotation of node!!!", TestKit.UPTODATE_STATUS, status);
227             //to do
228

229             //switch to branch
230
oto = new OutputTabOperator("file:///tmp/repo");
231             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
232             oto.clear();
233             projNode = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME);
234             SwitchOperator so = SwitchOperator.invoke(projNode);
235             so.setRepositoryFolder("branches/release01/" + PROJECT_NAME);
236             so.switchBt();
237             oto.waitText("Switch");
238             oto.waitText("finished.");
239
240             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|Main.java");
241             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
242             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
243
status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
244             assertEquals("Wrong annotation of node!!!", "[ release01]", status);
245
246             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
247             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
248             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
249
status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
250             assertEquals("Wrong annotation of node!!!", "[ release01]", status);
251
252             oto = new OutputTabOperator("file:///tmp/repo");
253             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
254             oto.clear();
255             projNode = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME);
256             so = SwitchOperator.invoke(projNode);
257             so.setRepositoryFolder("trunk/" + PROJECT_NAME);
258             so.switchBt();
259             oto.waitText("Switch");
260             oto.waitText("finished.");
261             Thread.sleep(2000);
262
263             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp" + "|Main.java");
264             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
265             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
266
status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
267             assertEquals("Wrong annotation of node!!!", TestKit.UPTODATE_STATUS, status);
268
269             nodeFile = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp");
270             nodeIDE = (org.openide.nodes.Node) nodeFile.getOpenideNode();
271             //String color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
272
status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
273             assertEquals("Wrong annotation of node!!!", TestKit.UPTODATE_STATUS, status);
274
275             stream.flush();
276             stream.close();
277         } catch (Exception JavaDoc e) {
278             throw new Exception JavaDoc("Test failed: " + e);
279         } finally {
280             TestKit.closeProject(PROJECT_NAME);
281         }
282     }
283 }
284
Popular Tags