+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.xgen.html;\r
+\r
+import static org.mockito.Matchers.anyInt;\r
+import static org.mockito.Mockito.atLeast;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.IOException;\r
+import java.io.Writer;\r
+import java.util.Map;\r
+import java.util.TreeMap;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_HTML4GenTest {\r
+\r
+ private final static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""\r
+ + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";\r
+\r
+ private String charset = "utf-8";\r
+\r
+ private final String CHARSET_LINE = "<meta http-equiv=\"Content-type\" content=\"text.hml; charset=" + charset\r
+ + "\">";\r
+\r
+ @Mock\r
+ Writer w;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+\r
+ w = mock(Writer.class);\r
+ }\r
+\r
+ @Test\r
+ public void testHTML() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.html("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+ for (char ch : DOCTYPE.toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "html".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ verify(w, atLeast(1)).write(anyInt());\r
+ }\r
+\r
+ @Test\r
+ public void testHead() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.head();\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "head".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testBody() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.body("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "body".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testCharSet() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.charset(charset);\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : CHARSET_LINE.toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testHeader() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.header("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "header".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "div".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testFooter() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.footer("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "footer".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "div".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testSection() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.section("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "section".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "div".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testArticle() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.article("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "attrib".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "div".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testAside() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.aside("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "aside".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "div".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testNav() throws IOException {\r
+\r
+ HTML4Gen gen = new HTML4Gen(w);\r
+\r
+ gen.nav("attributes");\r
+\r
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();\r
+\r
+ for (char ch : "nav".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "div".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : "attributes".toCharArray()) {\r
+ Integer times = map.get(ch);\r
+ map.put(ch, (times == null ? 0 : times) + 1);\r
+ }\r
+\r
+ for (char ch : map.keySet()) {\r
+ verify(w, atLeast(map.get(ch))).write(ch);\r
+ }\r
+ }\r
+\r
+}\r