View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia.siterenderer;
20  
21  import java.util.Iterator;
22  
23  import com.gargoylesoftware.htmlunit.html.HtmlElement;
24  import com.gargoylesoftware.htmlunit.html.HtmlHeading1;
25  import com.gargoylesoftware.htmlunit.html.HtmlListItem;
26  import com.gargoylesoftware.htmlunit.html.HtmlMain;
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 static org.junit.jupiter.api.Assertions.assertEquals;
33  import static org.junit.jupiter.api.Assertions.assertFalse;
34  import static org.junit.jupiter.api.Assertions.assertNotNull;
35  
36  /**
37   *
38   * @author ltheussl
39   */
40  public class MultipleBlockVerifier extends AbstractVerifier {
41      /** {@inheritDoc} */
42      public void verify(String file) throws Exception {
43          HtmlPage page = htmlPage(file);
44          assertNotNull(page);
45  
46          HtmlElement element = page.getHtmlElementById("contentBox");
47          assertNotNull(element);
48          HtmlMain main = (HtmlMain) element;
49          assertNotNull(main);
50  
51          Iterator<HtmlElement> elementIterator = main.getHtmlElementDescendants().iterator();
52  
53          // ----------------------------------------------------------------------
54          // Verify link
55          // ----------------------------------------------------------------------
56  
57          HtmlSection section = (HtmlSection) elementIterator.next();
58          assertNotNull(section);
59  
60          HtmlHeading1 h1 = (HtmlHeading1) elementIterator.next();
61          assertNotNull(h1);
62          assertEquals("section name", h1.asNormalizedText().trim());
63  
64          // ----------------------------------------------------------------------
65          // Paragraph
66          // ----------------------------------------------------------------------
67  
68          HtmlParagraph p = (HtmlParagraph) elementIterator.next();
69          assertNotNull(p);
70          assertEquals("text", p.asNormalizedText().trim());
71  
72          // ----------------------------------------------------------------------
73          // Unordered list
74          // ----------------------------------------------------------------------
75  
76          HtmlUnorderedList ul = (HtmlUnorderedList) elementIterator.next();
77          assertNotNull(ul);
78  
79          HtmlListItem li = (HtmlListItem) elementIterator.next();
80          assertNotNull(li);
81          assertEquals("list1", li.getFirstChild().asNormalizedText().trim());
82  
83          // ----------------------------------------------------------------------
84          // Paragraph
85          // ----------------------------------------------------------------------
86  
87          p = (HtmlParagraph) elementIterator.next();
88          assertNotNull(p);
89          assertEquals("text2", p.asNormalizedText().trim());
90  
91          // ----------------------------------------------------------------------
92          // Unordered list
93          // ----------------------------------------------------------------------
94  
95          ul = (HtmlUnorderedList) elementIterator.next();
96          assertNotNull(ul);
97  
98          li = (HtmlListItem) elementIterator.next();
99          assertNotNull(li);
100         assertEquals("list1", li.getFirstChild().asNormalizedText().trim());
101 
102         // ----------------------------------------------------------------------
103         // Paragraph
104         // ----------------------------------------------------------------------
105 
106         p = (HtmlParagraph) elementIterator.next();
107         assertNotNull(p);
108         assertEquals("text3", p.asNormalizedText().trim());
109 
110         // ----------------------------------------------------------------------
111         // Unordered list
112         // ----------------------------------------------------------------------
113 
114         ul = (HtmlUnorderedList) elementIterator.next();
115         assertNotNull(ul);
116 
117         li = (HtmlListItem) elementIterator.next();
118         assertNotNull(li);
119 
120         p = (HtmlParagraph) elementIterator.next();
121         assertNotNull(p);
122         assertEquals("list1", p.getFirstChild().asNormalizedText().trim());
123 
124         assertFalse(elementIterator.hasNext());
125     }
126 }