From 0626c68a31d89744461f534cd3205414d2019a69 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 29 Mar 2018 10:52:06 +0530 Subject: verify multivimproxy response utils Issue-ID: VFC-644 Change-Id: Id89709fd510e58ea320bc77e96f42e61cf688ecc Signed-off-by: Kanagaraj Manickam k00365106 --- .../common/util/response/ResponseUtilTest.java | 91 +++++++++++++ .../common/util/response/RoaResponseUtilTest.java | 148 +++++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/ResponseUtilTest.java create mode 100644 service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/RoaResponseUtilTest.java 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 index 0000000..ce3ce81 --- /dev/null +++ b/service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/ResponseUtilTest.java @@ -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 codeMap = new HashMap(5); + codeMap.put("httpStatusCode", -1); + codeMap.put("retCode", 1); + Map map = new HashMap(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 index 0000000..3ca08c9 --- /dev/null +++ b/service/src/test/java/org/onap/vfc/nfvo/multivimproxy/common/util/response/RoaResponseUtilTest.java @@ -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() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg, Map map) { + return null; + } + }; + JSONObject result = RoaResponseUtil.get(null); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testAdd() { + int a = 0; + new MockUp() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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() { + + @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(); + } + +} -- cgit 1.2.3-korg