Mass add newline package (Style Warnings)
[aaf/authz.git] / misc / xgen / src / test / java / org / onap / aaf / misc / xgen / html / JU_HTML4GenTest.java
1 /**\r
2  * ============LICENSE_START====================================================\r
3  * org.onap.aaf\r
4  * ===========================================================================\r
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
6  * ===========================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END====================================================\r
19  *\r
20  */\r
21 \r
22 package org.onap.aaf.misc.xgen.html;\r
23 \r
24 import static org.mockito.Matchers.anyInt;\r
25 import static org.mockito.Mockito.atLeast;\r
26 import static org.mockito.Mockito.mock;\r
27 import static org.mockito.Mockito.verify;\r
28 \r
29 import java.io.IOException;\r
30 import java.io.Writer;\r
31 import java.util.Map;\r
32 import java.util.TreeMap;\r
33 \r
34 import org.junit.Before;\r
35 import org.junit.Test;\r
36 import org.mockito.Mock;\r
37 \r
38 public class JU_HTML4GenTest {\r
39 \r
40     private final static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""\r
41             + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";\r
42 \r
43     private String charset = "utf-8";\r
44 \r
45     private final String CHARSET_LINE = "<meta http-equiv=\"Content-type\" content=\"text.hml; charset=" + charset\r
46             + "\">";\r
47 \r
48     @Mock\r
49     Writer w;\r
50 \r
51     @Before\r
52     public void setUp() throws Exception {\r
53 \r
54         w = mock(Writer.class);\r
55     }\r
56 \r
57     @Test\r
58     public void testHTML() throws IOException {\r
59 \r
60         HTML4Gen gen = new HTML4Gen(w);\r
61 \r
62         gen.html("attributes");\r
63 \r
64         Map<Character, Integer> map = new TreeMap<>();\r
65         for (char ch : DOCTYPE.toCharArray()) {\r
66             Integer times = map.get(ch);\r
67             map.put(ch, (times == null ? 0 : times) + 1);\r
68         }\r
69 \r
70         for (char ch : "html".toCharArray()) {\r
71             Integer times = map.get(ch);\r
72             map.put(ch, (times == null ? 0 : times) + 1);\r
73         }\r
74 \r
75         for (char ch : map.keySet()) {\r
76             verify(w, atLeast(map.get(ch))).write(ch);\r
77         }\r
78         verify(w, atLeast(1)).write(anyInt());\r
79     }\r
80 \r
81     @Test\r
82     public void testHead() throws IOException {\r
83 \r
84         HTML4Gen gen = new HTML4Gen(w);\r
85 \r
86         gen.head();\r
87 \r
88         Map<Character, Integer> map = new TreeMap<>();\r
89 \r
90         for (char ch : "head".toCharArray()) {\r
91             Integer times = map.get(ch);\r
92             map.put(ch, (times == null ? 0 : times) + 1);\r
93         }\r
94 \r
95         for (char ch : map.keySet()) {\r
96             verify(w, atLeast(map.get(ch))).write(ch);\r
97         }\r
98     }\r
99 \r
100     @Test\r
101     public void testBody() throws IOException {\r
102 \r
103         HTML4Gen gen = new HTML4Gen(w);\r
104 \r
105         gen.body("attributes");\r
106 \r
107         Map<Character, Integer> map = new TreeMap<>();\r
108 \r
109         for (char ch : "body".toCharArray()) {\r
110             Integer times = map.get(ch);\r
111             map.put(ch, (times == null ? 0 : times) + 1);\r
112         }\r
113         for (char ch : "attributes".toCharArray()) {\r
114             Integer times = map.get(ch);\r
115             map.put(ch, (times == null ? 0 : times) + 1);\r
116         }\r
117 \r
118         for (char ch : map.keySet()) {\r
119             verify(w, atLeast(map.get(ch))).write(ch);\r
120         }\r
121     }\r
122 \r
123     @Test\r
124     public void testCharSet() throws IOException {\r
125 \r
126         HTML4Gen gen = new HTML4Gen(w);\r
127 \r
128         gen.charset(charset);\r
129 \r
130         Map<Character, Integer> map = new TreeMap<>();\r
131 \r
132         for (char ch : CHARSET_LINE.toCharArray()) {\r
133             Integer times = map.get(ch);\r
134             map.put(ch, (times == null ? 0 : times) + 1);\r
135         }\r
136 \r
137         for (char ch : map.keySet()) {\r
138             verify(w, atLeast(map.get(ch))).write(ch);\r
139         }\r
140     }\r
141 \r
142     @Test\r
143     public void testHeader() throws IOException {\r
144 \r
145         HTML4Gen gen = new HTML4Gen(w);\r
146 \r
147         gen.header("attributes");\r
148 \r
149         Map<Character, Integer> map = new TreeMap<>();\r
150 \r
151         for (char ch : "header".toCharArray()) {\r
152             Integer times = map.get(ch);\r
153             map.put(ch, (times == null ? 0 : times) + 1);\r
154         }\r
155 \r
156         for (char ch : "div".toCharArray()) {\r
157             Integer times = map.get(ch);\r
158             map.put(ch, (times == null ? 0 : times) + 1);\r
159         }\r
160 \r
161         for (char ch : "attributes".toCharArray()) {\r
162             Integer times = map.get(ch);\r
163             map.put(ch, (times == null ? 0 : times) + 1);\r
164         }\r
165 \r
166         for (char ch : map.keySet()) {\r
167             verify(w, atLeast(map.get(ch))).write(ch);\r
168         }\r
169     }\r
170 \r
171     @Test\r
172     public void testFooter() throws IOException {\r
173 \r
174         HTML4Gen gen = new HTML4Gen(w);\r
175 \r
176         gen.footer("attributes");\r
177 \r
178         Map<Character, Integer> map = new TreeMap<>();\r
179 \r
180         for (char ch : "footer".toCharArray()) {\r
181             Integer times = map.get(ch);\r
182             map.put(ch, (times == null ? 0 : times) + 1);\r
183         }\r
184 \r
185         for (char ch : "div".toCharArray()) {\r
186             Integer times = map.get(ch);\r
187             map.put(ch, (times == null ? 0 : times) + 1);\r
188         }\r
189 \r
190         for (char ch : "attributes".toCharArray()) {\r
191             Integer times = map.get(ch);\r
192             map.put(ch, (times == null ? 0 : times) + 1);\r
193         }\r
194 \r
195         for (char ch : map.keySet()) {\r
196             verify(w, atLeast(map.get(ch))).write(ch);\r
197         }\r
198     }\r
199 \r
200     @Test\r
201     public void testSection() throws IOException {\r
202 \r
203         HTML4Gen gen = new HTML4Gen(w);\r
204 \r
205         gen.section("attributes");\r
206 \r
207         Map<Character, Integer> map = new TreeMap<>();\r
208 \r
209         for (char ch : "section".toCharArray()) {\r
210             Integer times = map.get(ch);\r
211             map.put(ch, (times == null ? 0 : times) + 1);\r
212         }\r
213 \r
214         for (char ch : "div".toCharArray()) {\r
215             Integer times = map.get(ch);\r
216             map.put(ch, (times == null ? 0 : times) + 1);\r
217         }\r
218 \r
219         for (char ch : "attributes".toCharArray()) {\r
220             Integer times = map.get(ch);\r
221             map.put(ch, (times == null ? 0 : times) + 1);\r
222         }\r
223 \r
224         for (char ch : map.keySet()) {\r
225             verify(w, atLeast(map.get(ch))).write(ch);\r
226         }\r
227     }\r
228 \r
229     @Test\r
230     public void testArticle() throws IOException {\r
231 \r
232         HTML4Gen gen = new HTML4Gen(w);\r
233 \r
234         gen.article("attributes");\r
235 \r
236         Map<Character, Integer> map = new TreeMap<>();\r
237 \r
238         for (char ch : "attrib".toCharArray()) {\r
239             Integer times = map.get(ch);\r
240             map.put(ch, (times == null ? 0 : times) + 1);\r
241         }\r
242 \r
243         for (char ch : "div".toCharArray()) {\r
244             Integer times = map.get(ch);\r
245             map.put(ch, (times == null ? 0 : times) + 1);\r
246         }\r
247 \r
248         for (char ch : "attributes".toCharArray()) {\r
249             Integer times = map.get(ch);\r
250             map.put(ch, (times == null ? 0 : times) + 1);\r
251         }\r
252 \r
253         for (char ch : map.keySet()) {\r
254             verify(w, atLeast(map.get(ch))).write(ch);\r
255         }\r
256     }\r
257 \r
258     @Test\r
259     public void testAside() throws IOException {\r
260 \r
261         HTML4Gen gen = new HTML4Gen(w);\r
262 \r
263         gen.aside("attributes");\r
264 \r
265         Map<Character, Integer> map = new TreeMap<>();\r
266 \r
267         for (char ch : "aside".toCharArray()) {\r
268             Integer times = map.get(ch);\r
269             map.put(ch, (times == null ? 0 : times) + 1);\r
270         }\r
271 \r
272         for (char ch : "div".toCharArray()) {\r
273             Integer times = map.get(ch);\r
274             map.put(ch, (times == null ? 0 : times) + 1);\r
275         }\r
276 \r
277         for (char ch : "attributes".toCharArray()) {\r
278             Integer times = map.get(ch);\r
279             map.put(ch, (times == null ? 0 : times) + 1);\r
280         }\r
281 \r
282         for (char ch : map.keySet()) {\r
283             verify(w, atLeast(map.get(ch))).write(ch);\r
284         }\r
285     }\r
286 \r
287     @Test\r
288     public void testNav() throws IOException {\r
289 \r
290         HTML4Gen gen = new HTML4Gen(w);\r
291 \r
292         gen.nav("attributes");\r
293 \r
294         Map<Character, Integer> map = new TreeMap<>();\r
295 \r
296         for (char ch : "nav".toCharArray()) {\r
297             Integer times = map.get(ch);\r
298             map.put(ch, (times == null ? 0 : times) + 1);\r
299         }\r
300 \r
301         for (char ch : "div".toCharArray()) {\r
302             Integer times = map.get(ch);\r
303             map.put(ch, (times == null ? 0 : times) + 1);\r
304         }\r
305 \r
306         for (char ch : "attributes".toCharArray()) {\r
307             Integer times = map.get(ch);\r
308             map.put(ch, (times == null ? 0 : times) + 1);\r
309         }\r
310 \r
311         for (char ch : map.keySet()) {\r
312             verify(w, atLeast(map.get(ch))).write(ch);\r
313         }\r
314     }\r
315 \r
316 }\r