1 package org.apache.maven.doxia.site.decoration.inheritance;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.codehaus.plexus.util.Os;
25 import org.codehaus.plexus.util.StringUtils;
26
27 import junit.framework.TestCase;
28
29
30
31
32
33
34
35 public class PathDescriptorTest
36 extends TestCase
37 {
38
39 public void testAbsPath()
40 throws Exception
41 {
42 String path = "absolutePath";
43
44 PathDescriptor desc = new PathDescriptor( "/" + path );
45
46 assertTrue( desc.isFile() );
47 assertTrue( desc.isRelative() );
48 assertNull( desc.getBaseUrl() );
49 assertNull( desc.getPathUrl() );
50 assertNotNull( desc.getPath() );
51 assertNotNull( desc.getLocation() );
52 assertEquals( "wrong path", path, desc.getPath() );
53 assertEquals( "wrong location", path, desc.getLocation() );
54 }
55
56
57 public void testRelPath()
58 throws Exception
59 {
60 String path = "relativePath";
61
62 PathDescriptor desc = new PathDescriptor( path );
63
64 assertTrue( desc.isFile() );
65 assertTrue( desc.isRelative() );
66 assertNull( desc.getBaseUrl() );
67 assertNull( desc.getPathUrl() );
68 assertNotNull( desc.getPath() );
69 assertNotNull( desc.getLocation() );
70 assertEquals( "wrong path", path, desc.getPath() );
71 assertEquals( "wrong location", path, desc.getLocation() );
72 }
73
74
75 public void testEmptyAbsPath()
76 throws Exception
77 {
78 String path = "";
79
80 PathDescriptor desc = new PathDescriptor( "/" + path );
81
82 assertTrue( desc.isFile() );
83 assertTrue( desc.isRelative() );
84 assertNull( desc.getBaseUrl() );
85 assertNull( desc.getPathUrl() );
86 assertNotNull( desc.getPath() );
87 assertNotNull( desc.getLocation() );
88 assertEquals( "wrong path", path, desc.getPath() );
89 assertEquals( "wrong location", path, desc.getLocation() );
90 }
91
92
93 public void testEmptyRelPath()
94 throws Exception
95 {
96 String path = "";
97
98 PathDescriptor desc = new PathDescriptor( path );
99
100 assertTrue( desc.isFile() );
101 assertTrue( desc.isRelative() );
102 assertNull( desc.getBaseUrl() );
103 assertNull( desc.getPathUrl() );
104 assertNotNull( desc.getPath() );
105 assertNotNull( desc.getLocation() );
106 assertEquals( "wrong path", path, desc.getPath() );
107 assertEquals( "wrong location", path, desc.getLocation() );
108 }
109
110
111 public void testNullPath()
112 throws Exception
113 {
114 String path = null;
115
116 PathDescriptor desc = new PathDescriptor( path );
117
118 assertTrue( desc.isFile() );
119 assertTrue( desc.isRelative() );
120 assertNull( desc.getBaseUrl() );
121 assertNull( desc.getPathUrl() );
122 assertNull( desc.getPath() );
123 assertNull( desc.getLocation() );
124 assertEquals( "wrong path", path, desc.getPath() );
125 assertEquals( "wrong location", path, desc.getLocation() );
126 }
127
128
129 public void testNullBaseAbsPath()
130 throws Exception
131 {
132 String base = null;
133 String path = "absolutePath";
134
135 PathDescriptor desc = new PathDescriptor( base, "/" + path );
136
137 assertTrue( desc.isFile() );
138 assertTrue( desc.isRelative() );
139 assertNull( desc.getBaseUrl() );
140 assertNull( desc.getPathUrl() );
141 assertNotNull( desc.getPath() );
142 assertNotNull( desc.getLocation() );
143 assertEquals( "wrong path", path, desc.getPath() );
144 assertEquals( "wrong location", path, desc.getLocation() );
145 }
146
147
148 public void testNullBaseRelPath()
149 throws Exception
150 {
151 String base = null;
152 String path = "relativePath";
153
154 PathDescriptor desc = new PathDescriptor( base, path );
155
156 assertTrue( desc.isFile() );
157 assertTrue( desc.isRelative() );
158 assertNull( desc.getBaseUrl() );
159 assertNull( desc.getPathUrl() );
160 assertNotNull( desc.getPath() );
161 assertNotNull( desc.getLocation() );
162 assertEquals( "wrong path", path, desc.getPath() );
163 assertEquals( "wrong location", path, desc.getLocation() );
164 }
165
166
167 public void testNullBaseEmptyAbsPath()
168 throws Exception
169 {
170 String base = null;
171 String path = "";
172
173 PathDescriptor desc = new PathDescriptor( base, "/" + path );
174
175 assertTrue( desc.isFile() );
176 assertTrue( desc.isRelative() );
177 assertNull( desc.getBaseUrl() );
178 assertNull( desc.getPathUrl() );
179 assertNotNull( desc.getPath() );
180 assertNotNull( desc.getLocation() );
181 assertEquals( "wrong path", path, desc.getPath() );
182 assertEquals( "wrong location", path, desc.getLocation() );
183 }
184
185
186 public void testNullBaseEmptyRelPath()
187 throws Exception
188 {
189 String base = null;
190 String path = "";
191
192 PathDescriptor desc = new PathDescriptor( base, path );
193
194 assertTrue( desc.isFile() );
195 assertTrue( desc.isRelative() );
196 assertNull( desc.getBaseUrl() );
197 assertNull( desc.getPathUrl() );
198 assertNotNull( desc.getPath() );
199 assertNotNull( desc.getLocation() );
200 assertEquals( "wrong path", path, desc.getPath() );
201 assertEquals( "wrong location", path, desc.getLocation() );
202 }
203
204
205 public void testNullBaseNullPath()
206 throws Exception
207 {
208 String base = null;
209 String path = null;
210
211 PathDescriptor desc = new PathDescriptor( base, path );
212
213 assertTrue( desc.isFile() );
214 assertTrue( desc.isRelative() );
215 assertNull( desc.getBaseUrl() );
216 assertNull( desc.getPathUrl() );
217 assertNull( desc.getPath() );
218 assertNull( desc.getLocation() );
219 assertEquals( "wrong path", path, desc.getPath() );
220 assertEquals( "wrong location", path, desc.getLocation() );
221 }
222
223
224 public void testUrlBaseAbsPath()
225 throws Exception
226 {
227 String base = "http://maven.apache.org/";
228 String path = "absolutePath";
229
230 PathDescriptor desc = new PathDescriptor( base, "/" + path );
231
232 assertFalse( desc.isFile() );
233 assertFalse( desc.isRelative() );
234 assertNotNull( desc.getBaseUrl() );
235 assertNotNull( desc.getPathUrl() );
236 assertNotNull( desc.getPath() );
237 assertNotNull( desc.getLocation() );
238 assertEquals( "wrong path", "/" + path, desc.getPath() );
239 assertEquals( "wrong location", base + path, desc.getLocation() );
240 }
241
242
243 public void testUrlBaseRelPath()
244 throws Exception
245 {
246 String base = "http://maven.apache.org/";
247 String path = "relativePath";
248
249 PathDescriptor desc = new PathDescriptor( base, path );
250
251 assertFalse( desc.isFile() );
252 assertFalse( desc.isRelative() );
253 assertNotNull( desc.getBaseUrl() );
254 assertNotNull( desc.getPathUrl() );
255 assertNotNull( desc.getPath() );
256 assertNotNull( desc.getLocation() );
257 assertEquals( "wrong path", "/" + path, desc.getPath() );
258 assertEquals( "wrong location", base + path, desc.getLocation() );
259 }
260
261
262 public void testUrlBaseEmptyAbsPath()
263 throws Exception
264 {
265 String base = "http://maven.apache.org/";
266 String path = "";
267
268 PathDescriptor desc = new PathDescriptor( base, "/" + path );
269
270 assertFalse( desc.isFile() );
271 assertFalse( desc.isRelative() );
272 assertNotNull( desc.getBaseUrl() );
273 assertNotNull( desc.getPathUrl() );
274 assertNotNull( desc.getPath() );
275 assertNotNull( desc.getLocation() );
276 assertEquals( "wrong path", "/" + path, desc.getPath() );
277 assertEquals( "wrong location", base + path, desc.getLocation() );
278 }
279
280
281 public void testUrlBaseEmptyRelPath()
282 throws Exception
283 {
284 String base = "http://maven.apache.org/";
285 String path = "";
286
287 PathDescriptor desc = new PathDescriptor( base, path );
288
289 assertFalse( desc.isFile() );
290 assertFalse( desc.isRelative() );
291 assertNotNull( desc.getBaseUrl() );
292 assertNotNull( desc.getPathUrl() );
293 assertNotNull( desc.getPath() );
294 assertNotNull( desc.getLocation() );
295 assertEquals( "wrong path", "/" + path, desc.getPath() );
296 assertEquals( "wrong location", base + path, desc.getLocation() );
297 }
298
299
300 public void testUrlBaseNullPath()
301 throws Exception
302 {
303 String base = "http://maven.apache.org/";
304 String path = null;
305
306 PathDescriptor desc = new PathDescriptor( base, path );
307
308 assertFalse( desc.isFile() );
309 assertFalse( desc.isRelative() );
310 assertNotNull( desc.getBaseUrl() );
311 assertNotNull( desc.getPathUrl() );
312 assertNotNull( desc.getPath() );
313 assertNotNull( desc.getLocation() );
314 assertEquals( "wrong path", "/", desc.getPath() );
315 assertEquals( "wrong location", base, desc.getLocation() );
316 }
317
318
319 public void testFileBaseAbsPath()
320 throws Exception
321 {
322 String base = "/tmp/foo";
323 String path = "absolutePath";
324
325 PathDescriptor desc = new PathDescriptor( "file://" + base, "/" + path );
326
327 assertTrue( desc.isFile() );
328 assertFalse( desc.isRelative() );
329 assertNotNull( desc.getBaseUrl() );
330 assertNotNull( desc.getPathUrl() );
331 assertNotNull( desc.getPath() );
332 assertNotNull( desc.getLocation() );
333 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
334 {
335 String s = StringUtils.replace( new File( base + "/" + path ).toURI().toURL().toString(), "file:", "" );
336 assertEquals( "wrong path", s, desc.getPath() );
337 assertEquals( "wrong location", s, desc.getLocation() );
338 }
339 else
340 {
341 assertEquals( "wrong path", base + "/" + path, desc.getPath() );
342 assertEquals( "wrong location", base + "/" + path, desc.getLocation() );
343 }
344 }
345
346
347 public void testFileBaseRelPath()
348 throws Exception
349 {
350 String base = "/tmp/foo";
351 String path = "relativePath";
352
353 PathDescriptor desc = new PathDescriptor( "file://" + base, path );
354
355 assertTrue( desc.isFile() );
356 assertFalse( desc.isRelative() );
357 assertNotNull( desc.getBaseUrl() );
358 assertNotNull( desc.getPathUrl() );
359 assertNotNull( desc.getPath() );
360 assertNotNull( desc.getLocation() );
361 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
362 {
363 String s = StringUtils.replace( new File( base + "/" + path ).toURI().toURL().toString(), "file:", "" );
364 assertEquals( "wrong path", s, desc.getPath() );
365 assertEquals( "wrong location", s, desc.getLocation() );
366 }
367 else
368 {
369 assertEquals( "wrong path", base + "/" + path, desc.getPath() );
370 assertEquals( "wrong location", base + "/" + path, desc.getLocation() );
371 }
372 }
373
374
375 public void testFileBaseEmptyAbsPath()
376 throws Exception
377 {
378 String base = "/tmp/foo";
379 String path = "";
380
381 PathDescriptor desc = new PathDescriptor( "file://" + base, "/" + path );
382
383 assertTrue( desc.isFile() );
384 assertFalse( desc.isRelative() );
385 assertNotNull( desc.getBaseUrl() );
386 assertNotNull( desc.getPathUrl() );
387 assertNotNull( desc.getPath() );
388 assertNotNull( desc.getLocation() );
389 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
390 {
391 String s = StringUtils.replace( new File( base ).toURI().toURL().toString(), "file:", "" );
392 assertEquals( "wrong path", s, desc.getPath() );
393 assertEquals( "wrong location", s, desc.getLocation() );
394 }
395 else
396 {
397 assertEquals( "wrong path", base, desc.getPath() );
398 assertEquals( "wrong location", base, desc.getLocation() );
399 }
400 }
401
402
403 public void testFileBaseEmptyRelPath()
404 throws Exception
405 {
406 String base = "/tmp/foo";
407 String path = "";
408
409 PathDescriptor desc = new PathDescriptor( "file://" + base, path );
410
411 assertTrue( desc.isFile() );
412 assertFalse( desc.isRelative() );
413 assertNotNull( desc.getBaseUrl() );
414 assertNotNull( desc.getPathUrl() );
415 assertNotNull( desc.getPath() );
416 assertNotNull( desc.getLocation() );
417 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
418 {
419 String s = StringUtils.replace( new File( base ).toURI().toURL().toString(), "file:", "" );
420 assertEquals( "wrong path", s, desc.getPath() );
421 assertEquals( "wrong location", s, desc.getLocation() );
422 }
423 else
424 {
425 assertEquals( "wrong path", base, desc.getPath() );
426 assertEquals( "wrong location", base, desc.getLocation() );
427 }
428 }
429
430
431 public void testFileBaseNullPath()
432 throws Exception
433 {
434 String base = "/tmp/foo";
435 String path = null;
436
437 PathDescriptor desc = new PathDescriptor( "file://" + base, path );
438
439 assertTrue( desc.isFile() );
440 assertFalse( desc.isRelative() );
441 assertNotNull( desc.getBaseUrl() );
442 assertNotNull( desc.getPathUrl() );
443 assertNotNull( desc.getPath() );
444 assertNotNull( desc.getLocation() );
445 assertEquals( "wrong path", base, desc.getPath() );
446 assertEquals( "wrong location", base, desc.getLocation() );
447 }
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 public void testPathBaseAbsPath()
472 throws Exception
473 {
474 String base = "/tmp/foo";
475 String path = "absolutePath";
476
477 PathDescriptor desc = new PathDescriptor( base, "/" + path );
478
479 assertTrue( desc.isFile() );
480 assertFalse( desc.isRelative() );
481 assertNotNull( desc.getBaseUrl() );
482 assertNotNull( desc.getPathUrl() );
483 assertNotNull( desc.getPath() );
484 assertNotNull( desc.getLocation() );
485 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
486 {
487 String s = StringUtils.replace( new File( base + "/" + path ).toURI().toURL().toString(), "file:", "" );
488 assertEquals( "wrong path", s, desc.getPath() );
489 assertEquals( "wrong location", s, desc.getLocation() );
490 }
491 else
492 {
493 assertEquals( "wrong path", base + "/" + path, desc.getPath() );
494 assertEquals( "wrong location", base + "/" + path, desc.getLocation() );
495 }
496 }
497
498
499 public void testPathBaseRelPath()
500 throws Exception
501 {
502 String base = "/tmp/foo";
503 String path = "relativePath";
504
505 PathDescriptor desc = new PathDescriptor( base, path );
506
507 assertTrue( desc.isFile() );
508 assertFalse( desc.isRelative() );
509 assertNotNull( desc.getBaseUrl() );
510 assertNotNull( desc.getPathUrl() );
511 assertNotNull( desc.getPath() );
512 assertNotNull( desc.getLocation() );
513 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
514 {
515 String s = StringUtils.replace( new File( base + "/" + path ).toURI().toURL().toString(), "file:", "" );
516 assertEquals( "wrong path", s, desc.getPath() );
517 assertEquals( "wrong location", s, desc.getLocation() );
518 }
519 else
520 {
521 assertEquals( "wrong path", base + "/" + path, desc.getPath() );
522 assertEquals( "wrong location", base + "/" + path, desc.getLocation() );
523 }
524 }
525
526
527 public void testPathBaseEmptyAbsPath()
528 throws Exception
529 {
530 String base = "/tmp/foo";
531 String path = "";
532
533 PathDescriptor desc = new PathDescriptor( base, "/" + path );
534
535 assertTrue( desc.isFile() );
536 assertFalse( desc.isRelative() );
537 assertNotNull( desc.getBaseUrl() );
538 assertNotNull( desc.getPathUrl() );
539 assertNotNull( desc.getPath() );
540 assertNotNull( desc.getLocation() );
541 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
542 {
543 String s = StringUtils.replace( new File( base ).toURI().toURL().toString(), "file:", "" );
544 assertEquals( "wrong path", s, desc.getPath() );
545 assertEquals( "wrong location", s, desc.getLocation() );
546 }
547 else
548 {
549 assertEquals( "wrong path", base, desc.getPath() );
550 assertEquals( "wrong location", base, desc.getLocation() );
551 }
552 }
553
554
555 public void testPathBaseEmptyRelPath()
556 throws Exception
557 {
558 String base = "/tmp/foo";
559 String path = "";
560
561 PathDescriptor desc = new PathDescriptor( base, path );
562
563 assertTrue( desc.isFile() );
564 assertFalse( desc.isRelative() );
565 assertNotNull( desc.getBaseUrl() );
566 assertNotNull( desc.getPathUrl() );
567 assertNotNull( desc.getPath() );
568 assertNotNull( desc.getLocation() );
569 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
570 {
571 String s = StringUtils.replace( new File( base ).toURI().toURL().toString(), "file:", "" );
572 assertEquals( "wrong path", s, desc.getPath() );
573 assertEquals( "wrong location", s, desc.getLocation() );
574 }
575 else
576 {
577 assertEquals( "wrong path", base, desc.getPath() );
578 assertEquals( "wrong location", base, desc.getLocation() );
579 }
580 }
581
582
583 public void testPathBaseNullPath()
584 throws Exception
585 {
586 String base = "/tmp/foo";
587 String path = null;
588
589 PathDescriptor desc = new PathDescriptor( base, path );
590
591 assertTrue( desc.isFile() );
592 assertFalse( desc.isRelative() );
593 assertNotNull( desc.getBaseUrl() );
594 assertNotNull( desc.getPathUrl() );
595 assertNotNull( desc.getPath() );
596 assertNotNull( desc.getLocation() );
597 if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
598 {
599 String s = StringUtils.replace( new File( base ).toURI().toURL().toString(), "file:", "" );
600 assertEquals( "wrong path", s, desc.getPath() );
601 assertEquals( "wrong location", s, desc.getLocation() );
602 }
603 else
604 {
605 assertEquals( "wrong path", base, desc.getPath() );
606 assertEquals( "wrong location", base, desc.getLocation() );
607 }
608 }
609
610
611 public void testPathRelBase()
612 throws Exception
613 {
614 String base = "../msite-404";
615 String path = "index.html";
616
617 PathDescriptor desc = new PathDescriptor( base, path );
618
619 assertTrue( desc.isFile() );
620 assertFalse( desc.isRelative() );
621 assertNotNull( desc.getBaseUrl() );
622 assertNotNull( desc.getPathUrl() );
623 assertNotNull( desc.getPath() );
624 assertNotNull( desc.getLocation() );
625 assertEquals( desc.getPath(), desc.getLocation() );
626
627
628 }
629 }