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