KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cvsgrab > web > Sourcecast3_0InterfaceTest


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 JavaDoc;
10
11 import java.util.Properties JavaDoc;
12
13 /**
14  * @author <a HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</a>
15  * @version $Revision: 1.3 $ $Date: 2005/06/25 19:51:33 $
16  * @created on 12 oct. 2003
17  */

18 public class Sourcecast3_0InterfaceTest extends AbstractTestCase {
19
20     private Sourcecast3_0Interface _interface;
21     private CVSGrab _grabber;
22
23     /**
24      * Constructor for Sourcecast3_0InterfaceTest
25      * @param testName
26      */

27     public Sourcecast3_0InterfaceTest(String JavaDoc testName) {
28         super(testName);
29     }
30
31     protected void setUp() throws Exception JavaDoc {
32         super.setUp();
33         _grabber = new CVSGrab();
34         _interface = new Sourcecast3_0Interface(_grabber);
35     }
36
37     public void testDetect() throws Exception JavaDoc {
38         Document JavaDoc doc = getDocument("src/test/html_docs/sourcecast_3_0.html");
39         _grabber.getWebOptions().setRootUrl("https://forms.dev.java.net/source/browse/");
40         _interface.detect(doc);
41
42         assertEquals("SourceCast 3.0.2.9.1", _interface.getType());
43         
44         doc = getDocument("src/test/html_docs/sourcecast_3_0_2.html");
45         _grabber.getWebOptions().setRootUrl("https://forms.dev.java.net/source/browse/");
46         _interface.detect(doc);
47
48         
49         assertEquals("SourceCast 3.0.2.9.3", _interface.getType());
50         
51     }
52
53     public void testGetFiles() throws Exception JavaDoc {
54         Document JavaDoc doc = getDocument("src/test/html_docs/sourcecast_3_0.html");
55
56         int i = 0;
57         RemoteFile[] files = _interface.getFiles(doc);
58         assertEquals(".cvsignore", files[i].getName());
59         assertFalse(files[i].isInAttic());
60         assertEquals("1.3", files[i++].getVersion());
61
62         assertEquals("LICENSE.txt", files[i].getName());
63         assertFalse(files[i].isInAttic());
64         assertEquals("1.6", files[i++].getVersion());
65
66         assertEquals("README.html", files[i].getName());
67         assertFalse(files[i].isInAttic());
68         assertEquals("1.19", files[i++].getVersion());
69
70         assertEquals("RELEASE-NOTES.txt", files[i].getName());
71         assertFalse(files[i].isInAttic());
72         assertEquals("1.35", files[i++].getVersion());
73
74         assertEquals("build.xml", files[i].getName());
75         assertFalse(files[i].isInAttic());
76         assertEquals("1.13", files[i++].getVersion());
77
78         assertEquals("default.properties", files[i].getName());
79         assertFalse(files[i].isInAttic());
80         assertEquals("1.26", files[i++].getVersion());
81
82         assertEquals("todo.txt", files[i].getName());
83         assertFalse(files[i].isInAttic());
84         assertEquals("1.19", files[i++].getVersion());
85
86         assertEquals("Expected no more files", i, files.length);
87
88     }
89
90     public void testGetDirectories() throws Exception JavaDoc {
91         Document JavaDoc doc = getDocument("src/test/html_docs/sourcecast_3_0.html");
92
93         int i = 0;
94         String JavaDoc[] directories = _interface.getDirectories(doc);
95         assertEquals("com", directories[i++]);
96         assertEquals("docs", directories[i++]);
97         assertEquals("formsdemo-0.9.9", directories[i++]);
98         assertEquals("jgoodies", directories[i++]);
99         assertEquals("src", directories[i++]);
100         assertEquals("www", directories[i++]);
101
102         assertEquals("Expected no more directories", i, directories.length);
103
104     }
105
106     public void testGetDirectoryUrl() throws Exception JavaDoc {
107         assertEquals("https://forms.dev.java.net/source/browse/forms/", _interface.getDirectoryUrl("https://forms.dev.java.net/source/browse/", "forms"));
108         _interface.setVersionTag("HEAD");
109         assertEquals("https://forms.dev.java.net/source/browse/forms/?only_with_tag=HEAD", _interface.getDirectoryUrl("https://forms.dev.java.net/source/browse/", "forms"));
110     }
111
112     public void testGetDownloadUrl() throws Exception JavaDoc {
113         RemoteRepository repository = new RemoteRepository("https://forms.dev.java.net/source/browse/", null);
114         RemoteDirectory dir = new RemoteDirectory(repository, "forms", "forms");
115         RemoteFile file = new RemoteFile("LICENSE.txt", "1.6");
116         file.setDirectory(dir);
117
118         assertEquals("https://forms.dev.java.net/source/browse/*checkout*/forms/LICENSE.txt?rev=1.6", _interface.getDownloadUrl(file));
119
120         file = new RemoteFile(".project", "1.1");
121         file.setDirectory(dir);
122         file.setInAttic(true);
123
124         assertEquals("https://forms.dev.java.net/source/browse/*checkout*/forms/Attic/.project?rev=1.1", _interface.getDownloadUrl(file));
125
126     }
127
128     public void testGuessWebProperties() {
129         Properties JavaDoc webProperties = _interface.guessWebProperties("https://forms.dev.java.net/source/browse/forms/");
130         assertEquals("https://forms.dev.java.net/source/browse/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
131         assertEquals("forms/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
132         assertNull(webProperties.get(CVSGrab.TAG_OPTION));
133         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
134         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
135         
136         webProperties = _interface.guessWebProperties("https://lg3d-core.dev.java.net/source/browse/lg3d-core/?only_with_tag=dev-0-6-1");
137         assertEquals("https://lg3d-core.dev.java.net/source/browse/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
138         assertEquals("lg3d-core/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
139         assertEquals("dev-0-6-1", webProperties.get(CVSGrab.TAG_OPTION));
140         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
141         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
142         
143         webProperties = _interface.guessWebProperties("https://swingfx.dev.java.net/source/browse/swingfx/src/net/java/swingfx/common/");
144         assertEquals("https://swingfx.dev.java.net/source/browse/", webProperties.get(CVSGrab.ROOT_URL_OPTION));
145         assertEquals("swingfx/src/net/java/swingfx/common/", webProperties.get(CVSGrab.PACKAGE_PATH_OPTION));
146         assertNull(webProperties.get(CVSGrab.TAG_OPTION));
147         assertNull(webProperties.get(CVSGrab.PROJECT_ROOT_OPTION));
148         assertNull(webProperties.get(CVSGrab.QUERY_PARAMS_OPTION));
149     }
150
151
152 }
153
Popular Tags