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_HTML5GenTest {
\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 charset=\"" + charset + "\">";
\r
50 public void setUp() throws Exception {
\r
52 w = mock(Writer.class);
\r
56 public void testHTML() throws IOException {
\r
58 HTML5Gen gen = new HTML5Gen(w);
\r
60 gen.html("attributes");
\r
62 Map<Character, Integer> map = new TreeMap<>();
\r
64 for (char ch : "html".toCharArray()) {
\r
65 Integer times = map.get(ch);
\r
66 map.put(ch, (times == null ? 0 : times) + 1);
\r
69 for (char ch : map.keySet()) {
\r
70 verify(w, atLeast(map.get(ch))).write(ch);
\r
72 verify(w, atLeast(1)).write(anyInt());
\r
76 public void testHead() throws IOException {
\r
78 HTML5Gen gen = new HTML5Gen(w);
\r
82 Map<Character, Integer> map = new TreeMap<>();
\r
84 for (char ch : "head".toCharArray()) {
\r
85 Integer times = map.get(ch);
\r
86 map.put(ch, (times == null ? 0 : times) + 1);
\r
89 for (char ch : map.keySet()) {
\r
90 verify(w, atLeast(map.get(ch))).write(ch);
\r
95 public void testBody() throws IOException {
\r
97 HTML5Gen gen = new HTML5Gen(w);
\r
99 gen.body("attributes");
\r
101 Map<Character, Integer> map = new TreeMap<>();
\r
103 for (char ch : "body".toCharArray()) {
\r
104 Integer times = map.get(ch);
\r
105 map.put(ch, (times == null ? 0 : times) + 1);
\r
107 for (char ch : "attributes".toCharArray()) {
\r
108 Integer times = map.get(ch);
\r
109 map.put(ch, (times == null ? 0 : times) + 1);
\r
112 for (char ch : map.keySet()) {
\r
113 verify(w, atLeast(map.get(ch))).write(ch);
\r
118 public void testCharSet() throws IOException {
\r
120 HTML5Gen gen = new HTML5Gen(w);
\r
122 gen.charset(charset);
\r
124 Map<Character, Integer> map = new TreeMap<>();
\r
126 for (char ch : CHARSET_LINE.toCharArray()) {
\r
127 Integer times = map.get(ch);
\r
128 map.put(ch, (times == null ? 0 : times) + 1);
\r
131 for (char ch : map.keySet()) {
\r
132 verify(w, atLeast(map.get(ch))).write(ch);
\r