diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-03-29 10:52:06 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-03-29 10:52:06 +0530 |
commit | 0626c68a31d89744461f534cd3205414d2019a69 (patch) | |
tree | 828bab858aa89fd8e41228233d946df2a6cfa957 /service | |
parent | 87db9c00fe96b7fec8cee0d000727c27cca514fa (diff) |
verify multivimproxy response utils
Issue-ID: VFC-644
Change-Id: Id89709fd510e58ea320bc77e96f42e61cf688ecc
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'service')
2 files changed, 239 insertions, 0 deletions
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<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 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<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(); + } + +} |