1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.output;
24
25 import java.util.Date;
26 import java.util.HashSet;
27
28 import junit.framework.TestCase;
29 import net.sf.statcvs.model.Directory;
30 import net.sf.statcvs.model.Revision;
31 import net.sf.statcvs.model.VersionedFile;
32
33 /**
34 * Test cases for {ViewCvsIntegration}
35 *
36 * @author Richard Cyganiak <rcyg@gmx.de>
37 * @version $Id: WebRepositoryIntegrationTest.java,v 1.21 2008/04/02 11:22:16 benoitx Exp $
38 */
39 public class WebRepositoryIntegrationTest extends TestCase {
40
41 private static final String BASE = "http://example.com/";
42
43 private WebRepositoryIntegration viewcvs;
44 private WebRepositoryIntegration cvsweb;
45 private WebRepositoryIntegration chora;
46 private final Date date = new Date(100000000);
47 private Directory root;
48 private Directory path;
49
50 /**
51 * Checkstyle drives me nuts
52 * @param arg0 stuff
53 */
54 public WebRepositoryIntegrationTest(final String arg0) {
55 super(arg0);
56 }
57
58 protected void setUp() throws Exception {
59 super.setUp();
60 viewcvs = new ViewCvsIntegration(BASE);
61 cvsweb = new CvswebIntegration(BASE);
62 chora = new ChoraIntegration(BASE);
63 root = Directory.createRoot();
64 path = root.createSubdirectory("path");
65 }
66
67 /**
68 * test
69 */
70 public void testViewcvsCreation() {
71 assertEquals("ViewCVS", viewcvs.getName());
72 }
73
74 /**
75 * Tests if stuff still works when the trailing slash is omitted from
76 * the base URL
77 */
78 public void testViewcvsForgivingBaseURL() {
79 final ViewCvsIntegration viewcvs2 = new ViewCvsIntegration("http://example.com");
80 final VersionedFile file = new VersionedFile("file", root);
81 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
82 assertEquals("http://example.com/file", viewcvs2.getFileHistoryUrl(file));
83 }
84
85 /**
86 * test URLs for a normal file
87 */
88 public void testViewcvsNormalFile() {
89 final VersionedFile file = new VersionedFile("path/file", path);
90 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
91 assertEquals(BASE + "path/file", viewcvs.getFileHistoryUrl(file));
92 assertEquals(BASE + "path/file?rev=HEAD&content-type=text/vnd.viewcvs-markup", viewcvs.getFileViewUrl(file));
93 }
94
95 /**
96 * Test for a ViewCVS URL that includes a cvsroot parameter
97 */
98 public void testViewcvsWithCvsroot() {
99 this.viewcvs = new ViewCvsIntegration("http://example.com/cgi-bin/viewcvs.cgi/module?cvsroot=CvsRoot");
100 final VersionedFile file = new VersionedFile("path/file", this.path);
101 file.addChangeRevision("1.1", null, this.date, null, 0, 0, 0, null);
102 assertEquals("http://example.com/cgi-bin/viewcvs.cgi/module/path/file?cvsroot=CvsRoot", this.viewcvs.getFileHistoryUrl(file));
103 assertEquals("http://example.com/cgi-bin/viewcvs.cgi/module/path/file?rev=HEAD&content-type=text/vnd.viewcvs-markup&cvsroot=CvsRoot", this.viewcvs
104 .getFileViewUrl(file));
105 }
106
107 /**
108 * test URLs for an attic file
109 */
110 public void testViewcvsAtticFile() {
111 final VersionedFile file = new VersionedFile("path/file", path);
112 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
113 final HashSet atticFileNames = new HashSet();
114 atticFileNames.add("path/file");
115 viewcvs.setAtticFileNames(atticFileNames);
116 assertEquals(BASE + "path/Attic/file", viewcvs.getFileHistoryUrl(file));
117 assertEquals(BASE + "path/Attic/file?rev=HEAD&content-type=text/vnd.viewcvs-markup", viewcvs.getFileViewUrl(file));
118 }
119
120 /**
121 * Test URLs for directories
122 */
123 public void testViewcvsDirectory() {
124 assertEquals("http://example.com/", viewcvs.getDirectoryUrl(root));
125 assertEquals("http://example.com/path/", viewcvs.getDirectoryUrl(path));
126 }
127
128 /**
129 * Test URLs for diff
130 */
131 public void testViewcvsDiff() {
132 final VersionedFile file = new VersionedFile("file", root);
133 final Revision rev1 = file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
134 final Revision rev2 = file.addChangeRevision("1.2", null, date, null, 0, 0, 0, null);
135 assertEquals("http://example.com/file.diff?r1=1.1&r2=1.2", viewcvs.getDiffUrl(rev1, rev2));
136 }
137
138 /**
139 * Test URLs for diff with cvsroot parameter
140 */
141 public void testViewcvsDiffWithCvsroot() {
142 this.viewcvs = new ViewCvsIntegration("http://example.com/cgi-bin/viewcvs.cgi/module?cvsroot=CvsRoot");
143 final VersionedFile file = new VersionedFile("file", this.root);
144 final Revision rev1 = file.addChangeRevision("1.1", null, this.date, null, 0, 0, 0, null);
145 final Revision rev2 = file.addChangeRevision("1.2", null, this.date, null, 0, 0, 0, null);
146 assertEquals("http://example.com/cgi-bin/viewcvs.cgi/module/file.diff?r1=1.1&r2=1.2&cvsroot=CvsRoot", this.viewcvs.getDiffUrl(rev1, rev2));
147 }
148
149 /**
150 * test
151 */
152 public void testCvswebCreation() {
153 assertEquals("cvsweb", cvsweb.getName());
154 }
155
156 /**
157 * Tests if stuff still works when the trailing slash is omitted from
158 * the base URL
159 */
160 public void testCvswebForgivingBaseURL() {
161 final CvswebIntegration cvsweb2 = new CvswebIntegration("http://example.com");
162 final VersionedFile file = new VersionedFile("file", root);
163 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
164 assertEquals("http://example.com/file", cvsweb2.getFileHistoryUrl(file));
165 }
166
167 /**
168 * test URLs for a normal file
169 */
170 public void testCvswebNormalFile() {
171 final VersionedFile file = new VersionedFile("path/file", path);
172 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
173 assertEquals(BASE + "path/file", cvsweb.getFileHistoryUrl(file));
174 assertEquals(BASE + "path/file?rev=HEAD&content-type=text/vnd.viewcvs-markup", cvsweb.getFileViewUrl(file));
175 }
176
177 /**
178 * Test for a URL that includes a cvsroot parameter
179 */
180 public void testCvswebWithCvsroot() {
181 this.cvsweb = new CvswebIntegration("http://example.com/cgi-bin/cvsweb.cgi/module?cvsroot=CvsRoot");
182 final VersionedFile file = new VersionedFile("path/file", this.path);
183 file.addChangeRevision("1.1", null, this.date, null, 0, 0, 0, null);
184 assertEquals("http://example.com/cgi-bin/cvsweb.cgi/module/path/file?cvsroot=CvsRoot", this.cvsweb.getFileHistoryUrl(file));
185 assertEquals("http://example.com/cgi-bin/cvsweb.cgi/module/path/file?rev=HEAD&content-type=text/vnd.viewcvs-markup&cvsroot=CvsRoot", this.cvsweb
186 .getFileViewUrl(file));
187 }
188
189 /**
190 * test URLs for an attic file
191 */
192 public void testCvswebAtticFile() {
193 final VersionedFile file = new VersionedFile("path/file", path);
194 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
195 final HashSet atticFileNames = new HashSet();
196 atticFileNames.add("path/file");
197 cvsweb.setAtticFileNames(atticFileNames);
198 assertEquals(BASE + "path/Attic/file", cvsweb.getFileHistoryUrl(file));
199 assertEquals(BASE + "path/Attic/file?rev=HEAD&content-type=text/vnd.viewcvs-markup", cvsweb.getFileViewUrl(file));
200 }
201
202 /**
203 * Test URLs for directories
204 */
205 public void testCvswebDirectory() {
206 assertEquals("http://example.com/", cvsweb.getDirectoryUrl(root));
207 assertEquals("http://example.com/path/", cvsweb.getDirectoryUrl(path));
208 }
209
210 /**
211 * Test URLs for diff
212 */
213 public void testCvswebDiff() {
214 final VersionedFile file = new VersionedFile("file", root);
215 final Revision rev1 = file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
216 final Revision rev2 = file.addChangeRevision("1.2", null, date, null, 0, 0, 0, null);
217 assertEquals("http://example.com/file.diff?r1=1.1&r2=1.2&f=h", cvsweb.getDiffUrl(rev1, rev2));
218 }
219
220 /**
221 * Test URLs for diff with cvsroot parameter
222 */
223 public void testCvswebDiffWithCvsroot() {
224 this.cvsweb = new CvswebIntegration("http://example.com/cgi-bin/cvsweb.cgi/module?cvsroot=CvsRoot");
225 final VersionedFile file = new VersionedFile("file", this.root);
226 final Revision rev1 = file.addChangeRevision("1.1", null, this.date, null, 0, 0, 0, null);
227 final Revision rev2 = file.addChangeRevision("1.2", null, this.date, null, 0, 0, 0, null);
228 assertEquals("http://example.com/cgi-bin/cvsweb.cgi/module/file.diff?r1=1.1&r2=1.2&f=h&cvsroot=CvsRoot", this.cvsweb.getDiffUrl(rev1, rev2));
229 }
230
231 /**
232 * test
233 */
234 public void testChoraCreation() {
235 assertEquals("Chora", chora.getName());
236 }
237
238 /**
239 * Tests if stuff still works when the trailing slash is omitted from
240 * the base URL
241 */
242 public void testChoraForgivingBaseURL() {
243 final ChoraIntegration chora2 = new ChoraIntegration("http://example.com");
244 final VersionedFile file = new VersionedFile("file", root);
245 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
246 assertEquals("http://example.com/file", chora2.getFileHistoryUrl(file));
247 }
248
249 /**
250 * test URLs for a normal file
251 */
252 public void testChoraNormalFile() {
253 final VersionedFile file = new VersionedFile("path/file", path);
254 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
255 assertEquals(BASE + "path/file", chora.getFileHistoryUrl(file));
256 assertEquals(BASE + "path/file?r=HEAD", chora.getFileViewUrl(file));
257 }
258
259 /**
260 * test URLs for an attic file
261 */
262 public void testChoraAtticFile() {
263 final VersionedFile file = new VersionedFile("path/file", path);
264 file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
265 final HashSet atticFileNames = new HashSet();
266 atticFileNames.add("path/file");
267 chora.setAtticFileNames(atticFileNames);
268 assertEquals(BASE + "path/Attic/file", chora.getFileHistoryUrl(file));
269 assertEquals(BASE + "path/Attic/file?r=HEAD", chora.getFileViewUrl(file));
270 }
271
272 /**
273 * Test URLs for directories
274 */
275 public void testChoraDirectory() {
276 assertEquals("http://example.com/", viewcvs.getDirectoryUrl(root));
277 assertEquals("http://example.com/path/", viewcvs.getDirectoryUrl(path));
278 }
279
280 /**
281 * Test URLs for diff
282 */
283 public void testChoraDiff() {
284 final VersionedFile file = new VersionedFile("file", root);
285 final Revision rev1 = file.addChangeRevision("1.1", null, date, null, 0, 0, 0, null);
286 final Revision rev2 = file.addChangeRevision("1.2", null, date, null, 0, 0, 0, null);
287 assertEquals("http://example.com/file?r1=1.1&r2=1.2", chora.getDiffUrl(rev1, rev2));
288 }
289 }