KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > ViewCvs1_0InterfaceTest


1 package net.sourceforge.cvsgrab.web;
2
3 import net.sourceforge.cvsgrab.AbstractTestCase;
4 import net.sourceforge.cvsgrab.CVSGrab;
5 import net.sourceforge.cvsgrab.RemoteDirectory;
6 import net.sourceforge.cvsgrab.RemoteFile;
7 import net.sourceforge.cvsgrab.RemoteRepository;
8
9 import org.w3c.dom.Document JavaDoc;
10
11 import java.util.Properties JavaDoc;
12
13 /**
14  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
15  * @version $Revision: 1.11 $ $Date: 2005/06/22 23:38:15 $
16  * @created on 12 oct. 2003
17  */

18 public class ViewCvs1_0InterfaceTest extends AbstractTestCase {
19
20     private ViewCvs1_0Interface _interface;
21     private CVSGrab _grabber;
22     
23     /**
24      * Constructor for ViewCvs1_0InterfaceTest
25      * @param testName
26      */

27     public ViewCvs1_0InterfaceTest(String JavaDoc testName) {
28         super(testName);
29     }
30
31     protected void setUp() throws Exception JavaDoc {
32         super.setUp();
33         _grabber = new CVSGrab();
34         _interface = new ViewCvs1_0Interface(_grabber);
35         _interface.setRoot("picocontainer");
36     }
37
38     public void testDetect() throws Exception JavaDoc {
39         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0.html");
40         _grabber.getWebOptions().setRootUrl("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/");
41         _interface.detect(doc);
42         
43         assertEquals("ViewCVS 1.0-dev", _interface.getType());
44         assertEquals("picocontainer", _interface.getRoot());
45         
46         doc = getDocument("src/test/html_docs/view_cvs_1_0_maven.html");
47         _grabber.getWebOptions().setRootUrl("http://cvs.apache.org/viewcvs.cgi/");
48         _interface.detect(doc);
49         
50         assertEquals("ViewCVS 1.0-dev", _interface.getType());
51         assertNull(_interface.getRoot());
52     }
53
54     /**
55      * Test for bug #2308061, no root defined in the web page,
56      * xpath //A/@href[contains(., 'root=')] returns null
57      * @throws Exception if the test fails
58      */

59     public void testDetectBusyBox() throws Exception JavaDoc {
60         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0_busybox.net.html");
61         _grabber.getWebOptions().setRootUrl("http://cvs.uclibc.org/cgi-bin/cvsweb/");
62         _interface.detect(doc);
63         
64         assertEquals("ViewCVS 1.0-dev", _interface.getType());
65         assertNull(_interface.getRoot());
66     }
67     
68     /**
69      * Test for bug #1024587, cannot download file in Attic, caused by bad detection of attic flag
70      * @throws Exception if the test fails
71      */

72     public void testFileInAttic() throws Exception JavaDoc {
73         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0_attic.html");
74         CVSGrab grabber = new CVSGrab();
75         grabber.getWebOptions().setRootUrl("http://cvs.apache.org/viewcvs.cgi/");
76         grabber.getWebOptions().setVersionTag("JCS_1_0");
77         
78         int i = 0;
79         RemoteFile[] files = _interface.getFiles(doc);
80         assertEquals("ILateralCacheTCPListener.java", files[i].getName());
81         assertTrue(files[i].isInAttic());
82         assertEquals("1.1.1.1", files[i++].getVersion());
83         
84         assertEquals("Expected no more files", i, files.length);
85     }
86     
87     public void testGetFiles() throws Exception JavaDoc {
88         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0.html");
89         
90         int i = 0;
91         RemoteFile[] files = _interface.getFiles(doc);
92         assertEquals(".cvsignore", files[i].getName());
93         assertFalse(files[i].isInAttic());
94         assertEquals("1.11", files[i++].getVersion());
95         
96         assertEquals("LICENSE.txt", files[i].getName());
97         assertFalse(files[i].isInAttic());
98         assertEquals("1.1", files[i++].getVersion());
99         
100         assertEquals("TODO.txt", files[i].getName());
101         assertFalse(files[i].isInAttic());
102         assertEquals("1.5", files[i++].getVersion());
103         
104         assertEquals("build.xml", files[i].getName());
105         assertFalse(files[i].isInAttic());
106         assertEquals("1.8", files[i++].getVersion());
107         
108         assertEquals("continuous-integration.sh", files[i].getName());
109         assertFalse(files[i].isInAttic());
110         assertEquals("1.15", files[i++].getVersion());
111         
112         assertEquals("maven.xml", files[i].getName());
113         assertFalse(files[i].isInAttic());
114         assertEquals("1.16", files[i++].getVersion());
115         
116         assertEquals("project.properties", files[i].getName());
117         assertFalse(files[i].isInAttic());
118         assertEquals("1.10", files[i++].getVersion());
119         
120         assertEquals("project.xml", files[i].getName());
121         assertFalse(files[i].isInAttic());
122         assertEquals("1.39", files[i++].getVersion());
123         
124         assertEquals("ClassRegistrationPicoContainer.java", files[i].getName());
125         assertTrue(files[i].isInAttic());
126         assertEquals("1.4", files[i++].getVersion());
127         
128         assertEquals("Expected no more files", i, files.length);
129         
130     }
131     
132     public void testGetDirectories() throws Exception JavaDoc {
133         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0.html");
134         
135         int i = 0;
136         String JavaDoc[] directories = _interface.getDirectories(doc);
137         assertEquals("src", directories[i++]);
138         assertEquals("xdocs", directories[i++]);
139         
140         assertEquals("Expected no more directories", i, directories.length);
141         
142     }
143  
144     /**
145      * Bug #1077452
146      */

147     public void testGetFilesMaven() throws Exception JavaDoc {
148         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0_maven.html");
149         
150         int i = 0;
151         RemoteFile[] files = _interface.getFiles(doc);
152         assertEquals(".cvsignore", files[i].getName());
153         assertFalse(files[i].isInAttic());
154         assertEquals("1.20", files[i++].getVersion());
155         
156         assertEquals("KEYS", files[i].getName());
157         assertFalse(files[i].isInAttic());
158         assertEquals("1.2", files[i++].getVersion());
159         
160         assertEquals("LICENSE.txt", files[i].getName());
161         assertFalse(files[i].isInAttic());
162         assertEquals("1.6", files[i++].getVersion());
163         
164         assertEquals("NOTICE.txt", files[i].getName());
165         assertFalse(files[i].isInAttic());
166         assertEquals("1.2", files[i++].getVersion());
167         
168         assertEquals("README.txt", files[i].getName());
169         assertFalse(files[i].isInAttic());
170         assertEquals("1.2", files[i++].getVersion());
171         
172         assertEquals("build-bootstrap.xml", files[i].getName());
173         assertFalse(files[i].isInAttic());
174         assertEquals("1.219", files[i++].getVersion());
175         
176         assertEquals("checkstyle-license.txt", files[i].getName());
177         assertFalse(files[i].isInAttic());
178         assertEquals("1.2", files[i++].getVersion());
179         
180         assertEquals("checkstyle.xml", files[i].getName());
181         assertFalse(files[i].isInAttic());
182         assertEquals("1.4", files[i++].getVersion());
183         
184         assertEquals("gump.xml", files[i].getName());
185         assertFalse(files[i].isInAttic());
186         assertEquals("1.9", files[i++].getVersion());
187         
188         assertEquals("maven.xml", files[i].getName());
189         assertFalse(files[i].isInAttic());
190         assertEquals("1.109", files[i++].getVersion());
191         
192         assertEquals("plugin-profile.xml", files[i].getName());
193         assertFalse(files[i].isInAttic());
194         assertEquals("1.4", files[i++].getVersion());
195         
196         assertEquals("plugins-site.xml", files[i].getName());
197         assertFalse(files[i].isInAttic());
198         assertEquals("1.3", files[i++].getVersion());
199         
200         assertEquals("project.properties", files[i].getName());
201         assertFalse(files[i].isInAttic());
202         assertEquals("1.69", files[i++].getVersion());
203         
204         assertEquals("project.xml", files[i].getName());
205         assertFalse(files[i].isInAttic());
206         assertEquals("1.343", files[i++].getVersion());
207         
208         assertEquals("release.xml", files[i].getName());
209         assertFalse(files[i].isInAttic());
210         assertEquals("1.2", files[i++].getVersion());
211         
212         assertEquals("Expected no more files", i, files.length);
213         
214     }
215     
216     /**
217      * Bug #1077452
218      */

219     public void testGetDirectoriesMaven() throws Exception JavaDoc {
220         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_1_0_maven.html");
221         
222         int i = 0;
223         String JavaDoc[] directories = _interface.getDirectories(doc);
224         assertEquals("announcements", directories[i++]);
225         assertEquals("conf", directories[i++]);
226         assertEquals("maven-jelly-tags", directories[i++]);
227         assertEquals("src", directories[i++]);
228         assertEquals("xdocs", directories[i++]);
229
230         assertEquals("Expected no more directories", i, directories.length);
231         
232     }
233  
234     public void testGetDirectoryUrl() throws Exception JavaDoc {
235         assertEquals("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/pico/src/java/picocontainer/?root=picocontainer",
236             _interface.getDirectoryUrl("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/", "pico/src/java/picocontainer"));
237         _interface.setVersionTag("PICOCONTAINER_1_0_ALPHA_1");
238         assertEquals("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/pico/src/java/picocontainer/?only_with_tag=PICOCONTAINER_1_0_ALPHA_1&root=picocontainer",
239             _interface.getDirectoryUrl("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/", "pico/src/java/picocontainer"));
240     }
241     
242     public void testGetDownloadUrl() throws Exception JavaDoc {
243         RemoteRepository repository = new RemoteRepository("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/", null);
244         RemoteDirectory dir = new RemoteDirectory(repository, "pico/src/java/org/picocontainer", "picocontainer");
245         RemoteFile file = new RemoteFile("PicoContainer.java", "1.10");
246         file.setDirectory(dir);
247         file.setInAttic(false);
248         assertEquals("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/*checkout*/pico/src/java/org/picocontainer/PicoContainer.java?rev=1.10&root=picocontainer", _interface.getDownloadUrl(file));
249         
250         dir = new RemoteDirectory(repository, "pico/src/java/picocontainer", "picocontainer");
251         file = new RemoteFile("ClassRegistrationPicoContainer.java", "1.4");
252         file.setDirectory(dir);
253         file.setInAttic(true);
254         assertEquals("http://cvs.picocontainer.codehaus.org/viewcvs.cgi/*checkout*/pico/src/java/picocontainer/Attic/ClassRegistrationPicoContainer.java?rev=1.4&root=picocontainer", _interface.getDownloadUrl(file));
255     }
256     
257     /**
258      * Fix for help request https://sourceforge.net/forum/message.php?msg_id=2294014
259      */

260     public void testStrangeUrls() {
261         _interface.setRoot(null);
262         String JavaDoc directoryUrl = _interface.getDirectoryUrl("http://cvs.apache.org/viewcvs.cgi/",
263                         "ant/src/etc/testcases/core/include/frag#ment/");
264         assertEquals("http://cvs.apache.org/viewcvs.cgi/ant/src/etc/testcases/core/include/frag%23ment/", directoryUrl);
265         directoryUrl = _interface.getDirectoryUrl("http://cvs.apache.org/viewcvs.cgi/",
266                         "ant/src/etc/testcases/core/include/with space/");
267         assertEquals("http://cvs.apache.org/viewcvs.cgi/ant/src/etc/testcases/core/include/with%20space/", directoryUrl);
268     }
269     
270     public void testGuessWebProperties() {
271         Properties JavaDoc webProperties = _interface.guessWebProperties("http://cvs.apache.org/viewcvs.cgi/ant/");
272         assertEquals("http://cvs.apache.org/viewcvs.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
273         assertEquals("ant/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
274         assertNull(webProperties.get(CVSGrab.TAG_OPTION));
275         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
276         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
277         webProperties = _interface.guessWebProperties("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/ooo4r/?only_with_tag=jamesgb&cvsroot=ooo4r");
278         assertEquals("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
279         assertEquals("ooo4r/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
280         assertEquals("jamesgb", webProperties.get(CVSGrab.TAG_OPTION));
281         assertEquals("ooo4r", webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
282         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
283     }
284     
285 }
286
Popular Tags