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.IOException;
23 import java.io.Reader;
24
25 import java.util.List;
26
27 import junit.framework.TestCase;
28
29 import org.apache.maven.doxia.site.decoration.Banner;
30 import org.apache.maven.doxia.site.decoration.Body;
31 import org.apache.maven.doxia.site.decoration.DecorationModel;
32 import org.apache.maven.doxia.site.decoration.LinkItem;
33 import org.apache.maven.doxia.site.decoration.Logo;
34 import org.apache.maven.doxia.site.decoration.Menu;
35 import org.apache.maven.doxia.site.decoration.io.xpp3.DecorationXpp3Reader;
36 import org.codehaus.plexus.util.IOUtil;
37 import org.codehaus.plexus.util.ReaderFactory;
38 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
39
40
41
42
43
44
45
46 public class DecorationModelInheritenceAssemblerTest
47 extends TestCase
48 {
49 private DecorationModelInheritanceAssembler assembler = new DefaultDecorationModelInheritanceAssembler();
50
51 private static final String NAME = "Name";
52
53
54
55
56
57
58 public void testInheritence()
59 throws IOException, XmlPullParserException
60 {
61 DecorationModel childModel = readModel( "child.xml" );
62 DecorationModel parentModel = readModel( "parent.xml" );
63
64 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
65 "http://maven.apache.org" );
66 DecorationModel mergedModel = readModel( "merged.xml" );
67
68 assertEquals( "Check result", mergedModel, childModel );
69
70
71 childModel = readModel( "child.xml" );
72 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia",
73 "scp://people.apache.org" );
74 assertEquals( "Check scp result", mergedModel, childModel );
75
76 assertEquals( "Modified parent!", readModel( "parent.xml" ), parentModel );
77 }
78
79
80
81
82
83
84 public void testSuppressedInheritence()
85 throws IOException, XmlPullParserException
86 {
87 DecorationModel unassembledChildModel = readModel( "child-no-inheritance.xml" );
88 DecorationModel childModel = readModel( "child-no-inheritance.xml" );
89 DecorationModel parentModel = readModel( "parent.xml" );
90 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
91 "http://maven.apache.org" );
92 assertEquals( "Check result", unassembledChildModel, childModel );
93
94
95 DecorationModel childOfchildModel = new DecorationModel();
96 assembler.assembleModelInheritance( "Child of Child", childOfchildModel, childModel,
97 "http://maven.apache.org/doxia/child", "http://maven.apache.org/doxia" );
98 assembler.assembleModelInheritance( NAME, childOfchildModel, parentModel, "http://maven.apache.org/doxia",
99 "http://maven.apache.org" );
100
101 assertEquals( "child of child no inheritance: breadcrumbs count", 0,
102 childOfchildModel.getBody().getBreadcrumbs().size() );
103 }
104
105
106
107
108
109
110 public void testPathsResolvedWhenEmpty()
111 throws IOException, XmlPullParserException
112 {
113
114 DecorationModel childModel = readModel( "empty.xml" );
115 DecorationModel parentModel = readModel( "empty.xml" );
116
117 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
118 "http://maven.apache.org" );
119 DecorationModel mergedModel = readModel( "empty.xml" );
120
121 assertEquals( "Check result", mergedModel, childModel );
122
123
124 childModel = readModel( "empty.xml" );
125 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia",
126 "scp://people.apache.org" );
127 assertEquals( "Check scp result", mergedModel, childModel );
128
129 assertEquals( "Modified parent!", readModel( "empty.xml" ), parentModel );
130 }
131
132
133
134
135
136
137 public void testPathsNotResolvedForExternalUrls()
138 throws IOException, XmlPullParserException
139 {
140 DecorationModel parentModel = readModel( "external-urls.xml" );
141 DecorationModel childModel = readModel( "empty.xml" );
142
143 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
144 "http://maven.apache.org" );
145 assertPathsNotResolvedForExternalUrls( childModel );
146
147
148 childModel = readModel( "empty.xml" );
149 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia",
150 "scp://people.apache.org" );
151 assertPathsNotResolvedForExternalUrls( childModel );
152
153 assertEquals( "Modified parent!", readModel( "external-urls.xml" ), parentModel );
154 }
155
156 private static void assertPathsNotResolvedForExternalUrls( final DecorationModel childModel )
157 {
158 assertEquals( "check left banner href", "http://jakarta.apache.org/", childModel.getBannerLeft().getHref() );
159 assertEquals( "check left banner image", "http://jakarta.apache.org/images/jakarta-logo.gif",
160 childModel.getBannerLeft().getSrc() );
161
162 assertEquals( "check right banner href", "http://jakarta.apache.org/commons/sandbox",
163 childModel.getBannerRight().getHref() );
164 assertEquals( "check right banner image", "http://jakarta.apache.org/commons/images/logo.png",
165 childModel.getBannerRight().getSrc() );
166
167 Logo poweredBy = childModel.getPoweredBy().get( 0 );
168 assertEquals( "check powered by logo href", "http://tomcat.apache.org/", poweredBy.getHref() );
169 assertEquals( "check powered by logo image", "http://tomcat.apache.org/logo.gif", poweredBy.getImg() );
170
171 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
172 assertEquals( "check breadcrumb href", "http://www.apache.org/", breadcrumb.getHref() );
173
174 LinkItem link = childModel.getBody().getLinks().get( 0 );
175 assertEquals( "check link href", "http://www.bouncycastle.org", link.getHref() );
176
177 Menu menu = childModel.getBody().getMenus().get( 0 );
178 LinkItem menuItem = menu.getItems().get( 0 );
179 assertEquals( "check menu item href", "http://www.apache.org/special/", menuItem.getHref() );
180 }
181
182
183
184
185
186
187 public void testPathsResolvedForRelativeUrls()
188 throws IOException, XmlPullParserException
189 {
190 DecorationModel parentModel = readModel( "relative-urls.xml" );
191 DecorationModel childModel = readModel( "empty.xml" );
192
193 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/",
194 "http://maven.apache.org" );
195 assertPathsResolvedForRelativeUrls( childModel );
196
197
198 childModel = readModel( "empty.xml" );
199 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia",
200 "scp://people.apache.org" );
201 assertPathsResolvedForRelativeUrls( childModel );
202
203 assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel );
204 }
205
206 private static void assertPathsResolvedForRelativeUrls( final DecorationModel childModel )
207 {
208 assertEquals( "check left banner href", "../banner/left", childModel.getBannerLeft().getHref() );
209 assertEquals( "check left banner image", "../images/jakarta-logo.gif", childModel.getBannerLeft().getSrc() );
210
211 assertEquals( "check right banner href", "../banner/right/", childModel.getBannerRight().getHref() );
212 assertEquals( "check right banner image", "../commons/images/logo.png", childModel.getBannerRight().getSrc() );
213
214 Logo poweredBy = childModel.getPoweredBy().get( 0 );
215 assertEquals( "check powered by logo href", "../tomcat", poweredBy.getHref() );
216 assertEquals( "check powered by logo image", "../tomcat/logo.gif", poweredBy.getImg() );
217
218 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
219 assertEquals( "check breadcrumb href", "../apache", breadcrumb.getHref() );
220
221 LinkItem link = childModel.getBody().getLinks().get( 0 );
222 assertEquals( "check link href", "../bouncycastle/", link.getHref() );
223
224 Menu menu = childModel.getBody().getMenus().get( 0 );
225 LinkItem menuItem = menu.getItems().get( 0 );
226 assertEquals( "check menu item href", "../special/", menuItem.getHref() );
227 }
228
229
230
231
232
233
234 public void testPathsResolvedForSubsiteUrls()
235 throws IOException, XmlPullParserException
236 {
237 DecorationModel parentModel = readModel( "subsite-urls.xml" );
238 DecorationModel childModel = readModel( "empty.xml" );
239
240 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/",
241 "http://maven.apache.org" );
242 assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" );
243
244 assertPathsResolvedForSubsiteUrls( childModel );
245
246
247 childModel = readModel( "empty.xml" );
248 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia",
249 "scp://people.apache.org" );
250 assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" );
251 assertPathsResolvedForSubsiteUrls( childModel );
252
253 assertEquals( "Modified parent!", readModel( "subsite-urls.xml" ), parentModel );
254 }
255
256 private static void assertPathsResolvedForSubsiteUrls( final DecorationModel childModel )
257 {
258 assertEquals( "check left banner href", "../banner/left", childModel.getBannerLeft().getHref() );
259 assertEquals( "check left banner image", "../images/jakarta-logo.gif", childModel.getBannerLeft().getSrc() );
260
261 assertEquals( "check right banner href", "../banner/right/", childModel.getBannerRight().getHref() );
262 assertEquals( "check right banner image", "../commons/images/logo.png", childModel.getBannerRight().getSrc() );
263
264 Logo poweredBy = childModel.getPoweredBy().get( 0 );
265 assertEquals( "check powered by logo href", "../tomcat", poweredBy.getHref() );
266 assertEquals( "check powered by logo image", "../tomcat/logo.gif", poweredBy.getImg() );
267
268 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
269 assertEquals( "check breadcrumb href", "../apache", breadcrumb.getHref() );
270
271 LinkItem link = childModel.getBody().getLinks().get( 0 );
272 assertEquals( "check link href", "../bouncycastle/", link.getHref() );
273
274 Menu menu = childModel.getBody().getMenus().get( 0 );
275 LinkItem menuItem = menu.getItems().get( 0 );
276 assertEquals( "check menu item href", "../special/", menuItem.getHref() );
277 }
278
279
280
281
282
283
284 public void testPathsResolvedForRelativeUrlsDepthOfTwo()
285 throws IOException, XmlPullParserException
286 {
287 DecorationModel parentModel = readModel( "relative-urls.xml" );
288 DecorationModel childModel = readModel( "empty.xml" );
289
290 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia/core",
291 "http://maven.apache.org" );
292 assertPathsResolvedForRelativeUrlsDepthOfTwo( childModel );
293
294
295 childModel = readModel( "empty.xml" );
296 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/doxia/core",
297 "scp://people.apache.org" );
298 assertPathsResolvedForRelativeUrlsDepthOfTwo( childModel );
299
300 assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel );
301 }
302
303 private static void assertPathsResolvedForRelativeUrlsDepthOfTwo( final DecorationModel childModel )
304 {
305 assertEquals( "check left banner href", "../../banner/left", childModel.getBannerLeft().getHref() );
306 assertEquals( "check left banner image", "../../images/jakarta-logo.gif", childModel.getBannerLeft().getSrc() );
307
308 assertEquals( "check right banner href", "../../banner/right/", childModel.getBannerRight().getHref() );
309 assertEquals( "check right banner image", "../../commons/images/logo.png",
310 childModel.getBannerRight().getSrc() );
311
312 Logo poweredBy = childModel.getPoweredBy().get( 0 );
313 assertEquals( "check powered by logo href", "../../tomcat", poweredBy.getHref() );
314 assertEquals( "check powered by logo image", "../../tomcat/logo.gif", poweredBy.getImg() );
315
316 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
317 assertEquals( "check breadcrumb href", "../../apache", breadcrumb.getHref() );
318
319 LinkItem link = childModel.getBody().getLinks().get( 0 );
320 assertEquals( "check link href", "../../bouncycastle/", link.getHref() );
321
322 Menu menu = childModel.getBody().getMenus().get( 0 );
323 LinkItem menuItem = menu.getItems().get( 0 );
324 assertEquals( "check menu item href", "../../special/", menuItem.getHref() );
325 }
326
327
328
329
330
331
332 public void testPathsResolvedForReverseRelativeUrls()
333 throws IOException, XmlPullParserException
334 {
335 DecorationModel parentModel = readModel( "relative-urls.xml" );
336 DecorationModel childModel = readModel( "empty.xml" );
337
338 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/",
339 "http://maven.apache.org/doxia/" );
340 assertPathsResolvedForReverseRelativeUrls( childModel );
341
342
343 childModel = readModel( "empty.xml" );
344 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/",
345 "scp://people.apache.org/doxia/" );
346 assertPathsResolvedForReverseRelativeUrls( childModel );
347
348 assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel );
349 }
350
351 private static void assertPathsResolvedForReverseRelativeUrls( final DecorationModel childModel )
352 {
353 assertEquals( "check left banner href", "doxia/banner/left", childModel.getBannerLeft().getHref() );
354 assertEquals( "check left banner image", "doxia/images/jakarta-logo.gif", childModel.getBannerLeft().getSrc() );
355
356 assertEquals( "check right banner href", "doxia/banner/right/", childModel.getBannerRight().getHref() );
357 assertEquals( "check right banner image", "doxia/commons/images/logo.png",
358 childModel.getBannerRight().getSrc() );
359
360 Logo poweredBy = childModel.getPoweredBy().get( 0 );
361 assertEquals( "check powered by logo href", "doxia/tomcat", poweredBy.getHref() );
362 assertEquals( "check powered by logo image", "doxia/tomcat/logo.gif", poweredBy.getImg() );
363
364 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
365 assertEquals( "check breadcrumb href", "doxia/apache", breadcrumb.getHref() );
366
367 LinkItem link = childModel.getBody().getLinks().get( 0 );
368 assertEquals( "check link href", "doxia/bouncycastle/", link.getHref() );
369
370 Menu menu = childModel.getBody().getMenus().get( 0 );
371 LinkItem menuItem = menu.getItems().get( 0 );
372 assertEquals( "check menu item href", "doxia/special/", menuItem.getHref() );
373 }
374
375
376
377
378
379
380 public void testPathsResolvedForReverseRelativeUrlsDepthOfTwo()
381 throws IOException, XmlPullParserException
382 {
383 DecorationModel parentModel = readModel( "relative-urls.xml" );
384 DecorationModel childModel = readModel( "empty.xml" );
385
386 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/",
387 "http://maven.apache.org/doxia/core/" );
388 assertPathsResolvedForReverseRelativeUrlsDepthOfTwo( childModel );
389
390
391 childModel = readModel( "empty.xml" );
392 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/",
393 "scp://people.apache.org/doxia/core/" );
394 assertPathsResolvedForReverseRelativeUrlsDepthOfTwo( childModel );
395
396 assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel );
397 }
398
399 private static void assertPathsResolvedForReverseRelativeUrlsDepthOfTwo( final DecorationModel childModel )
400 {
401 assertEquals( "check left banner href", "doxia/core/banner/left", childModel.getBannerLeft().getHref() );
402 assertEquals( "check left banner image", "doxia/core/images/jakarta-logo.gif",
403 childModel.getBannerLeft().getSrc() );
404
405 assertEquals( "check right banner href", "doxia/core/banner/right/", childModel.getBannerRight().getHref() );
406 assertEquals( "check right banner image", "doxia/core/commons/images/logo.png",
407 childModel.getBannerRight().getSrc() );
408
409 Logo poweredBy = childModel.getPoweredBy().get( 0 );
410 assertEquals( "check powered by logo href", "doxia/core/tomcat", poweredBy.getHref() );
411 assertEquals( "check powered by logo image", "doxia/core/tomcat/logo.gif", poweredBy.getImg() );
412
413 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
414 assertEquals( "check breadcrumb href", "doxia/core/apache", breadcrumb.getHref() );
415
416 LinkItem link = childModel.getBody().getLinks().get( 0 );
417 assertEquals( "check link href", "doxia/core/bouncycastle/", link.getHref() );
418
419 Menu menu = childModel.getBody().getMenus().get( 0 );
420 LinkItem menuItem = menu.getItems().get( 0 );
421 assertEquals( "check menu item href", "doxia/core/special/", menuItem.getHref() );
422 }
423
424
425
426
427
428
429 public void testPathsResolvedForUnrelatedRelativeUrls()
430 throws IOException, XmlPullParserException
431 {
432 DecorationModel parentModel = readModel( "relative-urls.xml" );
433 DecorationModel childModel = readModel( "empty.xml" );
434
435 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org",
436 "http://jakarta.apache.org" );
437 assertPathsResolvedForUnrelatedRelativeUrls( childModel );
438
439
440 childModel = readModel( "empty.xml" );
441 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://people.apache.org/",
442 "http://jakarta.apache.org" );
443 assertPathsResolvedForUnrelatedRelativeUrls( childModel );
444
445 assertEquals( "Modified parent!", readModel( "relative-urls.xml" ), parentModel );
446 }
447
448 private static void assertPathsResolvedForUnrelatedRelativeUrls( final DecorationModel childModel )
449 {
450 assertEquals( "check left banner href", "http://jakarta.apache.org/banner/left",
451 childModel.getBannerLeft().getHref() );
452 assertEquals( "check left banner image", "http://jakarta.apache.org/images/jakarta-logo.gif",
453 childModel.getBannerLeft().getSrc() );
454
455 assertEquals( "check right banner href", "http://jakarta.apache.org/banner/right/",
456 childModel.getBannerRight().getHref() );
457 assertEquals( "check right banner image", "http://jakarta.apache.org/commons/images/logo.png",
458 childModel.getBannerRight().getSrc() );
459
460 Logo poweredBy = childModel.getPoweredBy().get( 0 );
461 assertEquals( "check powered by logo href", "http://jakarta.apache.org/tomcat", poweredBy.getHref() );
462 assertEquals( "check powered by logo image", "http://jakarta.apache.org/tomcat/logo.gif", poweredBy.getImg() );
463
464 LinkItem breadcrumb = childModel.getBody().getBreadcrumbs().get( 0 );
465 assertEquals( "check breadcrumb href", "http://jakarta.apache.org/apache", breadcrumb.getHref() );
466
467 LinkItem link = childModel.getBody().getLinks().get( 0 );
468 assertEquals( "check link href", "http://jakarta.apache.org/bouncycastle/", link.getHref() );
469
470 Menu menu = childModel.getBody().getMenus().get( 0 );
471 LinkItem menuItem = menu.getItems().get( 0 );
472 assertEquals( "check menu item href", "http://jakarta.apache.org/special/", menuItem.getHref() );
473 }
474
475
476
477
478
479
480 public void testNullParent()
481 throws IOException, XmlPullParserException
482 {
483 DecorationModel childModel = readModel( "empty.xml" );
484
485 assembler.assembleModelInheritance( NAME, childModel, null, "http://maven.apache.org/doxia",
486 "http://maven.apache.org" );
487 DecorationModel mergedModel = readModel( "empty.xml" );
488
489 assertEquals( "Check result", mergedModel, childModel );
490
491
492 childModel = readModel( "empty.xml" );
493 assembler.assembleModelInheritance( NAME, childModel, null, "scp://people.apache.org/doxia",
494 "scp://people.apache.org" );
495 assertEquals( "Check scp result", mergedModel, childModel );
496 }
497
498
499
500
501
502
503 public void testFullyPopulatedChild()
504 throws IOException, XmlPullParserException
505 {
506 DecorationModel childModel = readModel( "fully-populated-child.xml" );
507 DecorationModel parentModel = readModel( "fully-populated-child.xml" );
508
509 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://foo.apache.org/doxia",
510 "http://foo.apache.org" );
511 DecorationModel mergedModel = readModel( "fully-populated-child.xml" );
512
513 assertEquals( "Check result", mergedModel, childModel );
514
515
516 childModel = readModel( "fully-populated-child.xml" );
517 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://foo.apache.org/doxia",
518 "scp://foo.apache.org" );
519 assertEquals( "Check scp result", mergedModel, childModel );
520
521 assertEquals( "Modified parent!", readModel( "fully-populated-child.xml" ), parentModel );
522 }
523
524
525
526
527
528
529 public void testFullyPopulatedParentAndEmptyChild()
530 throws IOException, XmlPullParserException
531 {
532 DecorationModel childModel = readModel( "empty.xml" );
533 DecorationModel parentModel = readModel( "fully-populated-child.xml" );
534
535 assembler.assembleModelInheritance( NAME, childModel, parentModel, "http://maven.apache.org/doxia",
536 "http://maven.apache.org" );
537
538 DecorationModel unresolvedModel = readModel( "fully-populated-unresolved.xml" );
539 assertEquals( "Check result", unresolvedModel, childModel );
540
541 assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" );
542 DecorationModel mergedModel = readModel( "fully-populated-merged.xml" );
543
544 assertEquals( "Check result", mergedModel, childModel );
545
546
547 childModel = readModel( "empty.xml" );
548 assembler.assembleModelInheritance( NAME, childModel, parentModel, "scp://maven.apache.org/doxia",
549 "scp://maven.apache.org" );
550 assembler.resolvePaths( childModel, "http://maven.apache.org/doxia" );
551 assertEquals( "Check scp result", mergedModel, childModel );
552
553 assertEquals( "Modified parent!", readModel( "fully-populated-child.xml" ), parentModel );
554 }
555
556
557
558
559
560
561 public void testResolvingAllExternalUrls()
562 throws IOException, XmlPullParserException
563 {
564 DecorationModel model = readModel( "external-urls.xml" );
565
566 assembler.resolvePaths( model, "http://foo.com/" );
567 DecorationModel mergedModel = readModel( "external-urls.xml" );
568
569 assertEquals( "Check result", mergedModel, model );
570 }
571
572
573
574
575
576
577 public void testResolvingAllRelativeUrls()
578 throws IOException, XmlPullParserException
579 {
580 DecorationModel model = readModel( "relative-urls.xml" );
581
582 assembler.resolvePaths( model, "http://foo.com/" );
583
584 DecorationModel resolvedModel = readModel( "relative-urls-resolved.xml" );
585
586 assertEquals( "Check result", resolvedModel, model );
587 }
588
589
590
591
592
593
594 public void testResolvingAllSiteUrls()
595 throws IOException, XmlPullParserException
596 {
597 DecorationModel model = readModel( "subsite-urls.xml" );
598
599 assembler.resolvePaths( model, "http://maven.apache.org/" );
600
601 DecorationModel resolvedModel = readModel( "relative-urls-resolved.xml" );
602 assertEquals( "Check result", resolvedModel, model );
603 }
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646 public void testResolvingEmptyDescriptor()
647 throws IOException, XmlPullParserException
648 {
649 DecorationModel model = readModel( "empty.xml" );
650 assembler.resolvePaths( model, "http://maven.apache.org" );
651 DecorationModel mergedModel = readModel( "empty.xml" );
652
653 assertEquals( "Check result", mergedModel, model );
654 }
655
656
657
658
659 public void testDuplicateParentElements()
660 {
661 DecorationModel model = new DecorationModel();
662 model.setBody( new Body() );
663 model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
664 model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
665
666 model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg" ) );
667 model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg" ) );
668
669 DecorationModel child = new DecorationModel();
670 assembler.assembleModelInheritance( NAME, child, model, "http://maven.apache.org/doxia",
671 "http://maven.apache.org" );
672
673 assertEquals( "Check size", 1, child.getBody().getLinks().size() );
674 assertEquals( "Check item", createLinkItem( "Foo", "http://foo.apache.org" ),
675 child.getBody().getLinks().get( 0 ) );
676
677 assertEquals( "Check size", 1, child.getPoweredBy().size() );
678 assertEquals( "Check item", createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg" ),
679 child.getPoweredBy().get( 0 ) );
680 }
681
682
683
684
685 public void testDuplicateChildElements()
686 {
687 DecorationModel model = new DecorationModel();
688 model.setBody( new Body() );
689 model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
690 model.getBody().addLink( createLinkItem( "Foo", "http://foo.apache.org" ) );
691
692 model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg" ) );
693 model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg" ) );
694
695 DecorationModel parent = new DecorationModel();
696 assembler.assembleModelInheritance( NAME, model, parent, "http://maven.apache.org/doxia",
697 "http://maven.apache.org" );
698
699 assertEquals( "Check size", 1, model.getBody().getLinks().size() );
700 assertEquals( "Check item", createLinkItem( "Foo", "http://foo.apache.org" ),
701 model.getBody().getLinks().get( 0 ) );
702
703 assertEquals( "Check size", 1, model.getPoweredBy().size() );
704 assertEquals( "Check item", createLogo( "Foo", "http://foo.apache.org", "http://foo.apache.org/foo.jpg" ),
705 model.getPoweredBy().get( 0 ) );
706
707 assertEquals( "Modified parent!", new DecorationModel(), parent );
708 }
709
710
711
712
713 public void testBadHref()
714 {
715 final DecorationModel model = new DecorationModel();
716 model.setBody( new Body() );
717 model.getBody().addBreadcrumb( createLinkItem( "Foo", "http://foo.apache.org/${property}" ) );
718 assembler.resolvePaths( model, "http://foo.apache.org" );
719 assertEquals( "Check size", 1, model.getBody().getBreadcrumbs().size() );
720 assertEquals( "Check item", createLinkItem( "Foo", "http://foo.apache.org/${property}" ),
721 model.getBody().getBreadcrumbs().get( 0 ) );
722 }
723
724
725
726
727 public void testBreadcrumbWithoutHref()
728 {
729 DecorationModel model = new DecorationModel();
730 model.setBody( new Body() );
731 model.getBody().addBreadcrumb( createLinkItem( "Foo", null ) );
732 assembler.resolvePaths( model, "http://foo.apache.org" );
733 assertEquals( "Check size", 1, model.getBody().getBreadcrumbs().size() );
734 assertEquals( "Check item", createLinkItem( "Foo", null ), model.getBody().getBreadcrumbs().get( 0 ) );
735 }
736
737
738
739
740 public void testBreadcrumbs()
741 {
742 String parentHref = "http://parent.com/index.html";
743
744 final DecorationModel parent = new DecorationModel();
745 parent.setBody( new Body() );
746 parent.getBody().addBreadcrumb( createLinkItem( "Parent", parentHref ) );
747
748 DecorationModel child = new DecorationModel();
749 assembler.assembleModelInheritance( "childName", child, parent,
750 "http://parent.com/child", "http://parent.com" );
751 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "childName", parentHref );
752
753
754
755 child = new DecorationModel();
756 assembler.assembleModelInheritance( "childName", child, parent,
757 "http://parent.com/child/", "http://parent.com/" );
758 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "childName", parentHref );
759
760
761 child = new DecorationModel();
762 assembler.assembleModelInheritance( "childName", child, parent,
763 "http://parent.com/child/", "http://parent.com" );
764 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "childName", parentHref );
765
766
767 child = new DecorationModel();
768 assembler.assembleModelInheritance( "childName", child, parent,
769 "http://parent.com/child", "http://parent.com/" );
770 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "childName", parentHref );
771
772
773
774 child = new DecorationModel();
775 child.setBody( new Body() );
776 child.getBody().addBreadcrumb( createLinkItem( "Child", "" ) );
777 assembler.assembleModelInheritance( "childName", child, parent,
778 "http://parent.com/child/", "http://parent.com/" );
779 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "Child", parentHref );
780
781
782
783 parentHref = "file://parent.com/index.html";
784 ( parent.getBody().getBreadcrumbs().get( 0 ) ).setHref( parentHref );
785 child = new DecorationModel();
786 assembler.assembleModelInheritance( "childName", child, parent,
787 "file://parent.com/child/", "file://parent.com/" );
788 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "childName", parentHref );
789
790
791
792 parentHref = "scp://parent.com/index.html";
793 ( parent.getBody().getBreadcrumbs().get( 0 ) ).setHref( parentHref );
794 child = new DecorationModel();
795 assembler.assembleModelInheritance( "childName", child, parent,
796 "scp://parent.com/child/", "scp://parent.com/" );
797 assertBreadcrumbsCorrect( child.getBody().getBreadcrumbs(), "childName", parentHref );
798 }
799
800 private static void assertBreadcrumbsCorrect( final List<LinkItem> breadcrumbs, final String childName,
801 final String parentHref )
802 {
803 assertEquals( "Check size", 2, breadcrumbs.size() );
804 assertEquals( "Check parent item", createLinkItem( "Parent", parentHref ), breadcrumbs.get( 0 ) );
805 assertEquals( "Check child item", createLinkItem( childName, "" ), breadcrumbs.get( 1 ) );
806 }
807
808
809
810
811 public void testBreadcrumbCutParentAfterDuplicate()
812 {
813 DecorationModel child = new DecorationModel();
814 child.setBody( new Body() );
815 child.getBody().addBreadcrumb( createLinkItem( "B", null ) );
816 child.getBody().addBreadcrumb( createLinkItem( "E", null ) );
817
818 DecorationModel parent = new DecorationModel();
819 parent.setBody( new Body() );
820 parent.getBody().addBreadcrumb( createLinkItem( "A", null ) );
821 parent.getBody().addBreadcrumb( createLinkItem( "B", null ) );
822 parent.getBody().addBreadcrumb( createLinkItem( "C", null ) );
823 parent.getBody().addBreadcrumb( createLinkItem( "D", null ) );
824
825 assembler.assembleModelInheritance( NAME, child, parent, "http://maven.apache.org/doxia",
826 "http://maven.apache.org" );
827
828 final List<LinkItem> breadcrumbs = child.getBody().getBreadcrumbs();
829 assertEquals( "Check size", 3, breadcrumbs.size() );
830 assertEquals( "Check item", createLinkItem( "A", null ), breadcrumbs.get( 0 ) );
831 assertEquals( "Check item", createLinkItem( "B", null ), breadcrumbs.get( 1 ) );
832 assertEquals( "Check item", createLinkItem( "E", null ), breadcrumbs.get( 2 ) );
833 }
834
835
836
837
838 public void testBannerWithoutHref()
839 {
840 DecorationModel model = new DecorationModel();
841 model.setBody( new Body() );
842
843 Banner banner = createBanner( "Left", null, "/images/src.gif", "alt" );
844
845 model.setBannerLeft( banner );
846
847 assembler.resolvePaths( model, "http://foo.apache.org" );
848
849 assertEquals( "Check banner", createBanner( "Left", null, "images/src.gif", "alt" ), model.getBannerLeft() );
850 }
851
852
853
854
855 public void testLogoWithoutImage()
856 {
857
858 DecorationModel model = new DecorationModel();
859 model.setBody( new Body() );
860 model.addPoweredBy( createLogo( "Foo", "http://foo.apache.org", null ) );
861 assembler.resolvePaths( model, "http://foo.apache.org" );
862 assertEquals( "Check size", 1, model.getPoweredBy().size() );
863 assertEquals( "Check item", createLogo( "Foo", "./", null ), model.getPoweredBy().get( 0 ) );
864 }
865
866 private static Banner createBanner( String name, String href, String src, String alt )
867 {
868 Banner banner = new Banner();
869 banner.setName( name );
870 banner.setHref( href );
871 banner.setSrc( src );
872 banner.setAlt( alt );
873 return banner;
874 }
875
876 private Logo createLogo( String name, String href, String img )
877 {
878 Logo logo = new Logo();
879 logo.setHref( href );
880 logo.setImg( img );
881 logo.setName( name );
882 return logo;
883 }
884
885 private static LinkItem createLinkItem( String name, String href )
886 {
887 LinkItem item = new LinkItem();
888 item.setName( name );
889 item.setHref( href );
890 return item;
891 }
892
893 private DecorationModel readModel( String name )
894 throws IOException, XmlPullParserException
895 {
896 Reader reader = null;
897 try
898 {
899 reader = ReaderFactory.newXmlReader( getClass().getResourceAsStream( "/" + name ) );
900 return new DecorationXpp3Reader().read( reader );
901 }
902 finally
903 {
904 IOUtil.close( reader );
905 }
906 }
907 }