2 * ============LICENSE_START====================================================
\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
11 * http://www.apache.org/licenses/LICENSE-2.0
\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
22 package org.onap.aaf.misc.xgen.html;
\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
29 import java.io.IOException;
\r
30 import java.io.Writer;
\r
31 import java.util.Map;
\r
32 import java.util.TreeMap;
\r
34 import org.junit.Before;
\r
35 import org.junit.Test;
\r
36 import org.mockito.Mock;
\r
38 public class JU_HTML4GenTest {
\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
43 private String charset = "utf-8";
\r
45 private final String CHARSET_LINE = "<meta http-equiv=\"Content-type\" content=\"text.hml; charset=" + charset
\r
52 public void setUp() throws Exception {
\r
54 w = mock(Writer.class);
\r
58 public void testHTML() throws IOException {
\r
60 HTML4Gen gen = new HTML4Gen(w);
\r
62 gen.html("attributes");
\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
70 for (char ch : "html".toCharArray()) {
\r
71 Integer times = map.get(ch);
\r
72 map.put(ch, (times == null ? 0 : times) + 1);
\r
75 for (char ch : map.keySet()) {
\r
76 verify(w, atLeast(map.get(ch))).write(ch);
\r
78 verify(w, atLeast(1)).write(anyInt());
\r
82 public void testHead() throws IOException {
\r
84 HTML4Gen gen = new HTML4Gen(w);
\r
88 Map<Character, Integer> map = new TreeMap<>();
\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
95 for (char ch : map.keySet()) {
\r
96 verify(w, atLeast(map.get(ch))).write(ch);
\r
101 public void testBody() throws IOException {
\r
103 HTML4Gen gen = new HTML4Gen(w);
\r
105 gen.body("attributes");
\r
107 Map<Character, Integer> map = new TreeMap<>();
\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
113 for (char ch : "attributes".toCharArray()) {
\r
114 Integer times = map.get(ch);
\r
115 map.put(ch, (times == null ? 0 : times) + 1);
\r
118 for (char ch : map.keySet()) {
\r
119 verify(w, atLeast(map.get(ch))).write(ch);
\r
124 public void testCharSet() throws IOException {
\r
126 HTML4Gen gen = new HTML4Gen(w);
\r
128 gen.charset(charset);
\r
130 Map<Character, Integer> map = new TreeMap<>();
\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
137 for (char ch : map.keySet()) {
\r
138 verify(w, atLeast(map.get(ch))).write(ch);
\r
143 public void testHeader() throws IOException {
\r
145 HTML4Gen gen = new HTML4Gen(w);
\r
147 gen.header("attributes");
\r
149 Map<Character, Integer> map = new TreeMap<>();
\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
156 for (char ch : "div".toCharArray()) {
\r
157 Integer times = map.get(ch);
\r
158 map.put(ch, (times == null ? 0 : times) + 1);
\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
166 for (char ch : map.keySet()) {
\r
167 verify(w, atLeast(map.get(ch))).write(ch);
\r
172 public void testFooter() throws IOException {
\r
174 HTML4Gen gen = new HTML4Gen(w);
\r
176 gen.footer("attributes");
\r
178 Map<Character, Integer> map = new TreeMap<>();
\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
185 for (char ch : "div".toCharArray()) {
\r
186 Integer times = map.get(ch);
\r
187 map.put(ch, (times == null ? 0 : times) + 1);
\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
195 for (char ch : map.keySet()) {
\r
196 verify(w, atLeast(map.get(ch))).write(ch);
\r
201 public void testSection() throws IOException {
\r
203 HTML4Gen gen = new HTML4Gen(w);
\r
205 gen.section("attributes");
\r
207 Map<Character, Integer> map = new TreeMap<>();
\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
214 for (char ch : "div".toCharArray()) {
\r
215 Integer times = map.get(ch);
\r
216 map.put(ch, (times == null ? 0 : times) + 1);
\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
224 for (char ch : map.keySet()) {
\r
225 verify(w, atLeast(map.get(ch))).write(ch);
\r
230 public void testArticle() throws IOException {
\r
232 HTML4Gen gen = new HTML4Gen(w);
\r
234 gen.article("attributes");
\r
236 Map<Character, Integer> map = new TreeMap<>();
\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
243 for (char ch : "div".toCharArray()) {
\r
244 Integer times = map.get(ch);
\r
245 map.put(ch, (times == null ? 0 : times) + 1);
\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
253 for (char ch : map.keySet()) {
\r
254 verify(w, atLeast(map.get(ch))).write(ch);
\r
259 public void testAside() throws IOException {
\r
261 HTML4Gen gen = new HTML4Gen(w);
\r
263 gen.aside("attributes");
\r
265 Map<Character, Integer> map = new TreeMap<>();
\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
272 for (char ch : "div".toCharArray()) {
\r
273 Integer times = map.get(ch);
\r
274 map.put(ch, (times == null ? 0 : times) + 1);
\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
282 for (char ch : map.keySet()) {
\r
283 verify(w, atLeast(map.get(ch))).write(ch);
\r
288 public void testNav() throws IOException {
\r
290 HTML4Gen gen = new HTML4Gen(w);
\r
292 gen.nav("attributes");
\r
294 Map<Character, Integer> map = new TreeMap<>();
\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
301 for (char ch : "div".toCharArray()) {
\r
302 Integer times = map.get(ch);
\r
303 map.put(ch, (times == null ? 0 : times) + 1);
\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
311 for (char ch : map.keySet()) {
\r
312 verify(w, atLeast(map.get(ch))).write(ch);
\r