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 CvsWeb3_0InterfaceTest extends AbstractTestCase { 19 20 private CvsWeb3_0Interface _interface; 21 private CVSGrab _grabber; 22 23 27 public CvsWeb3_0InterfaceTest(String testName) { 28 super(testName); 29 } 30 31 protected void setUp() throws Exception { 32 super.setUp(); 33 _grabber = new CVSGrab(); 34 _interface = new CvsWeb3_0Interface(_grabber); 35 } 36 37 public void testDetect() throws Exception { 38 Document 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 { 46 Document 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 { 83 Document doc = getDocument("src/test/html_docs/cvsweb_3_0.html"); 84 85 int i = 0; 86 String [] 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 { 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 { 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 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 { 125 Document 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 { 142 Document doc = getDocument("src/test/html_docs/cvsweb_3_0_jahia.html"); 143 144 int i = 0; 145 String [] 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 |