Increase code coverage for auth misc 49/47249/1
authorSai Gandham <sg481n@att.com>
Fri, 11 May 2018 18:28:13 +0000 (18:28 +0000)
committerSai Gandham <sg481n@att.com>
Fri, 11 May 2018 18:28:34 +0000 (18:28 +0000)
Issue-ID: AAF-129
Change-Id: Ibf8c2895bd19ce6d8aaba07b2d3159f7356a2d66
Signed-off-by: Sai Gandham <sg481n@att.com>
misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java [new file with mode: 0644]
misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java [new file with mode: 0644]
misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java
misc/xgen/sampletest.js [new file with mode: 0644]
misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_DynamicCodeTest.java [new file with mode: 0644]
misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_JSGenTest.java [new file with mode: 0644]

diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java
new file mode 100644 (file)
index 0000000..e3f5492
--- /dev/null
@@ -0,0 +1,62 @@
+/**\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
+\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.powermock.api.mockito.PowerMockito.when;\r
+\r
+import org.apache.log4j.Level;\r
+import org.apache.log4j.Logger;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({ Log4JLogTarget.class, Logger.class })\r
+public class JU_Log4JLogTargetTest {\r
+\r
+       @Mock\r
+       Logger log;\r
+\r
+       @Before\r
+       public void setup() {\r
+               MockitoAnnotations.initMocks(this);\r
+               PowerMockito.mockStatic(Logger.class);\r
+               when(Logger.getLogger("Info")).thenReturn(log);\r
+               when(log.isEnabledFor(Level.DEBUG)).thenReturn(false);\r
+       }\r
+\r
+       @Test\r
+       public void test() throws APIException {\r
+               Log4JLogTarget target = new Log4JLogTarget(null, Level.INFO);\r
+               Log4JLogTarget target1 = new Log4JLogTarget("Info", Level.DEBUG);\r
+\r
+               assertFalse(target1.isLoggable());\r
+\r
+       }\r
+}
\ No newline at end of file
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java
new file mode 100644 (file)
index 0000000..ce2245b
--- /dev/null
@@ -0,0 +1,56 @@
+/**\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
+\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Test;\r
+\r
+public class JU_SplitTest {\r
+\r
+       @Test\r
+       public void testSplit() {\r
+               String[] splits = Split.split('c', "character c to break string");\r
+\r
+               assertEquals(splits.length, 4);\r
+               assertEquals(splits[0], "");\r
+               assertEquals(splits[1], "hara");\r
+               assertEquals(splits[2], "ter ");\r
+               assertEquals(splits[3], " to break string");\r
+       }\r
+\r
+       @Test\r
+       public void testSplitTrim() {\r
+               String[] splits = Split.splitTrim('c', "character c to break string", 5);\r
+\r
+               assertEquals(splits.length, 5);\r
+               assertEquals(splits[0], "");\r
+               assertEquals(splits[1], "hara");\r
+               assertEquals(splits[2], "ter");\r
+               assertEquals(splits[3], "to break string");\r
+               assertEquals(splits[4], null);\r
+\r
+               splits = Split.splitTrim('c', " character ", 1);\r
+               assertEquals(splits.length, 1);\r
+               assertEquals(splits[0], "character");\r
+       }\r
+}\r
index e3f90de..11f03d5 100644 (file)
@@ -60,6 +60,8 @@ public class JU_PoolTest {
                                content = t;\r
                        }\r
                });\r
+               Pool.Pooled<Integer> pooled = new Pool.Pooled<Integer>(new Integer(123), pool, LogTarget.SYSOUT);\r
+               Pool.Pooled<Integer> pooled1 = new Pool.Pooled<Integer>(new Integer(123), null, LogTarget.SYSOUT);\r
                try {\r
                        // pool.drain();\r
                        assertEquals("Should return intial value", 0, pool.get().content);\r
@@ -74,8 +76,11 @@ public class JU_PoolTest {
 \r
                        pool.drain();\r
                        assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content);\r
+                       pool.setMaxRange(10);\r
+                       assertEquals(10, pool.getMaxRange());\r
+                       pooled.toss();\r
+                       pooled1.toss();\r
                } catch (APIException e) {\r
                }\r
        }\r
-\r
 }\r
diff --git a/misc/xgen/sampletest.js b/misc/xgen/sampletest.js
new file mode 100644 (file)
index 0000000..dc19fa1
--- /dev/null
@@ -0,0 +1,3 @@
+function myFunction() {\r
+       document.getElementById("demo").innerHTML = "Paragraph changed.";\r
+}
\ No newline at end of file
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_DynamicCodeTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_DynamicCodeTest.java
new file mode 100644 (file)
index 0000000..5aead07
--- /dev/null
@@ -0,0 +1,65 @@
+/**\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
+\r
+package org.onap.aaf.misc.xgen;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNull;\r
+\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.Trans;\r
+import org.onap.aaf.misc.xgen.html.HTML4Gen;\r
+import org.onap.aaf.misc.xgen.html.HTMLGen;\r
+import org.onap.aaf.misc.xgen.html.State;\r
+\r
+public class JU_DynamicCodeTest {\r
+\r
+       @Test\r
+       public void test() throws APIException, IOException {\r
+               final Cache<HTMLGen> cache1 = new Cache<HTMLGen>() {\r
+\r
+                       @Override\r
+                       public void dynamic(HTMLGen hgen, Code<HTMLGen> code) {\r
+                       }\r
+               };\r
+\r
+               final HTMLGen xgen1 = new HTML4Gen(new PrintWriter(System.out));\r
+               DynamicCode<HTMLGen, State<Env>, Trans> g = new DynamicCode<HTMLGen, State<Env>, Trans>() {\r
+\r
+                       @Override\r
+                       public void code(State<Env> state, Trans trans, Cache<HTMLGen> cache, HTMLGen xgen)\r
+                                       throws APIException, IOException {\r
+                               assertNull(state);\r
+                               assertNull(trans);\r
+                               assertEquals(cache, cache1);\r
+                               assertEquals(xgen, xgen1);\r
+                       }\r
+               };\r
+\r
+               g.code(cache1, xgen1);\r
+       }\r
+\r
+}\r
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_JSGenTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_JSGenTest.java
new file mode 100644 (file)
index 0000000..8bf811b
--- /dev/null
@@ -0,0 +1,214 @@
+/**\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
+\r
+package org.onap.aaf.misc.xgen.html;\r
+\r
+import static org.junit.Assert.fail;\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.IOException;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.onap.aaf.misc.env.util.IndentPrintWriter;\r
+import org.onap.aaf.misc.xgen.Back;\r
+import org.onap.aaf.misc.xgen.Mark;\r
+\r
+public class JU_JSGenTest {\r
+\r
+       @Mock\r
+       private HTMLGen hg;\r
+       @Mock\r
+       private Mark mark;\r
+       @Mock\r
+       private IndentPrintWriter writer;\r
+       @Mock\r
+       private Mark jm;\r
+\r
+       @Before\r
+       public void setup() {\r
+               MockitoAnnotations.initMocks(this);\r
+       }\r
+\r
+       @Test\r
+       public void testFileNotFoundException() {\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               try {\r
+                       gen.inline("JSScript", 2);\r
+                       fail("This file should not be found.");\r
+               } catch (Exception e) {\r
+\r
+               }\r
+       }\r
+\r
+       @Test\r
+       public void testJSRead() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.inline("./sampletest.js", 2);\r
+\r
+               verify(writer).print("function myFunction() {");\r
+               verify(writer).print("document.getElementById(\"demo\").innerHTML = \"Paragraph changed.\";");\r
+               verify(writer).print("}");\r
+               verify(writer, times(0)).println();\r
+       }\r
+\r
+       @Test\r
+       public void testJSReadPrettyPrint() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               hg.pretty = true;\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.inline("./sampletest.js", 2);\r
+\r
+               verify(writer).print("function myFunction() {");\r
+               verify(writer).print("document.getElementById(\"demo\").innerHTML = \"Paragraph changed.\";");\r
+               verify(writer).print("}");\r
+               verify(writer, times(3)).println();\r
+               verify(hg).setIndent(0);\r
+       }\r
+\r
+       @Test\r
+       public void testPst() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               when(hg.pushBack(any(Back.class))).thenReturn(3);\r
+               hg.pretty = true;\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.pst("line 1", "line 2");\r
+\r
+               verify(writer).append('(');\r
+               verify(writer).append("line 1");\r
+               verify(writer).print("line 2");\r
+               verify(writer, times(1)).print(", ");\r
+       }\r
+\r
+       @Test\r
+       public void testPstWithMark() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               when(hg.pushBack(any(Back.class))).thenReturn(3);\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.pst(jm, "line 1", "line 2");\r
+\r
+               verify(writer).append('(');\r
+               verify(writer).append("line 1");\r
+               verify(writer).print("line 2");\r
+               verify(writer, times(1)).print(", ");\r
+       }\r
+\r
+       @Test\r
+       public void testPstWithNoLines() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               when(hg.pushBack(any(Back.class))).thenReturn(3);\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.pst(jm);\r
+\r
+               verify(writer).append('(');\r
+       }\r
+\r
+       @Test\r
+       public void testLi() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               when(writer.getIndent()).thenReturn(3);\r
+\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.li("line 1", "line 2");\r
+\r
+               verify(writer).setIndent(3);\r
+               verify(writer).inc();\r
+               verify(writer).println();\r
+               verify(writer).print("line 1");\r
+               verify(writer).print("line 2");\r
+\r
+               hg.pretty = true;\r
+               gen.li("line 1", "line 2");\r
+               verify(writer, times(3)).println();\r
+       }\r
+\r
+       @Test\r
+       public void testText() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               hg.pretty = true;\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.text("line 1");\r
+\r
+               verify(writer).append("line 1");\r
+               verify(writer).println();\r
+\r
+               hg.pretty = false;\r
+               gen.text("line 1");\r
+\r
+               verify(writer, times(2)).append("line 1");\r
+       }\r
+\r
+       @Test\r
+       public void testFunction() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               when(hg.pushBack(any(Back.class))).thenReturn(3);\r
+               hg.pretty = true;\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.function("line 1", "line 2", "line 3");\r
+\r
+               verify(writer).print("function ");\r
+               verify(writer).print("line 1");\r
+               verify(writer).print('(');\r
+\r
+               verify(writer).print("line 2");\r
+               verify(writer).print("line 3");\r
+               verify(writer, times(1)).print(", ");\r
+               verify(writer).print(") {");\r
+               verify(writer).inc();\r
+               verify(writer).println();\r
+       }\r
+\r
+       @Test\r
+       public void testFunctionWithMark() throws IOException {\r
+               when(hg.getWriter()).thenReturn(writer);\r
+               when(hg.pushBack(any(Back.class))).thenReturn(3);\r
+               JSGen gen = new JSGen(mark, hg);\r
+\r
+               gen.function(jm, "line 1", "line 2", "line 3");\r
+\r
+               verify(writer).print("function ");\r
+               verify(writer).print("line 1");\r
+               verify(writer).print('(');\r
+\r
+               verify(writer).print("line 2");\r
+               verify(writer).print("line 3");\r
+               verify(writer, times(1)).print(", ");\r
+               verify(writer).print(") {");\r
+               verify(writer, times(0)).inc();\r
+               verify(writer, times(0)).println();\r
+       }\r
+\r
+}\r