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