verify multivimproxy response utils 19/40019/1
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Thu, 29 Mar 2018 05:22:06 +0000 (10:52 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Thu, 29 Mar 2018 05:22:06 +0000 (10:52 +0530)
Issue-ID: VFC-644

Change-Id: Id89709fd510e58ea320bc77e96f42e61cf688ecc
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/ResponseUtilTest.java [new file with mode: 0644]
service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/RoaResponseUtilTest.java [new file with mode: 0644]

diff --git a/service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/ResponseUtilTest.java b/service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/ResponseUtilTest.java
new file mode 100644 (file)
index 0000000..ce3ce81
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2018 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.onap.vfc.nfvo.multivimproxy.common.util.response;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.vfc.nfvo.multivimproxy.common.util.response.ResponseUtil;
+
+import net.sf.json.JSONObject;
+
+public class ResponseUtilTest {
+
+    @Test
+    public void TestGenHttpResponseWithTwoParam() {
+        int retCode1 = -1;
+        String msg1 = "123";
+        JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1);
+        JSONObject expectedResult = new JSONObject();
+        expectedResult.put("msg", "123");
+        assertEquals(result.toString(), expectedResult.toString());
+        ;
+    }
+
+    @Test
+    public void TestGenHttpResponseWithThreeParam() {
+        int retCode1 = -1;
+        String msg1 = "123";
+        JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null);
+        JSONObject expectedResult = new JSONObject();
+        expectedResult.put("msg", "123");
+        assertEquals(result.toString(), expectedResult.toString());
+        ;
+    }
+
+    @Test
+    public void TestGenHttpResponseWithFourParam1() {
+        int httpStatusCode = -1;
+        int retCode1 = -1;
+        String msg1 = "123";
+        JSONObject result = ResponseUtil.genHttpResponse(httpStatusCode, retCode1, msg1);
+        JSONObject expectedResult = new JSONObject();
+        expectedResult.put("msg", "123");
+        assertEquals(result.toString(), expectedResult.toString());
+        ;
+    }
+
+    @Test
+    public void TestGenHttpResponseWithFourParam2() {
+        Map<String, Integer> codeMap = new HashMap<String, Integer>(5);
+        codeMap.put("httpStatusCode", -1);
+        codeMap.put("retCode", 1);
+        Map<String, Object> map = new HashMap<String, Object>(5);
+        map.put("a", -1);
+        map.put("b", 1);
+        String msg1 = "123";
+        JSONObject result = ResponseUtil.genHttpResponse(codeMap, msg1, map);
+        JSONObject expectedResult = new JSONObject();
+        expectedResult.put("msg", "123");
+        expectedResult.put("a", "-1");
+        assertEquals(result.toString(), expectedResult.toString());
+        ;
+    }
+    @Test
+    public void testPrivateConstructor() throws Exception {
+        Constructor constructor = ResponseUtil.class.getDeclaredConstructor();
+        assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+        constructor.setAccessible(true);
+        constructor.newInstance();
+    }
+}
diff --git a/service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/RoaResponseUtilTest.java b/service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/RoaResponseUtilTest.java
new file mode 100644 (file)
index 0000000..3ca08c9
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2018 Huawei Technologies Co., Ltd.
+ *
+ * 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.
+ */
+
+package org.onap.vfc.nfvo.multivimproxy.common.util.response;
+
+import static org.junit.Assert.*;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.vfc.nfvo.multivimproxy.common.util.response.ResponseUtil;
+import org.onap.vfc.nfvo.multivimproxy.common.util.response.RoaResponseUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import net.sf.json.JSONObject;
+
+public class RoaResponseUtilTest {
+
+    @Test
+    public void testGet() {
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg, Map<String, Object> map) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.get(null);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testAdd() {
+        int a = 0;
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.add(a);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testAdd1() {
+        int a = 2;
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.add(a);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testUpdate() {
+        int a = 0;
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.update(a);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testUpdate1() {
+        int a = 2;
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.update(a);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testDelete() {
+        int a = -1;
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.delete(a);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testDelete1() {
+        int a = 0;
+        new MockUp<ResponseUtil>() {
+
+            @Mock
+            public JSONObject genHttpResponse(int retCode, String msg) {
+                return null;
+            }
+        };
+        JSONObject result = RoaResponseUtil.delete(a);
+        JSONObject expectedResult = null;
+        assertEquals(expectedResult, result);
+    }
+
+    @Test
+    public void testPrivateConstructor() throws Exception {
+        Constructor constructor = RoaResponseUtil.class.getDeclaredConstructor();
+        assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
+
+        constructor.setAccessible(true);
+        constructor.newInstance();
+    }
+
+}