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.HtmlDivision;
24  import com.gargoylesoftware.htmlunit.html.HtmlElement;
25  import com.gargoylesoftware.htmlunit.html.HtmlHeading1;
26  import com.gargoylesoftware.htmlunit.html.HtmlHeading2;
27  import com.gargoylesoftware.htmlunit.html.HtmlHeading3;
28  import com.gargoylesoftware.htmlunit.html.HtmlMain;
29  import com.gargoylesoftware.htmlunit.html.HtmlPage;
30  import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
31  import com.gargoylesoftware.htmlunit.html.HtmlPreformattedText;
32  import com.gargoylesoftware.htmlunit.html.HtmlSection;
33  
34  import static org.junit.jupiter.api.Assertions.assertEquals;
35  import static org.junit.jupiter.api.Assertions.assertFalse;
36  import static org.junit.jupiter.api.Assertions.assertNotNull;
37  
38  /**
39   * Verify the <code>site/xdoc/entityTest.xml</code>
40   *
41   * @author ltheussl
42   */
43  public class EntitiesVerifier extends AbstractVerifier {
44      /** {@inheritDoc} */
45      public void verify(String file) throws Exception {
46          HtmlPage page = htmlPage(file);
47          assertNotNull(page);
48  
49          HtmlElement element = page.getHtmlElementById("contentBox");
50          assertNotNull(element);
51          HtmlMain main = (HtmlMain) element;
52          assertNotNull(main);
53  
54          Iterator<HtmlElement> elementIterator = main.getHtmlElementDescendants().iterator();
55  
56          // ----------------------------------------------------------------------
57          //
58          // ----------------------------------------------------------------------
59  
60          HtmlSection section = (HtmlSection) elementIterator.next();
61  
62          HtmlHeading1 h1 = (HtmlHeading1) elementIterator.next();
63          assertNotNull(h1);
64          assertEquals(h1.asNormalizedText().trim(), "section name with entities: '&' '\u0391' ' ' '\uD835\uDFED'");
65  
66          section = (HtmlSection) elementIterator.next();
67          assertNotNull(section);
68  
69          section = (HtmlSection) elementIterator.next();
70          assertNotNull(section);
71  
72          HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
73          assertNotNull(h3);
74          assertEquals("Entities", h3.asNormalizedText().trim());
75  
76          section = (HtmlSection) elementIterator.next();
77          assertNotNull(section);
78  
79          HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
80          assertNotNull(h2);
81          assertEquals(
82                  "Generic Entities: '&' '<' '>' '\"' '''", h2.asNormalizedText().trim());
83  
84          HtmlParagraph p = (HtmlParagraph) elementIterator.next();
85          assertNotNull(p);
86          assertEquals("'&' '<' '>' '\"' '''", p.asNormalizedText().trim());
87  
88          section = (HtmlSection) elementIterator.next();
89          assertNotNull(section);
90  
91          h2 = (HtmlHeading2) elementIterator.next();
92          assertNotNull(h2);
93          assertEquals(
94                  "Local Entities: '\u0391' '\u0392' '\u0393' '\uD835\uDFED'",
95                  h2.asNormalizedText().trim());
96  
97          p = (HtmlParagraph) elementIterator.next();
98          assertNotNull(p);
99          assertEquals(
100                 "'\u0391' '\u0392' '\u0393' '\uD835\uDFED\uD835\uDFED' '\u0159\u0159' '\u0159'",
101                 p.asNormalizedText().trim());
102 
103         section = (HtmlSection) elementIterator.next();
104         assertNotNull(section);
105 
106         h2 = (HtmlHeading2) elementIterator.next();
107         assertNotNull(h2);
108         assertEquals(
109                 "DTD Entities: ' ' '\u00A1' '\u00A2'", h2.asNormalizedText().trim());
110 
111         p = (HtmlParagraph) elementIterator.next();
112         assertNotNull(p);
113         assertEquals("' ' '\u00A1' '\u00A2'", p.asNormalizedText().trim());
114 
115         section = (HtmlSection) elementIterator.next();
116         assertNotNull(section);
117 
118         h3 = (HtmlHeading3) elementIterator.next();
119         assertNotNull(h3);
120         assertEquals("CDATA", h3.asNormalizedText().trim());
121 
122         HtmlDivision div = (HtmlDivision) elementIterator.next();
123         assertNotNull(div);
124 
125         HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
126         assertNotNull(pre);
127         assertEquals("<project xmlns:ant=\"jelly:ant\">", pre.asNormalizedText().trim());
128 
129         p = (HtmlParagraph) elementIterator.next();
130         assertNotNull(p);
131         assertEquals("'&nbsp;' '&iexcl;'", p.asNormalizedText().trim());
132 
133         assertFalse(elementIterator.hasNext());
134     }
135 }