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.HtmlCode;
25 import com.gargoylesoftware.htmlunit.html.HtmlDivision;
26 import com.gargoylesoftware.htmlunit.html.HtmlElement;
27 import com.gargoylesoftware.htmlunit.html.HtmlHeading2;
28 import com.gargoylesoftware.htmlunit.html.HtmlHeading3;
29 import com.gargoylesoftware.htmlunit.html.HtmlItalic;
30 import com.gargoylesoftware.htmlunit.html.HtmlPage;
31 import com.gargoylesoftware.htmlunit.html.HtmlParagraph;
32 import com.gargoylesoftware.htmlunit.html.HtmlSection;
33 import com.gargoylesoftware.htmlunit.html.HtmlTeletype;
34
35 import java.util.Iterator;
36
37
38
39
40
41
42
43 public class AptVerifier
44 extends AbstractVerifier
45 {
46
47 public void verify( String file )
48 throws Exception
49 {
50 HtmlPage page = htmlPage( file );
51 assertNotNull( page );
52
53 HtmlElement element = page.getHtmlElementById( "contentBox" );
54 assertNotNull( element );
55 HtmlDivision division = (HtmlDivision) element;
56 assertNotNull( division );
57
58 Iterator<HtmlElement> elementIterator = division.getHtmlElementDescendants().iterator();
59
60
61
62
63
64 HtmlSection section = (HtmlSection) elementIterator.next();
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 section = (HtmlSection) elementIterator.next();
109 assertNotNull( section );
110
111 h2 = (HtmlHeading2) elementIterator.next();
112 assertNotNull( h2 );
113
114 assertEquals( "Section formatting: italic bold mono", 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 HtmlCode code = (HtmlCode) elementIterator.next();
128 assertEquals( "code", code.getTagName() );
129 assertEquals( "mono", code.asText().trim() );
130
131 section = (HtmlSection) elementIterator.next();
132 assertNotNull( section );
133
134 HtmlHeading3 h3 = (HtmlHeading3) elementIterator.next();
135 assertNotNull( h3 );
136
137 assertEquals( "SubSection formatting: italic bold mono", 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 code = (HtmlCode) elementIterator.next();
151 assertEquals( "code", code.getTagName() );
152 assertEquals( "mono", code.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 code = (HtmlCode) elementIterator.next();
166 assertEquals( "code", code.getTagName() );
167 assertEquals( "mono", code.asText().trim() );
168
169 section = (HtmlSection) elementIterator.next();
170 assertNotNull( section );
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 section = (HtmlSection) elementIterator.next();
179 assertNotNull( section );
180 }
181 }