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