1 package org.apache.maven.doxia.siterenderer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.HtmlHeading2;
26 import com.gargoylesoftware.htmlunit.html.HtmlHeading3;
27 import com.gargoylesoftware.htmlunit.html.HtmlHeading4;
28 import com.gargoylesoftware.htmlunit.html.HtmlMeta;
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 java.util.Iterator;
35
36
37
38
39
40
41 public class EntitiesVerifier
42 extends AbstractVerifier
43 {
44
45 public void verify( String file )
46 throws Exception
47 {
48 HtmlPage page = htmlPage( file );
49 assertNotNull( page );
50
51 HtmlMeta author = (HtmlMeta) page.getElementsByName( "author" ).get( 0 );
52 assertNotNull( author );
53 assertTrue( author.toString().indexOf( "Ligature \u00C6" ) > 0 );
54 assertEquals( "Ligature \u00C6", author.getContentAttribute() );
55
56 author = (HtmlMeta) page.getElementsByName( "author" ).get( 1 );
57 assertNotNull( author );
58 assertTrue( author.toString().indexOf( "Ampersand &" ) > 0 );
59 assertEquals( "Ampersand &", author.getContentAttribute() );
60
61 author = (HtmlMeta) page.getElementsByName( "author" ).get( 2 );
62 assertNotNull( author );
63 assertTrue( author.toString().indexOf( "Less than <" ) > 0 );
64 assertEquals( "Less than <", author.getContentAttribute() );
65
66 author = (HtmlMeta) page.getElementsByName( "author" ).get( 3 );
67 assertNotNull( author );
68 assertTrue( author.toString().indexOf( "Greater than >" ) > 0 );
69 assertEquals( "Greater than >", author.getContentAttribute() );
70
71 author = (HtmlMeta) page.getElementsByName( "author" ).get( 4 );
72 assertNotNull( author );
73 assertEquals( "Apostrophe '", author.getContentAttribute() );
74
75 author = (HtmlMeta) page.getElementsByName( "author" ).get( 5 );
76 assertNotNull( author );
77 assertTrue( author.toString().indexOf( "Quote "" ) > 0 );
78 assertEquals( "Quote \"", author.getContentAttribute() );
79
80 author = (HtmlMeta) page.getElementsByName( "author" ).get( 6 );
81 assertNotNull( author );
82 assertTrue( author.toString().indexOf( "test@email.com" ) > 0 );
83 assertEquals( "test@email.com", author.getContentAttribute() );
84
85 author = (HtmlMeta) page.getElementsByName( "author" ).get( 7 );
86 assertNotNull( author );
87 assertTrue( author.toString().indexOf( "test\u00A9email.com" ) > 0 );
88 assertEquals( "test\u00A9email.com", author.getContentAttribute() );
89
90 HtmlElement element = page.getHtmlElementById( "contentBox" );
91 assertNotNull( element );
92 HtmlDivision division = (HtmlDivision) element;
93 assertNotNull( division );
94
95 Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
96
97
98
99
100
101 HtmlSection section = (HtmlSection) elementIterator.next();
102
103 HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
104 assertNotNull( h2 );
105 assertEquals( h2.asText().trim(), "section name with entities: '&' '\u0391' ' ' '\uD835\uDFED'" );
106
107 HtmlAnchor a = (HtmlAnchor) elementIterator.next();
108 assertNotNull( a );
109 assertEquals( "section_name_with_entities:_.27.26.27_.27.CE.91.27_.27.C2.A0.27_.27.3F.3F.27",
110 a.getAttribute( "name" ) );
111
112 section = (HtmlSection) elementIterator.next();
113 assertNotNull( section );
114
115 section = (HtmlSection) elementIterator.next();
116 assertNotNull( section );
117
118 HtmlHeading4 h4 = (HtmlHeading4) elementIterator.next();
119 assertNotNull( h4 );
120 assertEquals( "Entities", h4.asText().trim() );
121
122 a = (HtmlAnchor) elementIterator.next();
123 assertNotNull( a );
124 assertEquals( "Entities", a.getAttribute( "name" ) );
125
126 section = (HtmlSection) elementIterator.next();
127 assertNotNull( section );
128
129 HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
130 assertNotNull( h3 );
131 assertEquals( "Generic Entities: '&' '<' '>' '\"' '''", h3.asText().trim() );
132
133 a = (HtmlAnchor) elementIterator.next();
134
135 HtmlParagraph p = (HtmlParagraph) elementIterator.next();
136 assertNotNull( p );
137 assertEquals( "'&' '<' '>' '\"' '''", p.asText().trim() );
138
139 section = (HtmlSection) elementIterator.next();
140 assertNotNull( section );
141
142 h3 = (HtmlHeading3) elementIterator.next();
143 assertNotNull( h3 );
144 assertEquals( "Local Entities: '\u0391' '\u0392' '\u0393' '\uD835\uDFED'", h3.asText().trim() );
145
146 a = (HtmlAnchor) elementIterator.next();
147
148 p = (HtmlParagraph) elementIterator.next();
149 assertNotNull( p );
150 assertEquals( "'\u0391' '\u0392' '\u0393' '\uD835\uDFED\uD835\uDFED' '\u0159\u0159' '\u0159'", p.asText().trim() );
151
152 section = (HtmlSection) elementIterator.next();
153 assertNotNull( section );
154
155 h3 = (HtmlHeading3) elementIterator.next();
156 assertNotNull( h3 );
157 assertEquals( "DTD Entities: ' ' '\u00A1' '\u00A2'", h3.asText().trim() );
158
159 a = (HtmlAnchor) elementIterator.next();
160
161 p = (HtmlParagraph) elementIterator.next();
162 assertNotNull( p );
163 assertEquals( "' ' '\u00A1' '\u00A2'", p.asText().trim() );
164
165 section = (HtmlSection) elementIterator.next();
166 assertNotNull( section );
167
168 h4 = (HtmlHeading4) elementIterator.next();
169 assertNotNull( h4 );
170 assertEquals( "CDATA", h4.asText().trim() );
171
172 a = (HtmlAnchor) elementIterator.next();
173 assertNotNull( a );
174 assertEquals( "CDATA", a.getAttribute( "name" ) );
175
176 HtmlDivision div = (HtmlDivision) elementIterator.next();
177 assertNotNull( div );
178
179 HtmlPreformattedText pre = (HtmlPreformattedText) elementIterator.next();
180 assertNotNull( pre );
181 assertEquals( "<project xmlns:ant=\"jelly:ant\">", pre.asText().trim() );
182
183 p = (HtmlParagraph) elementIterator.next();
184 assertNotNull( p );
185 assertEquals( "' ' '¡'", p.asText().trim() );
186
187 assertFalse( elementIterator.hasNext() );
188 }
189 }