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