summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSai Gandham <sg481n@att.com>2018-05-11 18:28:13 +0000
committerSai Gandham <sg481n@att.com>2018-05-11 18:28:34 +0000
commitd249df5d303d82be6d67340245cae6c2508f6cd6 (patch)
tree5db7ba90e77b82a920d834605d4c1837c4e8504f
parentc486733c0160bfb16bb75a008abe4e6a2616cb44 (diff)
Increase code coverage for auth misc
Issue-ID: AAF-129 Change-Id: Ibf8c2895bd19ce6d8aaba07b2d3159f7356a2d66 Signed-off-by: Sai Gandham <sg481n@att.com>
-rw-r--r--misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java62
-rw-r--r--misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java56
-rw-r--r--misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java7
-rw-r--r--misc/xgen/sampletest.js3
-rw-r--r--misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_DynamicCodeTest.java65
-rw-r--r--misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_JSGenTest.java214
6 files changed, 406 insertions, 1 deletions
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
index 00000000..e3f54929
--- /dev/null
+++ b/misc/env/src/test/java/org/onap/aaf/misc/env/impl/JU_Log4JLogTargetTest.java
@@ -0,0 +1,62 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.misc.env.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.aaf.misc.env.APIException;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ Log4JLogTarget.class, Logger.class })
+public class JU_Log4JLogTargetTest {
+
+ @Mock
+ Logger log;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(Logger.class);
+ when(Logger.getLogger("Info")).thenReturn(log);
+ when(log.isEnabledFor(Level.DEBUG)).thenReturn(false);
+ }
+
+ @Test
+ public void test() throws APIException {
+ Log4JLogTarget target = new Log4JLogTarget(null, Level.INFO);
+ Log4JLogTarget target1 = new Log4JLogTarget("Info", Level.DEBUG);
+
+ assertFalse(target1.isLoggable());
+
+ }
+} \ 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
index 00000000..ce2245bf
--- /dev/null
+++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/JU_SplitTest.java
@@ -0,0 +1,56 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.misc.env.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class JU_SplitTest {
+
+ @Test
+ public void testSplit() {
+ String[] splits = Split.split('c', "character c to break string");
+
+ assertEquals(splits.length, 4);
+ assertEquals(splits[0], "");
+ assertEquals(splits[1], "hara");
+ assertEquals(splits[2], "ter ");
+ assertEquals(splits[3], " to break string");
+ }
+
+ @Test
+ public void testSplitTrim() {
+ String[] splits = Split.splitTrim('c', "character c to break string", 5);
+
+ assertEquals(splits.length, 5);
+ assertEquals(splits[0], "");
+ assertEquals(splits[1], "hara");
+ assertEquals(splits[2], "ter");
+ assertEquals(splits[3], "to break string");
+ assertEquals(splits[4], null);
+
+ splits = Split.splitTrim('c', " character ", 1);
+ assertEquals(splits.length, 1);
+ assertEquals(splits[0], "character");
+ }
+}
diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java
index e3f90de1..11f03d52 100644
--- a/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java
+++ b/misc/env/src/test/java/org/onap/aaf/misc/env/util/test/JU_PoolTest.java
@@ -60,6 +60,8 @@ public class JU_PoolTest {
content = t;
}
});
+ Pool.Pooled<Integer> pooled = new Pool.Pooled<Integer>(new Integer(123), pool, LogTarget.SYSOUT);
+ Pool.Pooled<Integer> pooled1 = new Pool.Pooled<Integer>(new Integer(123), null, LogTarget.SYSOUT);
try {
// pool.drain();
assertEquals("Should return intial value", 0, pool.get().content);
@@ -74,8 +76,11 @@ public class JU_PoolTest {
pool.drain();
assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content);
+ pool.setMaxRange(10);
+ assertEquals(10, pool.getMaxRange());
+ pooled.toss();
+ pooled1.toss();
} catch (APIException e) {
}
}
-
}
diff --git a/misc/xgen/sampletest.js b/misc/xgen/sampletest.js
new file mode 100644
index 00000000..dc19fa1f
--- /dev/null
+++ b/misc/xgen/sampletest.js
@@ -0,0 +1,3 @@
+function myFunction() {
+ document.getElementById("demo").innerHTML = "Paragraph changed.";
+} \ 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
index 00000000..5aead073
--- /dev/null
+++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_DynamicCodeTest.java
@@ -0,0 +1,65 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.misc.xgen;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.junit.Test;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.env.Env;
+import org.onap.aaf.misc.env.Trans;
+import org.onap.aaf.misc.xgen.html.HTML4Gen;
+import org.onap.aaf.misc.xgen.html.HTMLGen;
+import org.onap.aaf.misc.xgen.html.State;
+
+public class JU_DynamicCodeTest {
+
+ @Test
+ public void test() throws APIException, IOException {
+ final Cache<HTMLGen> cache1 = new Cache<HTMLGen>() {
+
+ @Override
+ public void dynamic(HTMLGen hgen, Code<HTMLGen> code) {
+ }
+ };
+
+ final HTMLGen xgen1 = new HTML4Gen(new PrintWriter(System.out));
+ DynamicCode<HTMLGen, State<Env>, Trans> g = new DynamicCode<HTMLGen, State<Env>, Trans>() {
+
+ @Override
+ public void code(State<Env> state, Trans trans, Cache<HTMLGen> cache, HTMLGen xgen)
+ throws APIException, IOException {
+ assertNull(state);
+ assertNull(trans);
+ assertEquals(cache, cache1);
+ assertEquals(xgen, xgen1);
+ }
+ };
+
+ g.code(cache1, xgen1);
+ }
+
+}
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
index 00000000..8bf811be
--- /dev/null
+++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_JSGenTest.java
@@ -0,0 +1,214 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.aaf.misc.xgen.html;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.aaf.misc.env.util.IndentPrintWriter;
+import org.onap.aaf.misc.xgen.Back;
+import org.onap.aaf.misc.xgen.Mark;
+
+public class JU_JSGenTest {
+
+ @Mock
+ private HTMLGen hg;
+ @Mock
+ private Mark mark;
+ @Mock
+ private IndentPrintWriter writer;
+ @Mock
+ private Mark jm;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testFileNotFoundException() {
+ JSGen gen = new JSGen(mark, hg);
+
+ try {
+ gen.inline("JSScript", 2);
+ fail("This file should not be found.");
+ } catch (Exception e) {
+
+ }
+ }
+
+ @Test
+ public void testJSRead() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.inline("./sampletest.js", 2);
+
+ verify(writer).print("function myFunction() {");
+ verify(writer).print("document.getElementById(\"demo\").innerHTML = \"Paragraph changed.\";");
+ verify(writer).print("}");
+ verify(writer, times(0)).println();
+ }
+
+ @Test
+ public void testJSReadPrettyPrint() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ hg.pretty = true;
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.inline("./sampletest.js", 2);
+
+ verify(writer).print("function myFunction() {");
+ verify(writer).print("document.getElementById(\"demo\").innerHTML = \"Paragraph changed.\";");
+ verify(writer).print("}");
+ verify(writer, times(3)).println();
+ verify(hg).setIndent(0);
+ }
+
+ @Test
+ public void testPst() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ when(hg.pushBack(any(Back.class))).thenReturn(3);
+ hg.pretty = true;
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.pst("line 1", "line 2");
+
+ verify(writer).append('(');
+ verify(writer).append("line 1");
+ verify(writer).print("line 2");
+ verify(writer, times(1)).print(", ");
+ }
+
+ @Test
+ public void testPstWithMark() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ when(hg.pushBack(any(Back.class))).thenReturn(3);
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.pst(jm, "line 1", "line 2");
+
+ verify(writer).append('(');
+ verify(writer).append("line 1");
+ verify(writer).print("line 2");
+ verify(writer, times(1)).print(", ");
+ }
+
+ @Test
+ public void testPstWithNoLines() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ when(hg.pushBack(any(Back.class))).thenReturn(3);
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.pst(jm);
+
+ verify(writer).append('(');
+ }
+
+ @Test
+ public void testLi() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ when(writer.getIndent()).thenReturn(3);
+
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.li("line 1", "line 2");
+
+ verify(writer).setIndent(3);
+ verify(writer).inc();
+ verify(writer).println();
+ verify(writer).print("line 1");
+ verify(writer).print("line 2");
+
+ hg.pretty = true;
+ gen.li("line 1", "line 2");
+ verify(writer, times(3)).println();
+ }
+
+ @Test
+ public void testText() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ hg.pretty = true;
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.text("line 1");
+
+ verify(writer).append("line 1");
+ verify(writer).println();
+
+ hg.pretty = false;
+ gen.text("line 1");
+
+ verify(writer, times(2)).append("line 1");
+ }
+
+ @Test
+ public void testFunction() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ when(hg.pushBack(any(Back.class))).thenReturn(3);
+ hg.pretty = true;
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.function("line 1", "line 2", "line 3");
+
+ verify(writer).print("function ");
+ verify(writer).print("line 1");
+ verify(writer).print('(');
+
+ verify(writer).print("line 2");
+ verify(writer).print("line 3");
+ verify(writer, times(1)).print(", ");
+ verify(writer).print(") {");
+ verify(writer).inc();
+ verify(writer).println();
+ }
+
+ @Test
+ public void testFunctionWithMark() throws IOException {
+ when(hg.getWriter()).thenReturn(writer);
+ when(hg.pushBack(any(Back.class))).thenReturn(3);
+ JSGen gen = new JSGen(mark, hg);
+
+ gen.function(jm, "line 1", "line 2", "line 3");
+
+ verify(writer).print("function ");
+ verify(writer).print("line 1");
+ verify(writer).print('(');
+
+ verify(writer).print("line 2");
+ verify(writer).print("line 3");
+ verify(writer, times(1)).print(", ");
+ verify(writer).print(") {");
+ verify(writer, times(0)).inc();
+ verify(writer, times(0)).println();
+ }
+
+}