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