KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * DiffTest.java
3  *
4  * Created on July 3, 2006, 3:18 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.diff;
11
12 import java.io.File JavaDoc;
13 import java.io.PrintStream JavaDoc;
14 import junit.textui.TestRunner;
15 import org.netbeans.jellytools.EditorOperator;
16 import org.netbeans.jellytools.JellyTestCase;
17 import org.netbeans.jellytools.NbDialogOperator;
18 import org.netbeans.jellytools.OutputTabOperator;
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.TimeoutExpiredException;
24 import org.netbeans.jemmy.operators.JButtonOperator;
25 import org.netbeans.junit.NbTestSuite;
26 import org.netbeans.test.subversion.operators.CheckoutWizardOperator;
27 import org.netbeans.test.subversion.operators.RepositoryStepOperator;
28 import org.netbeans.test.subversion.operators.VersioningOperator;
29 import org.netbeans.test.subversion.operators.WorkDirStepOperator;
30 import org.netbeans.test.subversion.utils.RepositoryMaintenance;
31 import org.netbeans.test.subversion.utils.TestKit;
32 import org.netbeans.junit.ide.ProjectSupport;
33 import org.netbeans.test.subversion.operators.DiffOperator;
34
35 /**
36  *
37  * @author pvcs
38  */

39 public class DiffTest extends JellyTestCase {
40     
41     public static final String JavaDoc TMP_PATH = "/tmp";
42     public static final String JavaDoc REPO_PATH = "repo";
43     public static final String JavaDoc WORK_PATH = "work";
44     public static final String JavaDoc PROJECT_NAME = "JavaApp";
45     public File JavaDoc projectPath;
46     public PrintStream JavaDoc stream;
47     String JavaDoc os_name;
48     
49     /** Creates a new instance of DiffTest */
50     public DiffTest(String JavaDoc name) {
51         super(name);
52     }
53     
54     protected void setUp() throws Exception JavaDoc {
55         os_name = System.getProperty("os.name");
56         //System.out.println(os_name);
57
System.out.println("### "+getName()+" ###");
58         
59     }
60     
61     protected boolean isUnix() {
62         boolean unix = false;
63         if (os_name.indexOf("Windows") == -1) {
64             unix = true;
65         }
66         return unix;
67     }
68     
69     public static void main(String JavaDoc[] args) {
70         // TODO code application logic here
71
TestRunner.run(suite());
72     }
73     
74     public static NbTestSuite suite() {
75         NbTestSuite suite = new NbTestSuite();
76         suite.addTest(new DiffTest("testDiffFile"));
77         return suite;
78     }
79     
80     public void testDiffFile() throws Exception JavaDoc {
81         //JemmyProperties.setCurrentTimeout("ComponentOperator.WaitComponentTimeout", 30000);
82
//JemmyProperties.setCurrentTimeout("DialogWaiter.WaitDialogTimeout", 30000);
83
try {
84             TestKit.closeProject(PROJECT_NAME);
85             
86             stream = new PrintStream JavaDoc(new File JavaDoc(getWorkDir(), getName() + ".log"));
87             VersioningOperator vo = VersioningOperator.invoke();
88             CheckoutWizardOperator co = CheckoutWizardOperator.invoke();
89             RepositoryStepOperator rso = new RepositoryStepOperator();
90             
91             //create repository...
92
File JavaDoc work = new File JavaDoc(TMP_PATH + File.separator + WORK_PATH + File.separator + "w" + System.currentTimeMillis());
93             new File JavaDoc(TMP_PATH).mkdirs();
94             work.mkdirs();
95             RepositoryMaintenance.deleteFolder(new File JavaDoc(TMP_PATH + File.separator + REPO_PATH));
96             //RepositoryMaintenance.deleteFolder(new File(TMP_PATH + File.separator + WORK_PATH));
97
RepositoryMaintenance.createRepository(TMP_PATH + File.separator + REPO_PATH);
98             RepositoryMaintenance.loadRepositoryFromFile(TMP_PATH + File.separator + REPO_PATH, getDataDir().getCanonicalPath() + File.separator + "repo_dump");
99             rso.setRepositoryURL(RepositoryStepOperator.ITEM_FILE + RepositoryMaintenance.changeFileSeparator(TMP_PATH + File.separator + REPO_PATH, false));
100             
101             rso.next();
102             WorkDirStepOperator wdso = new WorkDirStepOperator();
103             wdso.setRepositoryFolder("trunk/" + PROJECT_NAME);
104             wdso.setLocalFolder(work.getCanonicalPath());
105             wdso.checkCheckoutContentOnly(false);
106             OutputTabOperator oto = new OutputTabOperator("file:///tmp/repo");
107             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
108             oto.clear();
109             wdso.finish();
110             //open project
111
oto.waitText("Checking out... finished.");
112             NbDialogOperator nbdialog = new NbDialogOperator("Checkout Completed");
113             JButtonOperator open = new JButtonOperator(nbdialog, "Open Project");
114             open.push();
115             
116             ProjectSupport.waitScanFinished();
117             new QueueTool().waitEmpty(1000);
118             ProjectSupport.waitScanFinished();
119             
120             //modify, save file and invoke Diff
121
oto = new OutputTabOperator("file:///tmp/repo");
122             oto.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 30000);
123             oto.clear();
124             Node node = new Node(new SourcePackagesNode(PROJECT_NAME), "javaapp|Main.java");
125             node.performPopupAction("Open");
126             EditorOperator eo = new EditorOperator("Main.java");
127             eo.deleteLine(2);
128             eo.insert(" insert", 5, 1);
129             eo.insert("\tSystem.out.println(\"\");\n", 19, 1);
130             eo.save();
131             node.performPopupAction("Subversion|Show Changes");
132             Thread.sleep(1000);
133             vo = VersioningOperator.invoke();
134             //Save action should change the file annotations
135
org.openide.nodes.Node nodeIDE = (org.openide.nodes.Node) node.getOpenideNode();
136             String JavaDoc color = TestKit.getColor(nodeIDE.getHtmlDisplayName());
137             String JavaDoc status = TestKit.getStatus(nodeIDE.getHtmlDisplayName());
138             assertEquals("Wrong color of node - file color should be new!!!", TestKit.MODIFIED_COLOR, color);
139             assertEquals("Wrong annotation of node - file status should be new!!!", TestKit.MODIFIED_STATUS, status);
140             assertEquals("Wrong number of records in Versioning view!!!", 1, vo.tabFiles().getRowCount());
141             
142             node.performPopupAction("Subversion|Diff");
143             System.out.println("DIFF action doesn't print information into OUTPUT!!!");
144             //oto.waitText("Annotating... finished.");
145
Thread.sleep(2000);
146             
147             DiffOperator diffOp = new DiffOperator("Main.java");
148             //
149
try {
150                 TimeoutExpiredException afee = null;
151                 diffOp.next();
152                 diffOp.next();
153                 try {
154                     diffOp.next();
155                 } catch (TimeoutExpiredException e) {
156                     afee = e;
157                 }
158                 assertNotNull("TimeoutExpiredException was expected.", afee);
159                 
160                 //verify previous button
161
afee = null;
162                 diffOp.previous();
163                 diffOp.previous();
164                 try {
165                     diffOp.previous();
166                 } catch (TimeoutExpiredException e) {
167                     afee = e;
168                 }
169                 assertNotNull("TimeoutExpiredException was expected.", afee);
170             } catch (Exception JavaDoc e) {
171                 System.out.println("Problem with buttons of differences");
172             }
173             
174             //TestKit.removeAllData(PROJECT_NAME);
175
stream.flush();
176             stream.close();
177             
178         } catch (Exception JavaDoc e) {
179             throw new Exception JavaDoc("Test failed: " + e);
180         } finally {
181             TestKit.closeProject(PROJECT_NAME);
182         }
183     }
184 }
185
Popular Tags