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_7InterfaceTest extends AbstractTestCase { 19 20 private ViewCvs0_7Interface _interface; 21 private CVSGrab _grabber; 22 23 27 public ViewCvs0_7InterfaceTest(String testName) { 28 super(testName); 29 } 30 31 protected void setUp() throws Exception { 32 super.setUp(); 33 _grabber = new CVSGrab(); 34 _interface = new ViewCvs0_7Interface(_grabber); 35 } 36 37 public void testDetect() throws Exception { 38 Document doc = getDocument("src/test/html_docs/view_cvs_0_7.html"); 39 _grabber.getWebOptions().setRootUrl("http://dev.eclipse.org/viewcvs/index.cgi/"); 40 _interface.detect(doc); 41 42 assertEquals("ViewCVS 0.7", _interface.getType()); 43 } 44 45 public void testGetFiles() throws Exception { 46 Document doc = getDocument("src/test/html_docs/view_cvs_0_7.html"); 47 48 int i = 0; 49 RemoteFile[] files = _interface.getFiles(doc); 50 assertEquals(".classpath", files[i].getName()); 51 assertFalse(files[i].isInAttic()); 52 assertEquals("1.3.2.2", files[i++].getVersion()); 53 54 assertEquals(".cvsignore", files[i].getName()); 55 assertFalse(files[i].isInAttic()); 56 assertEquals("1.1.2.1", files[i++].getVersion()); 57 58 assertEquals(".vcm_meta", files[i].getName()); 59 assertTrue(files[i].isInAttic()); 60 assertEquals("1.1.2.1", files[i++].getVersion()); 61 62 assertEquals("about.html", files[i].getName()); 63 assertFalse(files[i].isInAttic()); 64 assertEquals("1.4.2.1", files[i++].getVersion()); 65 66 assertEquals("ant.jar", files[i].getName()); 67 assertTrue(files[i].isInAttic()); 68 assertEquals("1.1.2.1", files[i++].getVersion()); 69 70 assertEquals("build.properties", files[i].getName()); 71 assertFalse(files[i].isInAttic()); 72 assertEquals("1.9.2.3", files[i++].getVersion()); 73 74 assertEquals("jakarta-ant-1.3-optional.jar", files[i].getName()); 75 assertTrue(files[i].isInAttic()); 76 assertEquals("1.1.2.1", files[i++].getVersion()); 77 78 assertEquals("plugin.jars", files[i].getName()); 79 assertTrue(files[i].isInAttic()); 80 assertEquals("1.1.2.2", files[i++].getVersion()); 81 82 assertEquals("plugin.properties", files[i].getName()); 83 assertFalse(files[i].isInAttic()); 84 assertEquals("1.1.2.1", files[i++].getVersion()); 85 86 assertEquals("plugin.xml", files[i].getName()); 87 assertFalse(files[i].isInAttic()); 88 assertEquals("1.5.2.3", files[i++].getVersion()); 89 90 assertEquals("Expected no more files", i, files.length); 91 92 } 93 94 public void testGetDirectories() throws Exception { 95 Document doc = getDocument("src/test/html_docs/view_cvs_0_7.html"); 96 97 int i = 0; 98 String [] directories = _interface.getDirectories(doc); 99 assertEquals(".externalToolBuilders", directories[i++]); 100 assertEquals("buildfiles", directories[i++]); 101 assertEquals("doc", directories[i++]); 102 assertEquals("lib", directories[i++]); 103 assertEquals("notes", directories[i++]); 104 assertEquals("old_root", directories[i++]); 105 assertEquals("os", directories[i++]); 106 assertEquals("schema", directories[i++]); 107 assertEquals("scripts", directories[i++]); 108 assertEquals("src", directories[i++]); 109 assertEquals("src_ant", directories[i++]); 110 111 assertEquals("Expected no more directories", i, directories.length); 112 113 } 114 115 public void testGetDirectoryUrl() throws Exception { 116 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ant.core/", _interface.getDirectoryUrl("http://dev.eclipse.org/viewcvs/index.cgi/", "org.eclipse.ant.core/")); 117 _interface.setVersionTag("R2_0_1"); 118 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ant.core/?only_with_tag=R2_0_1", _interface.getDirectoryUrl("http://dev.eclipse.org/viewcvs/index.cgi/", "org.eclipse.ant.core/")); 119 } 120 121 public void testGetDownloadUrl() throws Exception { 122 RemoteRepository repository = new RemoteRepository("http://dev.eclipse.org/viewcvs/index.cgi/", null); 123 RemoteDirectory dir = new RemoteDirectory(repository, "org.eclipse.ant.core/", "ant-core"); 124 RemoteFile file = new RemoteFile("about.html", "1.16"); 125 file.setDirectory(dir); 126 127 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/org.eclipse.ant.core/about.html?rev=1.16", _interface.getDownloadUrl(file)); 128 129 file = new RemoteFile("ant.jar", "1.1.2.1"); 130 file.setDirectory(dir); 131 file.setInAttic(true); 132 133 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/org.eclipse.ant.core/Attic/ant.jar?rev=1.1.2.1", _interface.getDownloadUrl(file)); 134 } 135 136 public void testGuessWebProperties() { 137 Properties webProperties = _interface.guessWebProperties("http://dev.eclipse.org/viewcvs/index.cgi/jdt-core-home/"); 138 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 139 assertEquals("jdt-core-home/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 140 assertNull(webProperties.get(CVSGrab.TAG_OPTION)); 141 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 142 webProperties = _interface.guessWebProperties("http://dev.eclipse.org/viewcvs/index.cgi/jdt-core-home/?only_with_tag=MAIN"); 143 assertEquals("http://dev.eclipse.org/viewcvs/index.cgi/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 144 assertEquals("jdt-core-home/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 145 assertEquals("MAIN", webProperties.get(CVSGrab.TAG_OPTION)); 146 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 147 } 148 } 149 | Popular Tags |