changed to unmaintained
[aaf/authz.git] / misc / xgen / src / test / java / org / onap / aaf / misc / xgen / html / JU_HTML5GenTest.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 \r
22 package org.onap.aaf.misc.xgen.html;\r
23 \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
28 \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
33 \r
34 import org.junit.Before;\r
35 import org.junit.Test;\r
36 import org.mockito.Mock;\r
37 \r
38 public class JU_HTML5GenTest {\r
39 \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
42 \r
43     private String charset = "utf-8";\r
44 \r
45     private final String CHARSET_LINE = "<meta charset=\"" + charset + "\">";\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         HTML5Gen gen = new HTML5Gen(w);\r
60 \r
61         gen.html("attributes");\r
62 \r
63         Map<Character, Integer> map = new TreeMap<>();\r
64 \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
68         }\r
69 \r
70         for (char ch : map.keySet()) {\r
71             verify(w, atLeast(map.get(ch))).write(ch);\r
72         }\r
73         verify(w, atLeast(1)).write(anyInt());\r
74     }\r
75 \r
76     @Test\r
77     public void testHead() throws IOException {\r
78 \r
79         HTML5Gen gen = new HTML5Gen(w);\r
80 \r
81         gen.head();\r
82 \r
83         Map<Character, Integer> map = new TreeMap<>();\r
84 \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
88         }\r
89 \r
90         for (char ch : map.keySet()) {\r
91             verify(w, atLeast(map.get(ch))).write(ch);\r
92         }\r
93     }\r
94 \r
95     @Test\r
96     public void testBody() throws IOException {\r
97 \r
98         HTML5Gen gen = new HTML5Gen(w);\r
99 \r
100         gen.body("attributes");\r
101 \r
102         Map<Character, Integer> map = new TreeMap<>();\r
103 \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
107         }\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
111         }\r
112 \r
113         for (char ch : map.keySet()) {\r
114             verify(w, atLeast(map.get(ch))).write(ch);\r
115         }\r
116     }\r
117 \r
118     @Test\r
119     public void testCharSet() throws IOException {\r
120 \r
121         HTML5Gen gen = new HTML5Gen(w);\r
122 \r
123         gen.charset(charset);\r
124 \r
125         Map<Character, Integer> map = new TreeMap<>();\r
126 \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
130         }\r
131 \r
132         for (char ch : map.keySet()) {\r
133             verify(w, atLeast(map.get(ch))).write(ch);\r
134         }\r
135     }\r
136 }\r