diff options
Diffstat (limited to 'misc/xgen/src/test/java/org')
9 files changed, 810 insertions, 0 deletions
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_BackTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_BackTest.java new file mode 100644 index 00000000..6a3eb15e --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_BackTest.java @@ -0,0 +1,37 @@ +/**
+ * ============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 org.junit.Test;
+
+public class JU_BackTest {
+
+ @Test
+ public void testBackConstructor() {
+ Back back = new Back("String", true, false);
+
+ assertEquals(back.str, "String");
+ assertEquals(back.dec, true);
+ assertEquals(back.cr, false);
+ }
+}
\ No newline at end of file diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_MarkTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_MarkTest.java new file mode 100644 index 00000000..200bde6e --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_MarkTest.java @@ -0,0 +1,41 @@ +/**
+ * ============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 org.junit.Test;
+
+public class JU_MarkTest {
+
+ @Test
+ public void testMark() {
+ Mark mark = new Mark();
+ assertEquals(mark.spot, 0);
+ assertEquals(mark.comment, null);
+
+ mark = new Mark("New Comment");
+ mark.spot(10);
+ assertEquals(mark.spot, 10);
+ assertEquals(mark.comment, "New Comment");
+
+ }
+}
\ No newline at end of file diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_NullCacheTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_NullCacheTest.java new file mode 100644 index 00000000..5b5f816a --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_NullCacheTest.java @@ -0,0 +1,35 @@ +/**
+ * ============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 org.junit.Test;
+import org.onap.aaf.misc.xgen.Cache.Null;
+
+public class JU_NullCacheTest {
+
+ @Test
+ public void testNullIsSingleton() {
+ Null<?> singleton = Cache.Null.singleton();
+ assertEquals(singleton, Cache.Null.singleton());
+ }
+}
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_SectionTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_SectionTest.java new file mode 100644 index 00000000..a45ea158 --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/JU_SectionTest.java @@ -0,0 +1,64 @@ +/**
+ * ============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.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aaf.misc.env.APIException;
+
+public class JU_SectionTest {
+
+ @Mock
+ private Writer writer;
+
+ @Before
+ public void setup() {
+ writer = mock(Writer.class);
+ }
+
+ @Test
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public void test() throws APIException, IOException {
+ Section section = new Section();
+ section.forward = "Forward";
+ section.backward = "Backward";
+
+ section.setIndent(10);
+ section.forward(writer);
+ section.back(writer);
+
+ assertEquals(section.use(null, null, null), section);
+ assertEquals(section.getIndent(), 10);
+ assertEquals(section.toString(), "Forward");
+
+ verify(writer).write("Forward");
+ verify(writer).write("Backward");
+ }
+
+}
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_HTML4GenTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_HTML4GenTest.java new file mode 100644 index 00000000..18b33938 --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_HTML4GenTest.java @@ -0,0 +1,315 @@ +/**
+ * ============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.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class JU_HTML4GenTest {
+
+ private final static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
+ + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
+
+ private String charset = "utf-8";
+
+ private final String CHARSET_LINE = "<meta http-equiv=\"Content-type\" content=\"text.hml; charset=" + charset
+ + "\">";
+
+ @Mock
+ Writer w;
+
+ @Before
+ public void setUp() throws Exception {
+
+ w = mock(Writer.class);
+ }
+
+ @Test
+ public void testHTML() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.html("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+ for (char ch : DOCTYPE.toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "html".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ verify(w, atLeast(1)).write(anyInt());
+ }
+
+ @Test
+ public void testHead() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.head();
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "head".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testBody() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.body("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "body".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testCharSet() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.charset(charset);
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : CHARSET_LINE.toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testHeader() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.header("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "header".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "div".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testFooter() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.footer("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "footer".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "div".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testSection() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.section("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "section".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "div".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testArticle() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.article("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "attrib".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "div".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testAside() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.aside("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "aside".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "div".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testNav() throws IOException {
+
+ HTML4Gen gen = new HTML4Gen(w);
+
+ gen.nav("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "nav".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "div".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+}
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_HTML5GenTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_HTML5GenTest.java new file mode 100644 index 00000000..953a4a3b --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_HTML5GenTest.java @@ -0,0 +1,135 @@ +/**
+ * ============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.mockito.Matchers.anyInt;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class JU_HTML5GenTest {
+
+ private final static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""
+ + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
+
+ private String charset = "utf-8";
+
+ private final String CHARSET_LINE = "<meta charset=\"" + charset + "\">";
+
+ @Mock
+ Writer w;
+
+ @Before
+ public void setUp() throws Exception {
+
+ w = mock(Writer.class);
+ }
+
+ @Test
+ public void testHTML() throws IOException {
+
+ HTML5Gen gen = new HTML5Gen(w);
+
+ gen.html("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "html".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ verify(w, atLeast(1)).write(anyInt());
+ }
+
+ @Test
+ public void testHead() throws IOException {
+
+ HTML5Gen gen = new HTML5Gen(w);
+
+ gen.head();
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "head".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testBody() throws IOException {
+
+ HTML5Gen gen = new HTML5Gen(w);
+
+ gen.body("attributes");
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : "body".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+ for (char ch : "attributes".toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+
+ @Test
+ public void testCharSet() throws IOException {
+
+ HTML5Gen gen = new HTML5Gen(w);
+
+ gen.charset(charset);
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ for (char ch : CHARSET_LINE.toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(w, atLeast(map.get(ch))).write(ch);
+ }
+ }
+}
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_ImportsTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_ImportsTest.java new file mode 100644 index 00000000..4a6ce6b8 --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/html/JU_ImportsTest.java @@ -0,0 +1,54 @@ +/**
+ * ============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.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class JU_ImportsTest {
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @Test
+ public void test() {
+ Imports imports = new Imports(2);
+ imports.css("styles.css");
+ imports.js("main.js");
+ imports.theme("New Theme");
+
+ assertEquals("New Theme", imports.themeResolve(null));
+ assertEquals("New Theme", imports.themeResolve(""));
+ assertEquals("The Theme", imports.themeResolve("The Theme"));
+
+ assertEquals("build/../../", imports.dots(new StringBuilder("build/")).toString());
+ assertEquals("../../Theme/", imports.themePath("Theme"));
+ assertEquals("../../New Theme/", imports.themePath(""));
+ assertEquals("../../New Theme/", imports.themePath(null));
+
+ imports.theme(null);
+ assertEquals("../../", imports.themePath(null));
+ }
+
+}
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/xml/JU_XMLCacheGenTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/xml/JU_XMLCacheGenTest.java new file mode 100644 index 00000000..c8014dda --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/xml/JU_XMLCacheGenTest.java @@ -0,0 +1,63 @@ +/**
+ * ============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.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aaf.misc.env.APIException;
+import org.onap.aaf.misc.xgen.Code;
+
+public class JU_XMLCacheGenTest {
+
+ @Mock
+ Writer writer;
+
+ @Mock
+ Code code;
+
+ @Before
+ public void setup() {
+
+ code = mock(Code.class);
+ writer = mock(Writer.class);
+ }
+
+ @Test
+ public void test() throws APIException, IOException {
+ XMLCacheGen cacheGen = new XMLCacheGen(0, code);
+ assertEquals(cacheGen.PRETTY, 1);
+
+ XMLGen xgen = cacheGen.create(1, writer);
+ assertEquals(0, xgen.getIndent());
+
+ xgen.setIndent(10);
+ assertEquals(10, xgen.getIndent());
+ xgen.comment("Comment");
+ }
+
+}
diff --git a/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/xml/JU_XMLGenTest.java b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/xml/JU_XMLGenTest.java new file mode 100644 index 00000000..2dbc422a --- /dev/null +++ b/misc/xgen/src/test/java/org/onap/aaf/misc/xgen/xml/JU_XMLGenTest.java @@ -0,0 +1,66 @@ +/**
+ * ============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.xml;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class JU_XMLGenTest {
+
+ @Mock
+ private Writer writer;
+
+ String XML_TAG = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
+
+ Map<Character, Integer> map = new TreeMap<Character, Integer>();
+
+ @Before
+ public void setUp() throws Exception {
+ writer = mock(Writer.class);
+ }
+
+ @Test
+ public void testXMLGenWriter() throws IOException {
+ XMLGen xmlGen = new XMLGen(writer);
+
+ xmlGen.xml();
+
+ for (char ch : XML_TAG.toCharArray()) {
+ Integer times = map.get(ch);
+ map.put(ch, (times == null ? 0 : times) + 1);
+ }
+
+ for (char ch : map.keySet()) {
+ verify(writer, times(map.get(ch))).write(ch);
+ }
+ }
+}
\ No newline at end of file |