KickJava   Java API By Example, From Geeks To Geeks.

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


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

21 public class ViewCvs0_8InterfaceTest extends AbstractTestCase {
22
23     private ViewCvs0_8Interface _interface;
24     private CVSGrab _grabber;
25
26     /**
27      * Constructor for ViewCvs0_8InterfaceTest
28      * @param testName
29      */

30     public ViewCvs0_8InterfaceTest(String JavaDoc testName) {
31         super(testName);
32     }
33
34     protected void setUp() throws Exception JavaDoc {
35         super.setUp();
36         _grabber = new CVSGrab();
37         _interface = new ViewCvs0_8Interface(_grabber);
38     }
39
40     public void testValidateAndDetect() throws Exception JavaDoc {
41         List JavaDoc errors = new ArrayList JavaDoc();
42         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_0_8.html");
43         _grabber.getWebOptions().setRootUrl("http://cvs.repository.org/viewcvs.py/");
44         _grabber.getWebOptions().setPackagePath("test");
45         CvsWebInterface.registerDocument("http://cvs.repository.org/viewcvs.py/test/", doc);
46         _interface.validate(errors);
47         assertTrue(errors.isEmpty());
48
49         assertEquals("ViewCVS 0.8", _interface.getType());
50     }
51
52     public void testGetFiles() throws Exception JavaDoc {
53         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_0_8.html");
54
55         int i = 0;
56         RemoteFile[] files = _interface.getFiles(doc);
57         assertEquals("AntRunner.properties", files[i].getName());
58         assertEquals("1.1.1.1", files[i++].getVersion());
59         assertEquals("CVSGrab.html", files[i].getName());
60         assertEquals("1.1.1.1", files[i++].getVersion());
61         assertEquals("CVSGrab.jpx", files[i].getName());
62         assertEquals("1.2", files[i++].getVersion());
63         assertEquals("HotSAX.library", files[i].getName());
64         assertEquals("1.1", files[i++].getVersion());
65         assertEquals("License.txt", files[i].getName());
66         assertEquals("1.1.1.1", files[i++].getVersion());
67         assertEquals("build.bat", files[i].getName());
68         assertEquals("1.1.1.1", files[i++].getVersion());
69         assertEquals("build.xml", files[i].getName());
70         assertEquals("1.4", files[i++].getVersion());
71         assertEquals("jCVS.library", files[i].getName());
72         assertEquals("1.1", files[i++].getVersion());
73
74         assertEquals("Expected no more files", i, files.length);
75
76     }
77
78     public void testGetDirectories() throws Exception JavaDoc {
79         Document JavaDoc doc = getDocument("src/test/html_docs/view_cvs_0_8.html");
80
81         int i = 0;
82         String JavaDoc[] directories = _interface.getDirectories(doc);
83         assertEquals("doc", directories[i++]);
84         assertEquals("etc", directories[i++]);
85         assertEquals("lib", directories[i++]);
86         assertEquals("src", directories[i++]);
87         assertEquals("web", directories[i++]);
88
89         assertEquals("Expected no more directories", i, directories.length);
90
91     }
92
93     /**
94      * Fix for bug #853915
95      */

96     public void testStrangeUrls() {
97         RemoteRepository repository = new RemoteRepository("http://cvs.sourceforge.net/viewcvs.py/", null);
98         RemoteDirectory dir = new RemoteDirectory(repository, "avantgarde/AvantGarde/src/st/fr/cageauxtrolls/avantgarde/gestion/partie/", "partie");
99         RemoteFile file = new RemoteFile("RestrictionsArm\u00E9e.java", "1.1");
100         file.setDirectory(dir);
101         String JavaDoc fileUrl = _interface.getDownloadUrl(file);
102         assertEquals("http://cvs.sourceforge.net/viewcvs.py/*checkout*/avantgarde/AvantGarde/src/st/fr/cageauxtrolls/avantgarde/gestion/partie/RestrictionsArm%E9e.java?rev=1.1", fileUrl);
103     }
104
105     public void testGuessWebProperties() {
106         Properties JavaDoc webProperties = _interface.guessWebProperties("http://cvs.sourceforge.net/viewcvs.py/cvsgrab/cvsgrab/");
107         assertEquals("http://cvs.sourceforge.net/viewcvs.py/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
108         assertEquals("cvsgrab/cvsgrab/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
109         assertNull(webProperties.get(CVSGrab.TAG_OPTION));
110         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
111         webProperties = _interface.guessWebProperties("http://cvs.sourceforge.net/viewcvs.py/cvsgrab/cvsgrab/?only_with_tag=RELEASE_2_0_3");
112         assertEquals("http://cvs.sourceforge.net/viewcvs.py/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
113         assertEquals("cvsgrab/cvsgrab/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
114         assertEquals("RELEASE_2_0_3", webProperties.get(CVSGrab.TAG_OPTION));
115         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
116     }
117
118 }
119
Popular Tags