KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > CvsWeb2_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.8 $ $Date: 2005/06/25 13:23:40 $
16  * @created on 12 oct. 2003
17  */

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

27     public CvsWeb2_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 CvsWeb2_0Interface(_grabber);
35     }
36
37     public void testDetect() throws Exception JavaDoc {
38         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_2_0.html");
39         _grabber.getWebOptions().setRootUrl("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/");
40         _interface.detect(doc);
41
42         assertEquals("FreeBSD-CVSweb 2.0.6", _interface.getType());
43     }
44
45     /**
46      * Bug #1069355
47      * @throws Exception
48      */

49     public void testDetectSgi() throws Exception JavaDoc {
50         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_2_0_sgi.html");
51         CVSGrab grabber = new CVSGrab();
52         grabber.getWebOptions().setRootUrl("http://oss.sgi.com/cgi-bin/cvsweb.cgi/");
53         _interface.detect(doc);
54
55         assertEquals("FreeBSD-cvsweb 2.0.0", _interface.getType());
56     }
57
58     public void testGetFiles() throws Exception JavaDoc {
59         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_2_0.html");
60
61         int i = 0;
62         RemoteFile[] files = _interface.getFiles(doc);
63         assertEquals(".cvsignore", files[i].getName());
64         assertFalse(files[i].isInAttic());
65         assertEquals("1.1", files[i++].getVersion());
66
67         assertEquals("Makefile.am", files[i].getName());
68         assertFalse(files[i].isInAttic());
69         assertEquals("1.13", files[i++].getVersion());
70
71         assertEquals("docbook.toolbar.tgz", files[i].getName());
72         assertFalse(files[i].isInAttic());
73         assertEquals("1.2", files[i++].getVersion());
74
75         assertEquals("kde_docbook.toolbar.tgz", files[i].getName());
76         assertFalse(files[i].isInAttic());
77         assertEquals("1.1", files[i++].getVersion());
78
79         assertEquals("Expected no more files", i, files.length);
80
81     }
82
83     public void testGetDirectories() throws Exception JavaDoc {
84         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_2_0.html");
85
86 // logDocument(doc);
87
// testXpath(doc, "//TR/TD");
88

89         int i = 0;
90         String JavaDoc[] directories = _interface.getDirectories(doc);
91         assertEquals("cfml", directories[i++]);
92         assertEquals("default", directories[i++]);
93         assertEquals("docbook", directories[i++]);
94         assertEquals("html", directories[i++]);
95         assertEquals("kde-docbook", directories[i++]);
96         assertEquals("schema", directories[i++]);
97         assertEquals("tagxml", directories[i++]);
98         assertEquals("wml-1-2", directories[i++]);
99         assertEquals("xml", directories[i++]);
100
101         assertEquals("Expected no more directories", i, directories.length);
102
103     }
104
105     public void testGetDirectoryUrl() throws Exception JavaDoc {
106         assertEquals("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/quanta/quanta/data/toolbars/", _interface.getDirectoryUrl("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/quanta/quanta/data/", "toolbars"));
107         _interface.setVersionTag("KDE_3_2_0_ALPHA_1");
108         assertEquals("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/quanta/quanta/data/toolbars/?only_with_tag=KDE_3_2_0_ALPHA_1", _interface.getDirectoryUrl("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/quanta/quanta/data/", "toolbars"));
109     }
110
111     public void testGetDownloadUrl() throws Exception JavaDoc {
112         RemoteRepository repository = new RemoteRepository("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/", null);
113         RemoteDirectory dir = new RemoteDirectory(repository, "quanta/quanta/data/toolbars", "toolbars");
114         RemoteFile file = new RemoteFile("Makefile.am", "1.13");
115         file.setDirectory(dir);
116
117         assertEquals("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/quanta/quanta/data/toolbars/Makefile.am?rev=1.13", _interface.getDownloadUrl(file));
118
119         file = new RemoteFile("Makefile", "1.1");
120         file.setDirectory(dir);
121         file.setInAttic(true);
122
123         assertEquals("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/~checkout~/quanta/quanta/data/toolbars/Attic/Makefile?rev=1.1", _interface.getDownloadUrl(file));
124
125     }
126
127     public void testGuessWebProperties() {
128         Properties JavaDoc webProperties = _interface.guessWebProperties("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/quanta/");
129         assertEquals("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
130         assertEquals("quanta/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
131         assertNull(webProperties.get(CVSGrab.TAG_OPTION));
132         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
133         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
134         webProperties = _interface.guessWebProperties("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/quanta/?sortby=date;only_with_tag=QUANTA_3_1_BRANCH");
135         assertEquals("http://webcvs.kde.org/cgi-bin/cvsweb.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
136         assertEquals("quanta/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
137         assertEquals("QUANTA_3_1_BRANCH", webProperties.get(CVSGrab.TAG_OPTION));
138         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
139         assertEquals("sortby=date", webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
140     }
141
142
143 }
144
Popular Tags