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
21 package org.onap.aaf.misc.xgen.html;
\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
28 import java.io.IOException;
\r
29 import java.io.Writer;
\r
30 import java.util.Map;
\r
31 import java.util.TreeMap;
\r
33 import org.junit.Before;
\r
34 import org.junit.Test;
\r
35 import org.mockito.Mock;
\r
37 public class JU_HTML4GenTest {
\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
42 private String charset = "utf-8";
\r
44 private final String CHARSET_LINE = "<meta http-equiv=\"Content-type\" content=\"text.hml; charset=" + charset
\r
51 public void setUp() throws Exception {
\r
53 w = mock(Writer.class);
\r
57 public void testHTML() throws IOException {
\r
59 HTML4Gen gen = new HTML4Gen(w);
\r
61 gen.html("attributes");
\r
63 Map<Character, Integer> map = new TreeMap<>();
\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
69 for (char ch : "html".toCharArray()) {
\r
70 Integer times = map.get(ch);
\r
71 map.put(ch, (times == null ? 0 : times) + 1);
\r
74 for (char ch : map.keySet()) {
\r
75 verify(w, atLeast(map.get(ch))).write(ch);
\r
77 verify(w, atLeast(1)).write(anyInt());
\r
81 public void testHead() throws IOException {
\r
83 HTML4Gen gen = new HTML4Gen(w);
\r
87 Map<Character, Integer> map = new TreeMap<>();
\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
94 for (char ch : map.keySet()) {
\r
95 verify(w, atLeast(map.get(ch))).write(ch);
\r
100 public void testBody() throws IOException {
\r
102 HTML4Gen gen = new HTML4Gen(w);
\r
104 gen.body("attributes");
\r
106 Map<Character, Integer> map = new TreeMap<>();
\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
112 for (char ch : "attributes".toCharArray()) {
\r
113 Integer times = map.get(ch);
\r
114 map.put(ch, (times == null ? 0 : times) + 1);
\r
117 for (char ch : map.keySet()) {
\r
118 verify(w, atLeast(map.get(ch))).write(ch);
\r
123 public void testCharSet() throws IOException {
\r
125 HTML4Gen gen = new HTML4Gen(w);
\r
127 gen.charset(charset);
\r
129 Map<Character, Integer> map = new TreeMap<>();
\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
136 for (char ch : map.keySet()) {
\r
137 verify(w, atLeast(map.get(ch))).write(ch);
\r
142 public void testHeader() throws IOException {
\r
144 HTML4Gen gen = new HTML4Gen(w);
\r
146 gen.header("attributes");
\r
148 Map<Character, Integer> map = new TreeMap<>();
\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
155 for (char ch : "div".toCharArray()) {
\r
156 Integer times = map.get(ch);
\r
157 map.put(ch, (times == null ? 0 : times) + 1);
\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
165 for (char ch : map.keySet()) {
\r
166 verify(w, atLeast(map.get(ch))).write(ch);
\r
171 public void testFooter() throws IOException {
\r
173 HTML4Gen gen = new HTML4Gen(w);
\r
175 gen.footer("attributes");
\r
177 Map<Character, Integer> map = new TreeMap<>();
\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
184 for (char ch : "div".toCharArray()) {
\r
185 Integer times = map.get(ch);
\r
186 map.put(ch, (times == null ? 0 : times) + 1);
\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
194 for (char ch : map.keySet()) {
\r
195 verify(w, atLeast(map.get(ch))).write(ch);
\r
200 public void testSection() throws IOException {
\r
202 HTML4Gen gen = new HTML4Gen(w);
\r
204 gen.section("attributes");
\r
206 Map<Character, Integer> map = new TreeMap<>();
\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
213 for (char ch : "div".toCharArray()) {
\r
214 Integer times = map.get(ch);
\r
215 map.put(ch, (times == null ? 0 : times) + 1);
\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
223 for (char ch : map.keySet()) {
\r
224 verify(w, atLeast(map.get(ch))).write(ch);
\r
229 public void testArticle() throws IOException {
\r
231 HTML4Gen gen = new HTML4Gen(w);
\r
233 gen.article("attributes");
\r
235 Map<Character, Integer> map = new TreeMap<>();
\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
242 for (char ch : "div".toCharArray()) {
\r
243 Integer times = map.get(ch);
\r
244 map.put(ch, (times == null ? 0 : times) + 1);
\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
252 for (char ch : map.keySet()) {
\r
253 verify(w, atLeast(map.get(ch))).write(ch);
\r
258 public void testAside() throws IOException {
\r
260 HTML4Gen gen = new HTML4Gen(w);
\r
262 gen.aside("attributes");
\r
264 Map<Character, Integer> map = new TreeMap<>();
\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
271 for (char ch : "div".toCharArray()) {
\r
272 Integer times = map.get(ch);
\r
273 map.put(ch, (times == null ? 0 : times) + 1);
\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
281 for (char ch : map.keySet()) {
\r
282 verify(w, atLeast(map.get(ch))).write(ch);
\r
287 public void testNav() throws IOException {
\r
289 HTML4Gen gen = new HTML4Gen(w);
\r
291 gen.nav("attributes");
\r
293 Map<Character, Integer> map = new TreeMap<>();
\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
300 for (char ch : "div".toCharArray()) {
\r
301 Integer times = map.get(ch);
\r
302 map.put(ch, (times == null ? 0 : times) + 1);
\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
310 for (char ch : map.keySet()) {
\r
311 verify(w, atLeast(map.get(ch))).write(ch);
\r