summaryrefslogtreecommitdiffstats
path: root/appc-dg/appc-dg-shared
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dg/appc-dg-shared')
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java48
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java111
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilVnfTest.java69
-rw-r--r--appc-dg/appc-dg-shared/appc-dg-common/src/test/resources/data/input.json1
4 files changed, 229 insertions, 0 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java
new file mode 100644
index 000000000..f0e525b53
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JAXBUtilTest.java
@@ -0,0 +1,48 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 AT&T
+*=================================================================================
+* 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.appc.dg.common.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+
+import javax.xml.bind.JAXBException;
+
+public class JAXBUtilTest {
+
+ @Before
+ public void setUp() {
+ }
+
+ @Test
+ public void testToObjectFail() {
+ String xmlStr = "<?xml version=\\\"1.0\\\"?><vnfId>I1</vnfId><vnfType>T1</vnfType>";
+ JSONUtilVnfTest jOut = null;
+ try {
+ jOut = JAXBUtil.toObject(xmlStr, JSONUtilVnfTest.class);
+ } catch (JAXBException jaxbe) {
+ assertEquals(jOut, null);
+ }
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java
new file mode 100644
index 000000000..0dff2e24d
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilTest.java
@@ -0,0 +1,111 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 AT&T
+*=================================================================================
+* 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.appc.dg.common.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+import java.util.HashMap;
+import java.util.Map;
+import java.io.FileReader;
+import java.io.FileNotFoundException;
+
+import java.io.UncheckedIOException;
+
+
+public class JSONUtilTest {
+
+ @Before
+ public void setUp() {
+ }
+
+ @Test
+ public void testFromJsonReader() {
+
+ try {
+ JSONUtilVnfTest jOut = JSONUtil.fromJson(new FileReader("src/test/resources/data/input.json"), JSONUtilVnfTest.class);
+ assertEquals("I1", jOut.getVnfId());
+ assertEquals("T1", jOut.getVnfType());
+ } catch (UncheckedIOException uioe) {
+ fail(uioe.getMessage() + " Unchecked IO exception encountered");
+ }
+ catch (FileNotFoundException fnfe) {
+ fail(fnfe.getMessage() + " File Not Found exception encountered");
+ }
+
+ }
+
+ @Test
+ public void testFromJsonException() {
+ JSONUtilVnfTest jOut = null;
+ try {
+ jOut = JSONUtil.fromJson("{\"vnfId\":\"I2\",\"vnfType\"\"T2\"}", JSONUtilVnfTest.class);
+ } catch (UncheckedIOException uioe) {
+ assertEquals(jOut, null);
+ }
+ }
+
+ @Test
+ public void testFromToJsonStr() {
+ JSONUtilVnfTest jRef = new JSONUtilVnfTest("I1", "T1");
+
+ try {
+ assertEquals(JSONUtil.toJson(jRef), "{\"vnfId\":\"I1\",\"vnfType\":\"T1\"}");
+ jRef.setVnfId("I2");
+ jRef.setVnfType("T2");
+ assertEquals(JSONUtil.toJson(jRef), "{\"vnfId\":\"I2\",\"vnfType\":\"T2\"}");
+ String refJson = JSONUtil.toJson(jRef);
+
+ JSONUtilVnfTest jOut = JSONUtil.fromJson(refJson, JSONUtilVnfTest.class);
+ assertEquals(jRef.getVnfId(), jOut.getVnfId());
+ assertEquals(jRef.getVnfType(), jOut.getVnfType());
+
+ } catch (UncheckedIOException uioe) {
+ fail(uioe.getMessage() + " Unchecked IO exception encountered");
+ }
+ }
+
+ @Test
+ public void testExttractValues() {
+ JSONUtilVnfTest jRef = new JSONUtilVnfTest("I2", "T2");
+
+ try {
+
+ String refJson = JSONUtil.toJson(jRef);
+
+
+ Map<String, String> map = JSONUtil.extractPlainValues(refJson, "vnfId", "vnfType");
+
+ HashMap<String, String> hashMap =
+ (map instanceof HashMap)
+ ? (HashMap) map
+ : new HashMap<String, String>(map);
+ assertEquals(hashMap.get("vnfId"), "I2");
+ assertEquals(hashMap.get("vnfType"), "T2");
+
+
+ } catch (UncheckedIOException uioe) {
+ fail(uioe.getMessage() + " Unchecked IO exception encountered");
+ }
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilVnfTest.java b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilVnfTest.java
new file mode 100644
index 000000000..c60984726
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/java/org/onap/appc/dg/common/utils/JSONUtilVnfTest.java
@@ -0,0 +1,69 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 AT&T
+*=================================================================================
+* 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.appc.dg.common.utils;
+
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "vnfId", "vnfType" })
+
+public class JSONUtilVnfTest {
+
+ @JsonProperty("vnfId")
+ private String vnfId;
+
+ @JsonProperty("vnfType")
+ private String vnfType;
+
+ public JSONUtilVnfTest()
+ {
+ super();
+ }
+
+ public JSONUtilVnfTest(String vnfId, String vnfType)
+ {
+ this.vnfId = vnfId;
+ this.vnfType = vnfType;
+ }
+
+ public String getVnfId()
+ {
+ return vnfId;
+ }
+
+ public void setVnfId(String vnfId)
+ {
+ this.vnfId = vnfId;
+ }
+
+ public String getVnfType()
+ {
+ return vnfType;
+ }
+
+ public void setVnfType(String vnfType)
+ {
+ this.vnfType = vnfType;
+ }
+
+}
diff --git a/appc-dg/appc-dg-shared/appc-dg-common/src/test/resources/data/input.json b/appc-dg/appc-dg-shared/appc-dg-common/src/test/resources/data/input.json
new file mode 100644
index 000000000..377c9f17e
--- /dev/null
+++ b/appc-dg/appc-dg-shared/appc-dg-common/src/test/resources/data/input.json
@@ -0,0 +1 @@
+{"vnfId":"I1","vnfType":"T1"} \ No newline at end of file