KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > CvsWeb3_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.3 $ $Date: 2005/06/24 00:04:48 $
16  * @created on 12 oct. 2003
17  */

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

27     public CvsWeb3_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 CvsWeb3_0Interface(_grabber);
35     }
36
37     public void testDetect() throws Exception JavaDoc {
38         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_3_0.html");
39         _grabber.getWebOptions().setRootUrl("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/");
40         _interface.detect(doc);
41
42         assertEquals("FreeBSD-CVSweb 3.0.4", _interface.getType());
43     }
44
45     public void testGetFiles() throws Exception JavaDoc {
46         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_3_0.html");
47
48         int i = 0;
49         RemoteFile[] files = _interface.getFiles(doc);
50         assertEquals(".cvsignore", files[i].getName());
51         assertFalse(files[i].isInAttic());
52         assertEquals("1.2", files[i++].getVersion());
53
54         assertEquals("maven-jahiawar-plugin.jpx", files[i].getName());
55         assertFalse(files[i].isInAttic());
56         assertEquals("1.1", files[i++].getVersion());
57
58         assertEquals("maven.xml", files[i].getName());
59         assertFalse(files[i].isInAttic());
60         assertEquals("1.1", files[i++].getVersion());
61
62         assertEquals("plugin.jelly", files[i].getName());
63         assertFalse(files[i].isInAttic());
64         assertEquals("1.12", files[i++].getVersion());
65
66         assertEquals("plugin.properties", files[i].getName());
67         assertFalse(files[i].isInAttic());
68         assertEquals("1.5", files[i++].getVersion());
69
70         assertEquals("project.properties", files[i].getName());
71         assertFalse(files[i].isInAttic());
72         assertEquals("1.1", files[i++].getVersion());
73
74         assertEquals("project.xml", files[i].getName());
75         assertFalse(files[i].isInAttic());
76         assertEquals("1.7", files[i++].getVersion());
77
78         assertEquals("Expected no more files", i, files.length);
79
80     }
81
82     public void testGetDirectories() throws Exception JavaDoc {
83         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_3_0.html");
84
85         int i = 0;
86         String JavaDoc[] directories = _interface.getDirectories(doc);
87         assertEquals("src", directories[i++]);
88         assertEquals("xdocs", directories[i++]);
89
90         assertEquals("Expected no more directories", i, directories.length);
91
92     }
93
94     public void testGetDirectoryUrl() throws Exception JavaDoc {
95         assertEquals("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/src/", _interface.getDirectoryUrl("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/", "src"));
96         _interface.setVersionTag("JAHIA_4_0_5_PR");
97         assertEquals("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/src/?only_with_tag=JAHIA_4_0_5_PR", _interface.getDirectoryUrl("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/", "src"));
98     }
99
100     public void testGetDownloadUrl() throws Exception JavaDoc {
101         RemoteRepository repository = new RemoteRepository("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/", null);
102         RemoteDirectory dir = new RemoteDirectory(repository, "maven-jahiawar-plugin/", ".");
103         RemoteFile file = new RemoteFile("maven.xml", "1.1");
104         file.setDirectory(dir);
105
106         assertEquals("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/~checkout~/maven-jahiawar-plugin/maven.xml?rev=1.1", _interface.getDownloadUrl(file));
107     }
108
109     public void testGuessWebProperties() {
110         Properties JavaDoc webProperties = _interface.guessWebProperties("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/");
111         assertEquals("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
112         assertEquals("maven-jahiawar-plugin/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
113         assertNull(webProperties.get(CVSGrab.TAG_OPTION));
114         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
115         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
116         webProperties = _interface.guessWebProperties("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/maven-jahiawar-plugin/?sortby=date;only_with_tag=JAHIA_4_0_5_PR");
117         assertEquals("http://cvspub.jahia.org/cgi-bin/cvsweb.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
118         assertEquals("maven-jahiawar-plugin/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
119         assertEquals("JAHIA_4_0_5_PR", webProperties.get(CVSGrab.TAG_OPTION));
120         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
121         assertEquals("sortby=date", webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
122     }
123
124     public void testGetFilesJahia() throws Exception JavaDoc {
125         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_3_0_jahia.html");
126
127         int i = 0;
128         RemoteFile[] files = _interface.getFiles(doc);
129         assertEquals(".cvsignore", files[i].getName());
130         assertFalse(files[i].isInAttic());
131         assertEquals("1.2", files[i++].getVersion());
132
133         assertEquals("README", files[i].getName());
134         assertFalse(files[i].isInAttic());
135         assertEquals("1.58.4.2", files[i++].getVersion());
136
137         assertEquals("Expected no more files", i, files.length);
138
139     }
140
141     public void testGetDirectoriesJahia() throws Exception JavaDoc {
142         Document JavaDoc doc = getDocument("src/test/html_docs/cvsweb_3_0_jahia.html");
143
144         int i = 0;
145         String JavaDoc[] directories = _interface.getDirectories(doc);
146         assertEquals("CVS", directories[i++]);
147         assertEquals("core", directories[i++]);
148         assertEquals("docs", directories[i++]);
149         assertEquals("etc", directories[i++]);
150         assertEquals("external-search-engine", directories[i++]);
151         assertEquals("lib", directories[i++]);
152         assertEquals("metadata", directories[i++]);
153         assertEquals("patched-slide", directories[i++]);
154         assertEquals("pluto", directories[i++]);
155         assertEquals("slide", directories[i++]);
156         assertEquals("src", directories[i++]);
157         assertEquals("test", directories[i++]);
158         assertEquals("torque", directories[i++]);
159         assertEquals("var", directories[i++]);
160         assertEquals("xdocs", directories[i++]);
161
162         assertEquals("Expected no more directories", i, directories.length);
163
164     }
165
166
167 }
168
Popular Tags