Adding more testcases to Misc xgen
[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 package org.onap.aaf.misc.xgen.html;\r
22 \r
23 import static org.mockito.Matchers.anyInt;\r
24 import static org.mockito.Mockito.atLeast;\r
25 import static org.mockito.Mockito.mock;\r
26 import static org.mockito.Mockito.verify;\r
27 \r
28 import java.io.IOException;\r
29 import java.io.Writer;\r
30 import java.util.Map;\r
31 import java.util.TreeMap;\r
32 \r
33 import org.junit.Before;\r
34 import org.junit.Test;\r
35 import org.mockito.Mock;\r
36 \r
37 public class JU_HTML4GenTest {\r
38 \r
39         private final static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""\r
40                         + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";\r
41 \r
42         private String charset = "utf-8";\r
43 \r
44         private final String CHARSET_LINE = "<meta http-equiv=\"Content-type\" content=\"text.hml; charset=" + charset\r
45                         + "\">";\r
46 \r
47         @Mock\r
48         Writer w;\r
49 \r
50         @Before\r
51         public void setUp() throws Exception {\r
52 \r
53                 w = mock(Writer.class);\r
54         }\r
55 \r
56         @Test\r
57         public void testHTML() throws IOException {\r
58 \r
59                 HTML4Gen gen = new HTML4Gen(w);\r
60 \r
61                 gen.html("attributes");\r
62 \r
63                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
64                 for (char ch : DOCTYPE.toCharArray()) {\r
65                         Integer times = map.get(ch);\r
66                         map.put(ch, (times == null ? 0 : times) + 1);\r
67                 }\r
68 \r
69                 for (char ch : "html".toCharArray()) {\r
70                         Integer times = map.get(ch);\r
71                         map.put(ch, (times == null ? 0 : times) + 1);\r
72                 }\r
73 \r
74                 for (char ch : map.keySet()) {\r
75                         verify(w, atLeast(map.get(ch))).write(ch);\r
76                 }\r
77                 verify(w, atLeast(1)).write(anyInt());\r
78         }\r
79 \r
80         @Test\r
81         public void testHead() throws IOException {\r
82 \r
83                 HTML4Gen gen = new HTML4Gen(w);\r
84 \r
85                 gen.head();\r
86 \r
87                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
88 \r
89                 for (char ch : "head".toCharArray()) {\r
90                         Integer times = map.get(ch);\r
91                         map.put(ch, (times == null ? 0 : times) + 1);\r
92                 }\r
93 \r
94                 for (char ch : map.keySet()) {\r
95                         verify(w, atLeast(map.get(ch))).write(ch);\r
96                 }\r
97         }\r
98 \r
99         @Test\r
100         public void testBody() throws IOException {\r
101 \r
102                 HTML4Gen gen = new HTML4Gen(w);\r
103 \r
104                 gen.body("attributes");\r
105 \r
106                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
107 \r
108                 for (char ch : "body".toCharArray()) {\r
109                         Integer times = map.get(ch);\r
110                         map.put(ch, (times == null ? 0 : times) + 1);\r
111                 }\r
112                 for (char ch : "attributes".toCharArray()) {\r
113                         Integer times = map.get(ch);\r
114                         map.put(ch, (times == null ? 0 : times) + 1);\r
115                 }\r
116 \r
117                 for (char ch : map.keySet()) {\r
118                         verify(w, atLeast(map.get(ch))).write(ch);\r
119                 }\r
120         }\r
121 \r
122         @Test\r
123         public void testCharSet() throws IOException {\r
124 \r
125                 HTML4Gen gen = new HTML4Gen(w);\r
126 \r
127                 gen.charset(charset);\r
128 \r
129                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
130 \r
131                 for (char ch : CHARSET_LINE.toCharArray()) {\r
132                         Integer times = map.get(ch);\r
133                         map.put(ch, (times == null ? 0 : times) + 1);\r
134                 }\r
135 \r
136                 for (char ch : map.keySet()) {\r
137                         verify(w, atLeast(map.get(ch))).write(ch);\r
138                 }\r
139         }\r
140 \r
141         @Test\r
142         public void testHeader() throws IOException {\r
143 \r
144                 HTML4Gen gen = new HTML4Gen(w);\r
145 \r
146                 gen.header("attributes");\r
147 \r
148                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
149 \r
150                 for (char ch : "header".toCharArray()) {\r
151                         Integer times = map.get(ch);\r
152                         map.put(ch, (times == null ? 0 : times) + 1);\r
153                 }\r
154 \r
155                 for (char ch : "div".toCharArray()) {\r
156                         Integer times = map.get(ch);\r
157                         map.put(ch, (times == null ? 0 : times) + 1);\r
158                 }\r
159 \r
160                 for (char ch : "attributes".toCharArray()) {\r
161                         Integer times = map.get(ch);\r
162                         map.put(ch, (times == null ? 0 : times) + 1);\r
163                 }\r
164 \r
165                 for (char ch : map.keySet()) {\r
166                         verify(w, atLeast(map.get(ch))).write(ch);\r
167                 }\r
168         }\r
169 \r
170         @Test\r
171         public void testFooter() throws IOException {\r
172 \r
173                 HTML4Gen gen = new HTML4Gen(w);\r
174 \r
175                 gen.footer("attributes");\r
176 \r
177                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
178 \r
179                 for (char ch : "footer".toCharArray()) {\r
180                         Integer times = map.get(ch);\r
181                         map.put(ch, (times == null ? 0 : times) + 1);\r
182                 }\r
183 \r
184                 for (char ch : "div".toCharArray()) {\r
185                         Integer times = map.get(ch);\r
186                         map.put(ch, (times == null ? 0 : times) + 1);\r
187                 }\r
188 \r
189                 for (char ch : "attributes".toCharArray()) {\r
190                         Integer times = map.get(ch);\r
191                         map.put(ch, (times == null ? 0 : times) + 1);\r
192                 }\r
193 \r
194                 for (char ch : map.keySet()) {\r
195                         verify(w, atLeast(map.get(ch))).write(ch);\r
196                 }\r
197         }\r
198 \r
199         @Test\r
200         public void testSection() throws IOException {\r
201 \r
202                 HTML4Gen gen = new HTML4Gen(w);\r
203 \r
204                 gen.section("attributes");\r
205 \r
206                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
207 \r
208                 for (char ch : "section".toCharArray()) {\r
209                         Integer times = map.get(ch);\r
210                         map.put(ch, (times == null ? 0 : times) + 1);\r
211                 }\r
212 \r
213                 for (char ch : "div".toCharArray()) {\r
214                         Integer times = map.get(ch);\r
215                         map.put(ch, (times == null ? 0 : times) + 1);\r
216                 }\r
217 \r
218                 for (char ch : "attributes".toCharArray()) {\r
219                         Integer times = map.get(ch);\r
220                         map.put(ch, (times == null ? 0 : times) + 1);\r
221                 }\r
222 \r
223                 for (char ch : map.keySet()) {\r
224                         verify(w, atLeast(map.get(ch))).write(ch);\r
225                 }\r
226         }\r
227 \r
228         @Test\r
229         public void testArticle() throws IOException {\r
230 \r
231                 HTML4Gen gen = new HTML4Gen(w);\r
232 \r
233                 gen.article("attributes");\r
234 \r
235                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
236 \r
237                 for (char ch : "attrib".toCharArray()) {\r
238                         Integer times = map.get(ch);\r
239                         map.put(ch, (times == null ? 0 : times) + 1);\r
240                 }\r
241 \r
242                 for (char ch : "div".toCharArray()) {\r
243                         Integer times = map.get(ch);\r
244                         map.put(ch, (times == null ? 0 : times) + 1);\r
245                 }\r
246 \r
247                 for (char ch : "attributes".toCharArray()) {\r
248                         Integer times = map.get(ch);\r
249                         map.put(ch, (times == null ? 0 : times) + 1);\r
250                 }\r
251 \r
252                 for (char ch : map.keySet()) {\r
253                         verify(w, atLeast(map.get(ch))).write(ch);\r
254                 }\r
255         }\r
256 \r
257         @Test\r
258         public void testAside() throws IOException {\r
259 \r
260                 HTML4Gen gen = new HTML4Gen(w);\r
261 \r
262                 gen.aside("attributes");\r
263 \r
264                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
265 \r
266                 for (char ch : "aside".toCharArray()) {\r
267                         Integer times = map.get(ch);\r
268                         map.put(ch, (times == null ? 0 : times) + 1);\r
269                 }\r
270 \r
271                 for (char ch : "div".toCharArray()) {\r
272                         Integer times = map.get(ch);\r
273                         map.put(ch, (times == null ? 0 : times) + 1);\r
274                 }\r
275 \r
276                 for (char ch : "attributes".toCharArray()) {\r
277                         Integer times = map.get(ch);\r
278                         map.put(ch, (times == null ? 0 : times) + 1);\r
279                 }\r
280 \r
281                 for (char ch : map.keySet()) {\r
282                         verify(w, atLeast(map.get(ch))).write(ch);\r
283                 }\r
284         }\r
285 \r
286         @Test\r
287         public void testNav() throws IOException {\r
288 \r
289                 HTML4Gen gen = new HTML4Gen(w);\r
290 \r
291                 gen.nav("attributes");\r
292 \r
293                 Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
294 \r
295                 for (char ch : "nav".toCharArray()) {\r
296                         Integer times = map.get(ch);\r
297                         map.put(ch, (times == null ? 0 : times) + 1);\r
298                 }\r
299 \r
300                 for (char ch : "div".toCharArray()) {\r
301                         Integer times = map.get(ch);\r
302                         map.put(ch, (times == null ? 0 : times) + 1);\r
303                 }\r
304 \r
305                 for (char ch : "attributes".toCharArray()) {\r
306                         Integer times = map.get(ch);\r
307                         map.put(ch, (times == null ? 0 : times) + 1);\r
308                 }\r
309 \r
310                 for (char ch : map.keySet()) {\r
311                         verify(w, atLeast(map.get(ch))).write(ch);\r
312                 }\r
313         }\r
314 \r
315 }\r