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 14 21 public class Chora_2_0InterfaceTest extends AbstractTestCase { 22 23 private Chora2_0Interface _interface; 24 private CVSGrab _grabber; 25 26 30 public Chora_2_0InterfaceTest(String testName) { 31 super(testName); 32 } 33 34 protected void setUp() throws Exception { 35 super.setUp(); 36 _grabber = new CVSGrab(); 37 _interface = new Chora2_0Interface(_grabber); 38 } 39 40 public void testDetect() throws Exception { 41 Document doc = getDocument("src/test/html_docs/chora_2_0.html"); 42 _grabber.getWebOptions().setRootUrl("http://cvs.php.net/cvs.php/"); 43 _interface.detect(doc); 44 45 assertEquals("Chora 2.x", _interface.getType()); 46 } 47 48 public void testGetFiles() throws Exception { 49 Document doc = getDocument("src/test/html_docs/chora_2_0.html"); 50 51 int i = 0; 52 RemoteFile[] files = _interface.getFiles(doc); 53 assertEquals(".cvsignore", files[i].getName()); 54 assertFalse(files[i].isInAttic()); 55 assertEquals("1.1", files[i++].getVersion()); 56 57 assertEquals("BUGS", files[i].getName()); 58 assertFalse(files[i].isInAttic()); 59 assertEquals("1.7", files[i++].getVersion()); 60 61 assertEquals("ChangeLog", files[i].getName()); 62 assertFalse(files[i].isInAttic()); 63 assertEquals("1.289", files[i++].getVersion()); 64 65 assertEquals("COPYING.lib", files[i].getName()); 66 assertFalse(files[i].isInAttic()); 67 assertEquals("1.1", files[i++].getVersion()); 68 69 assertEquals("FAQ", files[i].getName()); 70 assertFalse(files[i].isInAttic()); 71 assertEquals("1.39", files[i++].getVersion()); 72 73 assertEquals("INSTALL", files[i].getName()); 74 assertFalse(files[i].isInAttic()); 75 assertEquals("1.12", files[i++].getVersion()); 76 77 assertEquals("NEWS", files[i].getName()); 78 assertFalse(files[i].isInAttic()); 79 assertEquals("1.449", files[i++].getVersion()); 80 81 assertEquals("README", files[i].getName()); 82 assertFalse(files[i].isInAttic()); 83 assertEquals("1.56", files[i++].getVersion()); 84 85 assertEquals("RELEASE_NOTES", files[i].getName()); 86 assertFalse(files[i].isInAttic()); 87 assertEquals("1.47", files[i++].getVersion()); 88 89 assertEquals("TODO", files[i].getName()); 90 assertFalse(files[i].isInAttic()); 91 assertEquals("1.28", 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/chora_2_0.html"); 99 100 int i = 0; 101 String [] directories = _interface.getDirectories(doc); 102 assertEquals("configs", directories[i++]); 103 assertEquals("demo", directories[i++]); 104 assertEquals("docs", directories[i++]); 105 assertEquals("libs", directories[i++]); 106 assertEquals("misc", directories[i++]); 107 assertEquals("plugins", directories[i++]); 108 assertEquals("templates", directories[i++]); 109 assertEquals("unit_test", directories[i++]); 110 111 assertEquals("Expected no more directories", i, directories.length); 112 113 } 114 115 public void testGetDirectoryUrl() throws Exception { 116 assertEquals("http://cvs.php.net/cvs.php/smarty/", _interface.getDirectoryUrl("http://cvs.php.net/cvs.php/", "smarty")); 117 } 118 119 public void testGetDownloadUrl() throws Exception { 120 RemoteRepository repository = new RemoteRepository("http://cvs.php.net/cvs.php/", null); 122 RemoteDirectory dir = new RemoteDirectory(repository, "smarty", "smarty"); 123 RemoteFile file = new RemoteFile("BUGS", "1.7"); 124 file.setDirectory(dir); 125 126 assertEquals("http://cvs.php.net/co.php/smarty/BUGS?r=1.7&p=1", _interface.getDownloadUrl(file)); 127 128 repository = new RemoteRepository("http://cvs.php.net/", null); 130 dir = new RemoteDirectory(repository, "smarty/docs/scripts", "smarty/docs/scripts"); 131 file = new RemoteFile(".cvsignore", "1.1"); 132 file.setDirectory(dir); 133 _interface.setBrowsePath(""); 134 135 assertEquals("http://cvs.php.net/co.php/smarty/docs/scripts/.cvsignore?r=1.1&p=1", _interface.getDownloadUrl(file)); 136 } 137 138 public void testGuessWebProperties() { 139 Properties webProperties = _interface.guessWebProperties("http://cvs.php.net/smarty/docs/scripts/"); 141 assertEquals("http://cvs.php.net/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 142 assertEquals("smarty/docs/scripts/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 143 assertNull(webProperties.get(CVSGrab.TAG_OPTION)); 144 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 145 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 146 147 } 148 149 } 150 | Popular Tags |