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.HtmlBold;
24 import com.gargoylesoftware.htmlunit.html.HtmlDivision;
25 import com.gargoylesoftware.htmlunit.html.HtmlElement;
26 import com.gargoylesoftware.htmlunit.html.HtmlHeading2;
27 import com.gargoylesoftware.htmlunit.html.HtmlHeading3;
28 import com.gargoylesoftware.htmlunit.html.HtmlItalic;
29 import com.gargoylesoftware.htmlunit.html.HtmlPage;
30 import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
31 import com.gargoylesoftware.htmlunit.html.HtmlTeletype;
32
33 import java.util.Iterator;
34
35
36
37
38
39
40
41
42 public class AptVerifier
43 extends AbstractVerifier
44 {
45
46 public void verify( String file )
47 throws Exception
48 {
49 HtmlPage page = htmlPage( file );
50 assertNotNull( page );
51
52 HtmlElement element = page.getHtmlElementById( "contentBox" );
53 assertNotNull( element );
54 HtmlDivision division = (HtmlDivision) element;
55 assertNotNull( division );
56
57 Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
58
59
60
61
62
63 HtmlDivision div = (HtmlDivision) elementIterator.next();
64 assertEquals( "section", div.getAttribute( "class" ) );
65
66 HtmlHeading2 h2 = (HtmlHeading2) elementIterator.next();
67 assertNotNull( h2 );
68 assertEquals( "Links", h2.asText().trim() );
69
70 HtmlAnchor a = (HtmlAnchor) elementIterator.next();
71 assertEquals( "Links", a.getAttribute( "name" ) );
72
73 HtmlParagraph p = (HtmlParagraph) elementIterator.next();
74 assertNotNull( p );
75
76
77 a = (HtmlAnchor) elementIterator.next();
78 assertEquals( "Anchor", a.getAttribute( "name" ) );
79 a = (HtmlAnchor) elementIterator.next();
80 assertEquals( "cdc.html", a.getAttribute( "name" ) );
81
82 a = (HtmlAnchor) elementIterator.next();
83 assertEquals( "#Anchor", a.getAttribute( "href" ) );
84 a = (HtmlAnchor) elementIterator.next();
85 assertEquals( "#Anchor", a.getAttribute( "href" ) );
86
87 a = (HtmlAnchor) elementIterator.next();
88 assertEquals( "Anchor_with_space", a.getAttribute( "name" ) );
89 a = (HtmlAnchor) elementIterator.next();
90 assertEquals( "#Anchor_with_space", a.getAttribute( "href" ) );
91
92 a = (HtmlAnchor) elementIterator.next();
93 assertEquals( "http://maven.apache.org/", a.getAttribute( "href" ) );
94 assertEquals( "externalLink", a.getAttribute( "class" ) );
95 a = (HtmlAnchor) elementIterator.next();
96 assertEquals( "http://maven.apache.org/", a.getAttribute( "href" ) );
97 assertEquals( "externalLink", a.getAttribute( "class" ) );
98
99
100 a = (HtmlAnchor) elementIterator.next();
101 assertEquals( "./cdc.html", a.getAttribute( "href" ) );
102 a = (HtmlAnchor) elementIterator.next();
103 assertEquals( "#cdc.html", a.getAttribute( "href" ) );
104
105 a = (HtmlAnchor) elementIterator.next();
106 assertEquals( "/index.html", a.getAttribute( "href" ) );
107
108 div = (HtmlDivision) elementIterator.next();
109 assertEquals( "section", div.getAttribute( "class" ) );
110
111 h2 = (HtmlHeading2) elementIterator.next();
112 assertNotNull( h2 );
113
114 assertEquals( "Section formatting: italicboldmono", h2.asText().trim() );
115
116 a = (HtmlAnchor) elementIterator.next();
117 assertEquals( "Section_formatting:_italic_bold_mono", a.getAttribute( "name" ) );
118
119 HtmlItalic italic = (HtmlItalic) elementIterator.next();
120 assertEquals( "i", italic.getTagName() );
121 assertEquals( "italic", italic.asText().trim() );
122
123 HtmlBold bold = (HtmlBold) elementIterator.next();
124 assertEquals( "b", bold.getTagName() );
125 assertEquals( "bold", bold.asText().trim() );
126
127 HtmlTeletype tt = (HtmlTeletype) elementIterator.next();
128 assertEquals( "tt", tt.getTagName() );
129 assertEquals( "mono", tt.asText().trim() );
130
131 div = (HtmlDivision) elementIterator.next();
132 assertEquals( "section", div.getAttribute( "class" ) );
133
134 HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
135 assertNotNull( h3 );
136
137 assertEquals( "SubSection formatting: italicboldmono", h3.asText().trim() );
138
139 a = (HtmlAnchor) elementIterator.next();
140 assertEquals( "SubSection_formatting:_italic_bold_mono", a.getAttribute( "name" ) );
141
142 italic = (HtmlItalic) elementIterator.next();
143 assertEquals( "i", italic.getTagName() );
144 assertEquals( "italic", italic.asText().trim() );
145
146 bold = (HtmlBold) elementIterator.next();
147 assertEquals( "b", bold.getTagName() );
148 assertEquals( "bold", bold.asText().trim() );
149
150 tt = (HtmlTeletype) elementIterator.next();
151 assertEquals( "tt", tt.getTagName() );
152 assertEquals( "mono", tt.asText().trim() );
153
154 p = (HtmlParagraph) elementIterator.next();
155 assertNotNull( p );
156
157 italic = (HtmlItalic) elementIterator.next();
158 assertEquals( "i", italic.getTagName() );
159 assertEquals( "italic", italic.asText().trim() );
160
161 bold = (HtmlBold) elementIterator.next();
162 assertEquals( "b", bold.getTagName() );
163 assertEquals( "bold", bold.asText().trim() );
164
165 tt = (HtmlTeletype) elementIterator.next();
166 assertEquals( "tt", tt.getTagName() );
167 assertEquals( "mono", tt.asText().trim() );
168
169 div = (HtmlDivision) elementIterator.next();
170 assertEquals( "section", div.getAttribute( "class" ) );
171
172 h2 = (HtmlHeading2) elementIterator.next();
173 assertNotNull( h2 );
174 assertEquals( "No Default Anchor in Section Title with Explicit Anchor", h2.asText().trim() );
175 a = (HtmlAnchor) elementIterator.next();
176 assertEquals( "No_Default_Anchor_in_Section_Title_with_Explicit_Anchor", a.getAttribute( "name" ) );
177
178 div = (HtmlDivision) elementIterator.next();
179 assertEquals( "section", div.getAttribute( "class" ) );
180 }
181 }