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.ArrayList;
31  import java.util.Iterator;
32  import java.util.List;
33  
34  /**
35   * Verify correct rendering of <code>site/xdoc/head.xml</code>.
36   *
37   * @author ltheussl
38   * @version $Id: HeadVerifier.java 1737482 2016-04-02 09:56:25Z hboutemy $
39   */
40  public class HeadVerifier
41      extends AbstractVerifier
42  {
43  
44      /** {@inheritDoc} */
45      public void verify( String file )
46              throws Exception
47      {
48          HtmlPage page = htmlPage( file );
49          assertNotNull( page );
50  
51          HtmlElement html = page.getDocumentElement();
52          assertNotNull( html );
53  
54          List<String> tagNames = new ArrayList<String>( 2 );
55          tagNames.add( "head" );
56          List<HtmlElement> heads = html.getHtmlElementsByTagNames( tagNames );
57          assertEquals( 1, heads.size() );
58          HtmlElement head = heads.get( 0 );
59          assertNotNull( head );
60  
61          Iterator<HtmlElement> elementIterator = head.getHtmlElementDescendants().iterator();
62  
63          // ----------------------------------------------------------------------
64          //
65          // ----------------------------------------------------------------------
66  
67          HtmlMeta meta = (HtmlMeta) elementIterator.next();
68          assertEquals( "Content-Type", meta.getAttribute( "http-equiv" ) );
69          assertEquals( "text/html; charset=UTF-8", meta.getAttribute( "content" ) );
70  
71          HtmlTitle title = (HtmlTitle) elementIterator.next();
72          assertNotNull( title );
73  
74          HtmlStyle style = (HtmlStyle) elementIterator.next();
75          assertNotNull( style );
76  
77          HtmlLink link = (HtmlLink) elementIterator.next();
78          assertNotNull( link );
79  
80          meta = (HtmlMeta) elementIterator.next();
81          assertEquals( "author", meta.getAttribute( "name" ) );
82          assertEquals( "John Doe", meta.getAttribute( "content" ).trim() );
83  
84          meta = (HtmlMeta) elementIterator.next();
85          assertEquals( "Content-Language", meta.getAttribute( "http-equiv" ) );
86          assertEquals( "en", meta.getAttribute( "content" ) );
87  
88          meta = (HtmlMeta) elementIterator.next();
89          assertEquals( "description", meta.getAttribute( "name" ) );
90          assertEquals( "Free Web tutorials", meta.getAttribute( "content" ) );
91  
92          meta = (HtmlMeta) elementIterator.next();
93          assertEquals( "keywords", meta.getAttribute( "name" ) );
94          assertEquals( "HTML,CSS,XML,JavaScript", meta.getAttribute( "content" ) );
95  
96          HtmlBase base = (HtmlBase) elementIterator.next();
97          assertEquals( "http://maven.apache.org/", base.getAttribute( "href" ) );
98      }
99  }