KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > subversion > main > diff > ExportDiffPatchTest


1 /*
2  * ExportDiffPatchTest.java
3  *
4  * Created on Piatok, 2006, september 15, 10:49
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.diff;
11
12 import java.io.BufferedReader JavaDoc;
13 import java.io.File JavaDoc;
14 import java.io.FileReader JavaDoc;
15 import java.io.PrintStream JavaDoc;
16 import org.netbeans.jellytools.JellyTestCase;
17 import org.netbeans.junit.NbTestSuite;
18 import org.netbeans.junit.ide.ProjectSupport;
19 import junit.textui.TestRunner;
20 import org.netbeans.jellytools.EditorOperator;
21 import org.netbeans.jellytools.NbDialogOperator;
22 import org.netbeans.jellytools.OutputTabOperator;
23 import org.netbeans.jellytools.ProjectsTabOperator;
24 import org.netbeans.jellytools.nodes.Node;
25 import org.netbeans.jellytools.nodes.SourcePackagesNode;
26 import org.netbeans.jemmy.JemmyProperties;
27 import org.netbeans.jemmy.QueueTool;
28 import org.netbeans.jemmy.operators.JButtonOperator;
29 import org.netbeans.jemmy.operators.JTextFieldOperator;
30 import org.netbeans.test.subversion.operators.CheckoutWizardOperator;
31 import org.netbeans.test.subversion.operators.RepositoryStepOperator;
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 ExportDiffPatchTest 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     
51     /** Creates a new instance of ExportDiffPatchTest */
52     public ExportDiffPatchTest(String JavaDoc name) {
53         super(name);
54     }
55     
56     protected void setUp() throws Exception JavaDoc {
57         os_name = System.getProperty("os.name");
58         //System.out.println(os_name);
59
System.out.println("### "+getName()+" ###");
60         
61     }
62     
63     protected boolean isUnix() {
64         boolean unix = false;
65         if (os_name.indexOf("Windows") == -1) {
66             unix = true;
67         }
68         return unix;
69     }
70     
71     public static void main(String JavaDoc[] args) {
72         // TODO code application logic here
73
TestRunner.run(suite());
74     }
75     
76     public static NbTestSuite suite() {
77         NbTestSuite suite = new NbTestSuite();
78         suite.addTest(new ExportDiffPatchTest("invokeExportDiffPatch"));
79         return suite;
80     }
81     
82     public void invokeExportDiffPatch() throws Exception JavaDoc {
83         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
84
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
85
try {
86             TestKit.closeProject(PROJECT_NAME);
87             
88             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
89             VersioningOperator vo = VersioningOperator.invoke();
90             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
91             RepositoryStepOperator rso = new RepositoryStepOperator();
92             
93             //create repository...
94
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
95             new File JavaDoc(TMP_PATH).mkdirs();
96             work.mkdirs();
97             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
98             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
99
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
100             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
101             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
102             
103             rso.next();
104             WorkDirStepOperator wdso = new WorkDirStepOperator();
105             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
106             wdso.setLocalFolder(work.getCanonicalPath());
107             wdso.checkCheckoutContentOnly(false);
108             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
109             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
110             oto.clear();
111             wdso.finish();
112             //open project
113
oto.waitText("Checking out... finished.");
114             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
115             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
116             open.push();
117             
118             ProjectSupport.waitScanFinished();
119             new QueueTool().waitEmpty(1000);
120             ProjectSupport.waitScanFinished();
121             
122             //modify, save file and invoke Diff
123
oto = new OutputTabOperator("file:///tmp/repo");
124             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
125             oto.clear();
126             Node node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java");
127             node.performPopupAction("Open");
128             EditorOperator eo = new EditorOperator("Main.java");
129             eo.deleteLine(2);
130             eo.insert(" insert", 5, 1);
131             eo.insert("\tSystem.out.println(\"\");\n", 19, 1);
132             eo.save();
133             node.performPopupAction("Subversion|Show Changes");
134             Thread.sleep(1000);
135             vo = VersioningOperator.invoke();
136             //Save action should change the file annotations
137
org.openide.nodes.Node nodeIDE = (org.openide.nodes.Node) node.getOpenideNode();
138             String JavaDoc color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
139             String JavaDoc status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
140             assertEquals("Wrong color of node - file color should be new!!!", TestKit.MODIFIED_COLOR, color);
141             assertEquals("Wrong annotation of node - file status should be new!!!", TestKit.MODIFIED_STATUS, status);
142             assertEquals("Wrong number of records in Versioning view!!!", 1, vo.tabFiles().getRowCount());
143             
144             node = new Node(new ProjectsTabOperator().tree(), PROJECT_NAME);
145             node.select();
146             node.performMenuActionNoBlock("Versioning|Export");
147             nbdialog = new NbDialogOperator("Export");
148             JButtonOperator btn = new JButtonOperator(nbdialog, "Export");
149             JTextFieldOperator tf = new JTextFieldOperator(nbdialog, 0);
150             String JavaDoc patchFile = "/tmp/patch" + System.currentTimeMillis() + ".patch";
151             File JavaDoc file = new File JavaDoc(patchFile);
152             tf.setText(file.getCanonicalFile().toString());
153             oto = new OutputTabOperator("file:///tmp/repo");
154             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
155             oto.clear();
156             btn.push();
157             oto.waitText("Diff Patch finished");
158             
159             BufferedReader JavaDoc br = new BufferedReader JavaDoc(new FileReader JavaDoc(file));
160             String JavaDoc line = br.readLine();
161             boolean generated = false;
162             if (line != null) {
163                 generated = line.indexOf("# This patch file was generated by NetBeans IDE") != -1 ? true : false;
164             }
165             
166             br.close();
167             assertTrue("Diff Patch file is empty!", generated);
168             System.setProperty("netbeans.t9y.cvs.connection.CVSROOT", "");
169             stream.flush();
170             stream.close();
171             
172         } catch (Exception JavaDoc e) {
173             throw new Exception JavaDoc("Test failed: " + e);
174         } finally {
175             TestKit.closeProject(PROJECT_NAME);
176         }
177     }
178     
179 }
180
Popular Tags