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 Sourcecast2_0InterfaceTest extends AbstractTestCase { 19 20 private Sourcecast2_0Interface _interface; 21 private CVSGrab _grabber; 22 23 27 public Sourcecast2_0InterfaceTest(String testName) { 28 super(testName); 29 } 30 31 protected void setUp() throws Exception { 32 super.setUp(); 33 _grabber = new CVSGrab(); 34 _interface = new Sourcecast2_0Interface(_grabber); 35 } 36 37 public void testDetect() throws Exception { 38 Document doc = getDocument("src/test/html_docs/sourcecast_2_0.html"); 39 _grabber.getWebOptions().setRootUrl("https://forms.dev.java.net/source/browse/"); 40 _interface.detect(doc); 41 42 assertEquals("SourceCast 2.0.3.000", _interface.getType()); 43 } 44 45 public void testGetFiles() throws Exception { 46 Document doc = getDocument("src/test/html_docs/sourcecast_2_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("LICENSE.txt", files[i].getName()); 55 assertFalse(files[i].isInAttic()); 56 assertEquals("1.3", files[i++].getVersion()); 57 58 assertEquals("README.html", files[i].getName()); 59 assertFalse(files[i].isInAttic()); 60 assertEquals("1.5", files[i++].getVersion()); 61 62 assertEquals("RELEASE-NOTES.txt", files[i].getName()); 63 assertFalse(files[i].isInAttic()); 64 assertEquals("1.9", files[i++].getVersion()); 65 66 assertEquals("build.xml", files[i].getName()); 67 assertFalse(files[i].isInAttic()); 68 assertEquals("1.7", files[i++].getVersion()); 69 70 assertEquals("default.properties", files[i].getName()); 71 assertFalse(files[i].isInAttic()); 72 assertEquals("1.9", files[i++].getVersion()); 73 74 assertEquals("todo.txt", files[i].getName()); 75 assertFalse(files[i].isInAttic()); 76 assertEquals("1.2", 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/sourcecast_2_0.html"); 84 85 int i = 0; 86 String [] directories = _interface.getDirectories(doc); 87 assertEquals("com", directories[i++]); 88 assertEquals("docs", directories[i++]); 89 assertEquals("formsdemo-0.9.9", directories[i++]); 90 assertEquals("jgoodies", directories[i++]); 91 assertEquals("src", directories[i++]); 92 assertEquals("www", directories[i++]); 93 94 assertEquals("Expected no more directories", i, directories.length); 95 96 } 97 98 public void testGetDirectoryUrl() throws Exception { 99 assertEquals("https://forms.dev.java.net/source/browse/forms/", _interface.getDirectoryUrl("https://forms.dev.java.net/source/browse/", "forms")); 100 _interface.setVersionTag("HEAD"); 101 assertEquals("https://forms.dev.java.net/source/browse/forms/?only_with_tag=HEAD", _interface.getDirectoryUrl("https://forms.dev.java.net/source/browse/", "forms")); 102 } 103 104 public void testGetDownloadUrl() throws Exception { 105 RemoteRepository repository = new RemoteRepository("https://forms.dev.java.net/source/browse/", null); 106 RemoteDirectory dir = new RemoteDirectory(repository, "forms", "forms"); 107 RemoteFile file = new RemoteFile("LICENSE.txt", "1.3"); 108 file.setDirectory(dir); 109 110 assertEquals("https://forms.dev.java.net/source/browse/*checkout*/forms/LICENSE.txt?rev=1.3", _interface.getDownloadUrl(file)); 111 112 file = new RemoteFile("ant.jar", "1.1.2.1"); 113 file.setDirectory(dir); 114 file.setInAttic(true); 115 116 assertEquals("https://forms.dev.java.net/source/browse/*checkout*/forms/Attic/ant.jar?rev=1.1.2.1", _interface.getDownloadUrl(file)); 117 118 } 119 120 public void testGuessWebProperties() { 121 Properties webProperties = _interface.guessWebProperties("https://forms.dev.java.net/source/browse/forms/"); 122 assertEquals("https://forms.dev.java.net/source/browse/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 123 assertEquals("forms/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 124 assertNull(webProperties.get(CVSGrab.TAG_OPTION)); 125 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 126 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 127 webProperties = _interface.guessWebProperties("https://lg3d-core.dev.java.net/source/browse/lg3d-core/?only_with_tag=dev-0-6-1"); 128 assertEquals("https://lg3d-core.dev.java.net/source/browse/", webProperties.get(CVSGrab.ROOT_URL_OPTION)); 129 assertEquals("lg3d-core/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION)); 130 assertEquals("dev-0-6-1", webProperties.get(CVSGrab.TAG_OPTION)); 131 assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION)); 132 assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION)); 133 } 134 135 136 } 137 | Popular Tags |