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