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