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