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 CvsWeb1_0InterfaceTest extends AbstractTestCase { 19 20 private CvsWeb1_0Interface _interface; 21 private CVSGrab _grabber; 22 23 27 public CvsWeb1_0InterfaceTest(String testName) { 28 super(testName); 29 } 30 31 protected void setUp() throws Exception { 32 super.setUp(); 33 _grabber = new CVSGrab(); 34 _interface = new CvsWeb1_0Interface(_grabber); 35 } 36 37 public void testDetect() throws Exception { 38 Document doc = getDocument("src/test/html_docs/cvsweb_1_0.html"); 39 _grabber.getWebOptions().setRootUrl("http://dev.w3.org/cvsweb/"); 40 _interface.detect(doc); 41 42 assertEquals("hennerik CVSweb Revision: 1.1", _interface.getType()); 43 44 doc = getDocument("src/test/html_docs/cvsweb_1_58.html"); 45 _grabber.getWebOptions().setRootUrl("http://dev.w3.org/cvsweb/"); 46 _interface.detect(doc); 47 48 assertEquals("hennerik CVSweb Revision: 1.58", _interface.getType()); 49 } 50 51 public void testGetFiles() throws Exception { 52 Document doc = getDocument("src/test/html_docs/cvsweb_1_0.html"); 53 54 int i = 0; 55 RemoteFile[] files = _interface.getFiles(doc); 56 assertEquals("README.cvs", files[i].getName()); 57 assertFalse(files[i].isInAttic()); 58 assertEquals("1.1", files[i++].getVersion()); 59 60 assertEquals("Expected no more files", i, files.length); 61 } 62 63 public void testGetDirectories() throws Exception { 64 Document doc = getDocument("src/test/html_docs/cvsweb_1_0.html"); 65 66 int i = 0; 67 String [] directories = _interface.getDirectories(doc); 68 assertEquals("classes", directories[i++]); 69 assertEquals("classes.EGP", directories[i++]); 70 assertEquals("lib", directories[i++]); 71 assertEquals("makefiles", directories[i++]); 72 73 assertEquals("Expected no more directories", i, directories.length); 74 } 75 76 public void testGetDirectoryUrl() throws Exception { 77 assertEquals("http://dev.w3.org/cvsweb/java/", _interface.getDirectoryUrl("http://dev.w3.org/cvsweb/", "java")); 78 _interface.setVersionTag("R_2_0_3_B0"); 79 assertEquals("http://dev.w3.org/cvsweb/java/?only_with_tag=R_2_0_3_B0", _interface.getDirectoryUrl("http://dev.w3.org/cvsweb/", "java")); 80 } 81 82 public void testGetDownloadUrl() throws Exception { 83 RemoteRepository repository = new RemoteRepository("http://dev.w3.org/cvsweb/", null); 84 RemoteDirectory dir = new RemoteDirectory(repository, "java", "java"); 85 RemoteFile file = new RemoteFile("README.cvs", "1.1"); 86 file.setDirectory(dir); 87 88 assertEquals("http://dev.w3.org/cvsweb/~checkout~/java/README.cvs?rev=1.1", _interface.getDownloadUrl(file)); 89 } 90 91 public void testGuessWebProperties() { 92 Properties webProperties = _interface.guessWebProperties("http://dev.w3.org/cvsweb/java/"); 93 assertEquals("http://dev.w3.org/cvsweb/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 94 assertEquals("java/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 95 assertNull(webProperties.get(CVSGrab.TAG_OPTION)); 96 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 97 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 98 webProperties = _interface.guessWebProperties("http://dev.w3.org/cvsweb/java/?only_with_tag=R_2_0_3_B0"); 99 assertEquals("http://dev.w3.org/cvsweb/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 100 assertEquals("java/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 101 assertEquals("R_2_0_3_B0", webProperties.get(CVSGrab.TAG_OPTION)); 102 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 103 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 104 } 105 106 public void testGetFilesXPDevelopper() throws Exception { 107 Document doc = getDocument("src/test/html_docs/cvsweb_1_58.html"); 108 109 int i = 0; 110 RemoteFile[] files = _interface.getFiles(doc); 111 112 assertEquals("Makefile", files[i].getName()); 113 assertFalse(files[i].isInAttic()); 114 assertEquals("1.1.1.1", files[i++].getVersion()); 115 116 assertEquals("README", files[i].getName()); 117 assertFalse(files[i].isInAttic()); 118 assertEquals("1.1.1.1", files[i++].getVersion()); 119 120 assertEquals("lilo.conf", files[i].getName()); 121 assertFalse(files[i].isInAttic()); 122 assertEquals("1.1.1.1", files[i++].getVersion()); 123 124 assertEquals("Expected no more files", i, files.length); 125 } 126 127 public void testGetDirectoriesXPDevelopper() throws Exception { 128 Document doc = getDocument("src/test/html_docs/cvsweb_1_58.html"); 129 130 int i = 0; 131 String [] directories = _interface.getDirectories(doc); 132 assertEquals("Squeak-VM", directories[i++]); 133 assertEquals("SqueakNOS", directories[i++]); 134 assertEquals("cd", directories[i++]); 135 assertEquals("images", directories[i++]); 136 assertEquals("include", directories[i++]); 137 assertEquals("linux-boot", directories[i++]); 138 assertEquals("micro", directories[i++]); 139 assertEquals("test", directories[i++]); 140 141 assertEquals("Expected no more directories", i, directories.length); 142 } 143 144 145 } 146 | Popular Tags |