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_HTML5GenTest {
\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 charset=\"" + charset + "\">";
\r
51 public void setUp() throws Exception {
\r
53 w = mock(Writer.class);
\r
57 public void testHTML() throws IOException {
\r
59 HTML5Gen gen = new HTML5Gen(w);
\r
61 gen.html("attributes");
\r
63 Map<Character, Integer> map = new TreeMap<>();
\r
65 for (char ch : "html".toCharArray()) {
\r
66 Integer times = map.get(ch);
\r
67 map.put(ch, (times == null ? 0 : times) + 1);
\r
70 for (char ch : map.keySet()) {
\r
71 verify(w, atLeast(map.get(ch))).write(ch);
\r
73 verify(w, atLeast(1)).write(anyInt());
\r
77 public void testHead() throws IOException {
\r
79 HTML5Gen gen = new HTML5Gen(w);
\r
83 Map<Character, Integer> map = new TreeMap<>();
\r
85 for (char ch : "head".toCharArray()) {
\r
86 Integer times = map.get(ch);
\r
87 map.put(ch, (times == null ? 0 : times) + 1);
\r
90 for (char ch : map.keySet()) {
\r
91 verify(w, atLeast(map.get(ch))).write(ch);
\r
96 public void testBody() throws IOException {
\r
98 HTML5Gen gen = new HTML5Gen(w);
\r
100 gen.body("attributes");
\r
102 Map<Character, Integer> map = new TreeMap<>();
\r
104 for (char ch : "body".toCharArray()) {
\r
105 Integer times = map.get(ch);
\r
106 map.put(ch, (times == null ? 0 : times) + 1);
\r
108 for (char ch : "attributes".toCharArray()) {
\r
109 Integer times = map.get(ch);
\r
110 map.put(ch, (times == null ? 0 : times) + 1);
\r
113 for (char ch : map.keySet()) {
\r
114 verify(w, atLeast(map.get(ch))).write(ch);
\r
119 public void testCharSet() throws IOException {
\r
121 HTML5Gen gen = new HTML5Gen(w);
\r
123 gen.charset(charset);
\r
125 Map<Character, Integer> map = new TreeMap<>();
\r
127 for (char ch : CHARSET_LINE.toCharArray()) {
\r
128 Integer times = map.get(ch);
\r
129 map.put(ch, (times == null ? 0 : times) + 1);
\r
132 for (char ch : map.keySet()) {
\r
133 verify(w, atLeast(map.get(ch))).write(ch);
\r