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