View Javadoc
1   package org.apache.maven.doxia.siterenderer;
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 com.gargoylesoftware.htmlunit.html.HtmlBase;
23  import com.gargoylesoftware.htmlunit.html.HtmlElement;
24  import com.gargoylesoftware.htmlunit.html.HtmlLink;
25  import com.gargoylesoftware.htmlunit.html.HtmlMeta;
26  import com.gargoylesoftware.htmlunit.html.HtmlPage;
27  import com.gargoylesoftware.htmlunit.html.HtmlStyle;
28  import com.gargoylesoftware.htmlunit.html.HtmlTitle;
29  
30  import java.util.Iterator;
31  import java.util.List;
32  
33  /**
34   * Verify correct rendering of <code>site/xdoc/head.xml</code>.
35   *
36   * @author ltheussl
37   */
38  public class HeadVerifier
39      extends AbstractVerifier
40  {
41  
42      /** {@inheritDoc} */
43      public void verify( String file )
44              throws Exception
45      {
46          HtmlPage page = htmlPage( file );
47          assertNotNull( page );
48  
49          HtmlElement html = page.getDocumentElement();
50          assertNotNull( html );
51  
52          assertEquals( "en", html.getAttribute( "lang" ) );
53  
54          List<HtmlElement> heads = html.getElementsByTagName( "head" );
55          assertEquals( 1, heads.size() );
56          HtmlElement head = heads.get( 0 );
57          assertNotNull( head );
58  
59          Iterator<HtmlElement> elementIterator = head.getHtmlElementDescendants().iterator();
60  
61          // ----------------------------------------------------------------------
62          //
63          // ----------------------------------------------------------------------
64  
65          HtmlMeta meta = (HtmlMeta) elementIterator.next();
66          assertEquals( "UTF-8", meta.getAttribute( "charset" ) );
67  
68          // Skip viewport
69          elementIterator.next();
70  
71          meta = (HtmlMeta) elementIterator.next();
72          assertEquals( "Unexpected meta entry found generated resource " + file, "generator", meta.getAttribute( "name" ) );
73          String generator = meta.getAttribute("content");
74          assertEquals("Unexpected value found for generator meta entry in generated resource " + file, "Apache Maven Doxia Site Renderer", generator);
75  
76          meta = (HtmlMeta) elementIterator.next();
77          assertEquals( "author", meta.getAttribute( "name" ) );
78          assertEquals( "John Doe", meta.getAttribute( "content" ).trim() );
79  
80          HtmlTitle title = (HtmlTitle) elementIterator.next();
81          assertNotNull( title );
82  
83          HtmlLink link = (HtmlLink) elementIterator.next();
84          assertNotNull( link );
85          link = (HtmlLink) elementIterator.next();
86          assertNotNull( link );
87          link = (HtmlLink) elementIterator.next();
88          assertNotNull( link );
89          link = (HtmlLink) elementIterator.next();
90          assertNotNull( link );
91  
92          meta = (HtmlMeta) elementIterator.next();
93          assertEquals( "description", meta.getAttribute( "name" ) );
94          assertEquals( "Free Web tutorials", meta.getAttribute( "content" ) );
95  
96          meta = (HtmlMeta) elementIterator.next();
97          assertEquals( "keywords", meta.getAttribute( "name" ) );
98          assertEquals( "HTML,CSS,XML,JavaScript", meta.getAttribute( "content" ) );
99  
100         HtmlBase base = (HtmlBase) elementIterator.next();
101         assertEquals( "http://maven.apache.org/", base.getAttribute( "href" ) );
102     }
103 }