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