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.HtmlAnchor;
23  import com.gargoylesoftware.htmlunit.html.HtmlDivision;
24  import com.gargoylesoftware.htmlunit.html.HtmlElement;
25  import com.gargoylesoftware.htmlunit.html.HtmlHeading2;
26  import com.gargoylesoftware.htmlunit.html.HtmlListItem;
27  import com.gargoylesoftware.htmlunit.html.HtmlPage;
28  import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
29  import com.gargoylesoftware.htmlunit.html.HtmlUnorderedList;
30  
31  import java.util.Iterator;
32  
33  /**
34   *
35   * @author ltheussl
36   * @version $Id: MultipleBlockVerifier.java 1737482 2016-04-02 09:56:25Z hboutemy $
37   */
38  public class MultipleBlockVerifier
39      extends AbstractVerifier
40  {
41      /** {@inheritDoc} */
42      public void verify( String file )
43              throws Exception
44      {
45          HtmlPage page = htmlPage( file );
46          assertNotNull( page );
47  
48          HtmlElement element = page.getHtmlElementById( "contentBox" );
49          assertNotNull( element );
50          HtmlDivision division = (HtmlDivision) element;
51          assertNotNull( division );
52  
53          Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
54  
55          // ----------------------------------------------------------------------
56          // Verify link
57          // ----------------------------------------------------------------------
58  
59          HtmlDivision div = (HtmlDivision) elementIterator.next();
60          assertNotNull( div );
61          assertEquals( "section", div.getAttribute( "class" ) );
62  
63          HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
64          assertNotNull( h2 );
65          assertEquals( "section name", h2.asText().trim() );
66  
67          HtmlAnchor a = (HtmlAnchor) elementIterator.next();
68          assertNotNull( a );
69          assertEquals( "section_name", a.getAttribute( "name" ) );
70  
71          // ----------------------------------------------------------------------
72          // Paragraph
73          // ----------------------------------------------------------------------
74  
75          HtmlParagraph p = (HtmlParagraph) elementIterator.next();
76          assertNotNull( p );
77          assertEquals( "text", p.asText().trim() );
78  
79          // ----------------------------------------------------------------------
80          // Unordered list
81          // ----------------------------------------------------------------------
82  
83          HtmlUnorderedList ul = (HtmlUnorderedList) elementIterator.next();
84          assertNotNull( ul );
85  
86          HtmlListItem li = (HtmlListItem) elementIterator.next();
87          assertNotNull( li );
88          assertEquals( "list1", li.getFirstChild().asText().trim() );
89  
90          // ----------------------------------------------------------------------
91          // Paragraph
92          // ----------------------------------------------------------------------
93  
94          p = (HtmlParagraph) elementIterator.next();
95          assertNotNull( p );
96          assertEquals( "text2", p.asText().trim() );
97  
98          // ----------------------------------------------------------------------
99          // Unordered list
100         // ----------------------------------------------------------------------
101 
102         ul = (HtmlUnorderedList) elementIterator.next();
103         assertNotNull( ul );
104 
105         li = (HtmlListItem) elementIterator.next();
106         assertNotNull( li );
107         assertEquals( "list1", li.getFirstChild().asText().trim() );
108 
109         // ----------------------------------------------------------------------
110         // Paragraph
111         // ----------------------------------------------------------------------
112 
113         p = (HtmlParagraph) elementIterator.next();
114         assertNotNull( p );
115         assertEquals( "text3", p.asText().trim() );
116 
117         // ----------------------------------------------------------------------
118         // Unordered list
119         // ----------------------------------------------------------------------
120 
121         ul = (HtmlUnorderedList) elementIterator.next();
122         assertNotNull( ul );
123 
124         li = (HtmlListItem) elementIterator.next();
125         assertNotNull( li );
126 
127         p = (HtmlParagraph) elementIterator.next();
128         assertNotNull( p );
129         assertEquals( "list1", p.getFirstChild().asText().trim() );
130 
131         assertFalse( elementIterator.hasNext() );
132     }
133 }