--- /dev/null
+/**\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
--- /dev/null
+/**\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
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
\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
--- /dev/null
+function myFunction() {\r
+ document.getElementById("demo").innerHTML = "Paragraph changed.";\r
+}
\ No newline at end of file
--- /dev/null
+/**\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
--- /dev/null
+/**\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