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 ; 10 11 import java.util.Properties ; 12 13 18 public class ViewCvs0_9InterfaceTest extends AbstractTestCase { 19 20 private ViewCvs0_9Interface _interface; 21 private CVSGrab _grabber; 22 23 27 public ViewCvs0_9InterfaceTest(String testName) { 28 super(testName); 29 } 30 31 protected void setUp() throws Exception { 32 super.setUp(); 33 _grabber = new CVSGrab(); 34 _interface = new ViewCvs0_9Interface(_grabber); 35 } 36 37 public void testDetect() throws Exception { 38 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2.html"); 39 _grabber.getWebOptions().setRootUrl("http://cvs.apache.org/viewcvs/"); 40 _interface.detect(doc); 41 42 assertEquals("ViewCVS 0.9.2", _interface.getType()); 43 } 44 45 public void testDetectWithGraph() throws Exception { 46 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2_graph.html"); 47 CVSGrab grabber = new CVSGrab(); 48 grabber.getWebOptions().setRootUrl("http://cvs.apache.org/viewcvs/"); 49 _interface.detect(doc); 50 51 assertEquals("ViewCVS 0.9.2", _interface.getType()); 52 } 53 54 public void testDetectWithMultipleRoots() throws Exception { 55 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2_multi_roots.html"); 56 CVSGrab grabber = new CVSGrab(); 57 grabber.getWebOptions().setRootUrl("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/"); 58 _interface.detect(doc); 59 60 assertEquals("ViewCVS 0.9.2", _interface.getType()); 61 assertEquals("ooo4r", _interface.getProjectRoot()); 62 } 63 64 public void testGetFiles() throws Exception { 65 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2.html"); 66 67 int i = 0; 68 RemoteFile[] files = _interface.getFiles(doc); 69 assertEquals(".cvsignore", files[i].getName()); 70 assertFalse(files[i].isInAttic()); 71 assertEquals("1.2", files[i++].getVersion()); 72 73 assertEquals("INSTALL", files[i].getName()); 74 assertFalse(files[i].isInAttic()); 75 assertEquals("1.14", files[i++].getVersion()); 76 77 assertEquals("LICENSE.APL", files[i].getName()); 78 assertTrue(files[i].isInAttic()); 79 assertEquals("1.2", files[i++].getVersion()); 80 81 assertEquals("Makefile", files[i].getName()); 82 assertTrue(files[i].isInAttic()); 83 assertEquals("1.2", files[i++].getVersion()); 84 85 assertEquals("build.bat", files[i].getName()); 86 assertTrue(files[i].isInAttic()); 87 assertEquals("1.1", files[i++].getVersion()); 88 89 assertEquals("build.sh", files[i].getName()); 90 assertTrue(files[i].isInAttic()); 91 assertEquals("1.1", files[i++].getVersion()); 92 93 assertEquals("Expected no more files", i, files.length); 94 95 } 96 97 public void testGetDirectories() throws Exception { 98 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2.html"); 99 100 int i = 0; 101 String [] directories = _interface.getDirectories(doc); 102 assertEquals("bin", directories[i++]); 103 assertEquals("build", directories[i++]); 104 assertEquals("contribs", directories[i++]); 105 assertEquals("docs", directories[i++]); 106 assertEquals("examples", directories[i++]); 107 assertEquals("icons", directories[i++]); 108 assertEquals("log4jMini", directories[i++]); 109 assertEquals("make", directories[i++]); 110 assertEquals("packaging", directories[i++]); 111 assertEquals("src", directories[i++]); 112 assertEquals("tests", directories[i++]); 113 114 assertEquals("Expected no more directories", i, directories.length); 115 116 } 117 118 public void testGetDirectoryUrl() throws Exception { 119 assertEquals("http://cvs.apache.org/viewcvs/jakarta-log4j/", _interface.getDirectoryUrl("http://cvs.apache.org/viewcvs/", "jakarta-log4j")); 120 121 _interface.setVersionTag("v_1_1"); 123 assertEquals("http://cvs.apache.org/viewcvs/jakarta-log4j/?only_with_tag=v_1_1", _interface.getDirectoryUrl("http://cvs.apache.org/viewcvs/", "jakarta-log4j")); 124 125 _grabber.getWebOptions().setRootUrl("http://dev.eclipse.org/viewcvs/index.cgi/"); 127 _grabber.getWebOptions().setProjectRoot("Technology_Project"); 128 _interface.setVersionTag(null); 129 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ercp/?cvsroot=Technology_Project", _interface.getDirectoryUrl("http://dev.eclipse.org/viewcvs/index.cgi/", "org.eclipse.ercp")); 130 } 131 132 public void testGetDownloadUrl() throws Exception { 133 RemoteRepository repository = new RemoteRepository("http://cvs.apache.org/viewcvs/", null); 134 RemoteDirectory dir = new RemoteDirectory(repository, "jakarta-log4j", "log4j"); 135 RemoteFile file = new RemoteFile("INSTALL", "1.14"); 136 file.setDirectory(dir); 137 file.setInAttic(false); 138 assertEquals("http://cvs.apache.org/viewcvs/*checkout*/jakarta-log4j/INSTALL?rev=1.14", _interface.getDownloadUrl(file)); 139 140 file = new RemoteFile("Makefile", "1.2"); 141 file.setDirectory(dir); 142 file.setInAttic(true); 143 assertEquals("http://cvs.apache.org/viewcvs/*checkout*/jakarta-log4j/Attic/Makefile?rev=1.2", _interface.getDownloadUrl(file)); 144 } 145 146 public void testGetFilesWithGraph() throws Exception { 147 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2_graph.html"); 148 149 int i = 0; 150 RemoteFile[] files = _interface.getFiles(doc); 151 assertEquals(".cvsignore", files[i].getName()); 152 assertFalse(files[i].isInAttic()); 153 assertEquals("1.25", files[i++].getVersion()); 154 155 assertEquals("BuildCVS.txt", files[i].getName()); 156 assertFalse(files[i].isInAttic()); 157 assertEquals("1.34", files[i++].getVersion()); 158 159 assertEquals("Makefile.in", files[i].getName()); 160 assertFalse(files[i].isInAttic()); 161 assertEquals("1.352", files[i++].getVersion()); 162 163 assertEquals("acinclude.m4", files[i].getName()); 164 assertFalse(files[i].isInAttic()); 165 assertEquals("1.14", files[i++].getVersion()); 166 167 assertEquals("aclocal.m4", files[i].getName()); 168 assertFalse(files[i].isInAttic()); 169 assertEquals("1.57", files[i++].getVersion()); 170 171 assertEquals("autoconf_inc.m4", files[i].getName()); 172 assertFalse(files[i].isInAttic()); 173 assertEquals("1.44", files[i++].getVersion()); 174 } 175 176 public void testGetDirectoriesWithGraph() throws Exception { 177 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2_graph.html"); 178 179 int i = 0; 180 String [] directories = _interface.getDirectories(doc); 181 assertEquals("art", directories[i++]); 182 assertEquals("build", directories[i++]); 183 assertEquals("contrib", directories[i++]); 184 assertEquals("debian", directories[i++]); 185 assertEquals("demos", directories[i++]); 186 assertEquals("distrib", directories[i++]); 187 assertEquals("docs", directories[i++]); 188 assertEquals("include", directories[i++]); 189 assertEquals("install", directories[i++]); 190 assertEquals("lib", directories[i++]); 191 assertEquals("locale", directories[i++]); 192 assertEquals("misc", directories[i++]); 193 assertEquals("mobile", directories[i++]); 194 assertEquals("samples", directories[i++]); 195 assertEquals("setup", directories[i++]); 196 assertEquals("src", directories[i++]); 197 assertEquals("tests", directories[i++]); 198 assertEquals("user", directories[i++]); 199 assertEquals("utils", directories[i++]); 200 assertEquals("wxPython", directories[i++]); 201 } 202 203 public void testGetDirectoryUrlWithMultipleRoots() throws Exception { 204 _interface.setProjectRoot("ooo4r"); 205 assertEquals("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/ooo4r/?cvsroot=ooo4r", _interface.getDirectoryUrl("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/", "ooo4r")); 206 _interface.setVersionTag("jamesgb"); 207 assertEquals("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/ooo4r/?cvsroot=ooo4r&only_with_tag=jamesgb", _interface.getDirectoryUrl("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/", "ooo4r")); 208 } 209 210 public void testGetDownloadUrlWithMultipleRoots() throws Exception { 211 _interface.setProjectRoot("ooo4r"); 212 RemoteRepository repository = new RemoteRepository("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/", null); 213 RemoteDirectory dir = new RemoteDirectory(repository, "ooo4r", "ooo4r"); 214 RemoteFile file = new RemoteFile("README.txt", "1.1"); 215 file.setDirectory(dir); 216 file.setInAttic(false); 217 assertEquals("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/*checkout*/ooo4r/README.txt?cvsroot=ooo4r&rev=1.1", _interface.getDownloadUrl(file)); 218 } 219 220 public void testGetFilesOnEclipse() throws Exception { 221 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2_eclipse.html"); 222 223 int i = 0; 224 RemoteFile[] files = _interface.getFiles(doc); 225 assertEquals(".classpath", files[i].getName()); 226 assertFalse(files[i].isInAttic()); 227 assertEquals("1.6", files[i++].getVersion()); 228 229 assertEquals(".project", files[i].getName()); 230 assertFalse(files[i].isInAttic()); 231 assertEquals("1.4", files[i++].getVersion()); 232 233 assertEquals("about.html", files[i].getName()); 234 assertFalse(files[i].isInAttic()); 235 assertEquals("1.15", files[i++].getVersion()); 236 237 assertEquals("build.properties", files[i].getName()); 238 assertFalse(files[i].isInAttic()); 239 assertEquals("1.10", files[i++].getVersion()); 240 241 assertEquals("cpl-v10.html", files[i].getName()); 242 assertFalse(files[i].isInAttic()); 243 assertEquals("1.1", files[i++].getVersion()); 244 245 assertEquals("junit.jar", files[i].getName()); 246 assertFalse(files[i].isInAttic()); 247 assertEquals("1.4", files[i++].getVersion()); 248 249 assertEquals("junitsrc.zip", files[i].getName()); 250 assertFalse(files[i].isInAttic()); 251 assertEquals("1.5", files[i++].getVersion()); 252 253 assertEquals("plugin.properties", files[i].getName()); 254 assertFalse(files[i].isInAttic()); 255 assertEquals("1.4", files[i++].getVersion()); 256 257 assertEquals("plugin.xml", files[i].getName()); 258 assertFalse(files[i].isInAttic()); 259 assertEquals("1.9", files[i++].getVersion()); 260 261 assertEquals("Expected no more files", i, files.length); 262 263 } 264 265 public void testGetDirectoriesOnEclipse() throws Exception { 266 Document doc = getDocument("src/test/html_docs/view_cvs_0_9_2_eclipse.html"); 267 268 int i = 0; 269 String [] directories = _interface.getDirectories(doc); 270 assertEquals("META-INF", directories[i++]); 271 assertEquals("scripts", directories[i++]); 272 273 assertEquals("Expected no more directories", i, directories.length); 274 275 } 276 277 public void testGuessWebProperties() { 278 Properties webProperties = _interface.guessWebProperties("http://cvs.apache.org/viewcvs/jakarta-log4j/?only_with_tag=v_1_1"); 279 assertEquals("http://cvs.apache.org/viewcvs/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 280 assertEquals("jakarta-log4j/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 281 assertEquals("v_1_1", webProperties.get(CVSGrab.TAG_OPTION)); 282 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 283 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 284 285 webProperties = _interface.guessWebProperties("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/ooo4r/?only_with_tag=jamesgb&cvsroot=ooo4r"); 286 assertEquals("http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 287 assertEquals("ooo4r/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 288 assertEquals("jamesgb", webProperties.get(CVSGrab.TAG_OPTION)); 289 assertEquals("ooo4r", webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 290 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 291 292 webProperties = _interface.guessWebProperties("http://savannah.gnu.org/cgi-bin/viewcvs/sed/"); 293 assertEquals("http://savannah.gnu.org/cgi-bin/viewcvs/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 294 assertEquals("sed/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 295 assertNull(webProperties.get(CVSGrab.TAG_OPTION)); 296 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 297 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 298 299 webProperties = _interface.guessWebProperties("http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ercp/?cvsroot=Technology_Project"); 300 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 301 assertEquals("org.eclipse.ercp/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 302 assertNull(webProperties.get(CVSGrab.TAG_OPTION)); 303 assertEquals("Technology_Project", webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 304 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 305 } 306 307 308 } 309 | Popular Tags |