2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.res.common.util.response;
19 import static org.junit.Assert.*;
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.Modifier;
23 import java.util.HashMap;
26 import org.junit.Test;
27 import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil;
29 import net.sf.json.JSONObject;
31 public class ResponseUtilTest {
34 public void TestGenHttpResponseWithTwoParam() {
37 JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1);
38 JSONObject expectedResult = new JSONObject();
39 expectedResult.put("msg", "123");
40 assertEquals(result.toString(), expectedResult.toString());
45 public void TestGenHttpResponseWithThreeParam() {
48 JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null);
49 JSONObject expectedResult = new JSONObject();
50 expectedResult.put("msg", "123");
51 assertEquals(result.toString(), expectedResult.toString());
56 public void TestGenHttpResponseWithFourParam1() {
57 int httpStatusCode = -1;
60 JSONObject result = ResponseUtil.genHttpResponse(null, httpStatusCode, retCode1, msg1);
61 JSONObject expectedResult = new JSONObject();
62 expectedResult.put("msg", "123");
63 assertEquals(result.toString(), expectedResult.toString());
68 public void TestGenHttpResponseWithFourParam2() {
69 Map<String, Integer> codeMap = new HashMap<String, Integer>(5);
70 codeMap.put("httpStatusCode", -1);
71 codeMap.put("retCode", 1);
72 Map<String, Object> map = new HashMap<String, Object>(5);
76 JSONObject result = ResponseUtil.genHttpResponse(null, codeMap, msg1, map);
77 JSONObject expectedResult = new JSONObject();
78 expectedResult.put("msg", "123");
79 expectedResult.put("a", "-1");
80 assertEquals(result.toString(), expectedResult.toString());
84 public void testPrivateConstructor() throws Exception {
85 Constructor constructor = ResponseUtil.class.getDeclaredConstructor();
86 assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
88 constructor.setAccessible(true);
89 constructor.newInstance();