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.HtmlSection;
30  import com.gargoylesoftware.htmlunit.html.HtmlUnorderedList;
31  
32  import java.util.Iterator;
33  
34  /**
35   *
36   * @author ltheussl
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          HtmlSection section = (HtmlSection) elementIterator.next();
60          assertNotNull( section );
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 }