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(h1.asNormalizedText().trim(), "section name with entities: '&' '\u0391' ' ' '\uD835\uDFED'");
71  
72          section = (HtmlSection) elementIterator.next();
73          assertNotNull(section);
74  
75          anchor = (HtmlAnchor) elementIterator.next();
76          assertNotNull(anchor);
77          assertEquals("Entities", anchor.getAttribute("id"));
78          HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
79          assertNotNull(h2);
80          assertEquals("Entities", h2.asNormalizedText().trim());
81  
82          section = (HtmlSection) elementIterator.next();
83          assertNotNull(section);
84  
85          anchor = (HtmlAnchor) elementIterator.next();
86          assertNotNull(anchor);
87          assertEquals(
88                  "Generic_Entities.3A_.27.26.27_.27.3C.27_.27.3E.27_.27.22.27_.27.27.27", anchor.getAttribute("id"));
89          HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
90          assertNotNull(h3);
91          assertEquals(
92                  "Generic Entities: '&' '<' '>' '\"' '''", h3.asNormalizedText().trim());
93  
94          HtmlParagraph p = (HtmlParagraph) elementIterator.next();
95          assertNotNull(p);
96          assertEquals("'&' '<' '>' '\"' '''", p.asNormalizedText().trim());
97  
98          section = (HtmlSection) elementIterator.next();
99          assertNotNull(section);
100 
101         anchor = (HtmlAnchor) elementIterator.next();
102         assertNotNull(anchor);
103         assertEquals(
104                 "Local_Entities.3A_.27.CE.91.27_.27.CE.92.27_.27.CE.93.27_.27.3F.3F.27", anchor.getAttribute("id"));
105         h3 = (HtmlHeading3) elementIterator.next();
106         assertNotNull(h3);
107         assertEquals(
108                 "Local Entities: '\u0391' '\u0392' '\u0393' '\uD835\uDFED'",
109                 h3.asNormalizedText().trim());
110 
111         p = (HtmlParagraph) elementIterator.next();
112         assertNotNull(p);
113         assertEquals(
114                 "'\u0391' '\u0392' '\u0393' '\uD835\uDFED\uD835\uDFED' '\u0159\u0159' '\u0159'",
115                 p.asNormalizedText().trim());
116 
117         section = (HtmlSection) elementIterator.next();
118         assertNotNull(section);
119 
120         anchor = (HtmlAnchor) elementIterator.next();
121         assertNotNull(anchor);
122         assertEquals("DTD_Entities.3A_.27.27_.27.C2.A1.27_.27.C2.A2.27", anchor.getAttribute("id"));
123         h3 = (HtmlHeading3) elementIterator.next();
124         assertNotNull(h3);
125         assertEquals(
126                 "DTD Entities: ' ' '\u00A1' '\u00A2'", h3.asNormalizedText().trim());
127 
128         p = (HtmlParagraph) elementIterator.next();
129         assertNotNull(p);
130         assertEquals("' ' '\u00A1' '\u00A2'", p.asNormalizedText().trim());
131 
132         section = (HtmlSection) elementIterator.next();
133         assertNotNull(section);
134 
135         anchor = (HtmlAnchor) elementIterator.next();
136         assertNotNull(anchor);
137         assertEquals("CDATA", anchor.getAttribute("id"));
138         h2 = (HtmlHeading2) elementIterator.next();
139         assertNotNull(h2);
140         assertEquals("CDATA", h2.asNormalizedText().trim());
141 
142         HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
143         assertNotNull(pre);
144         HtmlCode code = (HtmlCode) elementIterator.next();
145         assertNotNull(code);
146         assertEquals(
147                 "<project xmlns:ant=\"jelly:ant\">", code.asNormalizedText().trim());
148 
149         p = (HtmlParagraph) elementIterator.next();
150         assertNotNull(p);
151         assertEquals("'&nbsp;' '&iexcl;'", p.asNormalizedText().trim());
152 
153         assertFalse(elementIterator.hasNext());
154     }
155 }