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.openo.nfvo.resmanagement.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;
28 import net.sf.json.JSONObject;
30 public class ResponseUtilTest {
33 public void TestGenHttpResponseWithTwoParam() {
36 JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1);
37 JSONObject expectedResult = new JSONObject();
38 expectedResult.put("msg", "123");
39 assertEquals(result.toString(), expectedResult.toString());
44 public void TestGenHttpResponseWithThreeParam() {
47 JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null);
48 JSONObject expectedResult = new JSONObject();
49 expectedResult.put("msg", "123");
50 assertEquals(result.toString(), expectedResult.toString());
55 public void TestGenHttpResponseWithFourParam1() {
56 int httpStatusCode = -1;
59 JSONObject result = ResponseUtil.genHttpResponse(null, httpStatusCode, retCode1, msg1);
60 JSONObject expectedResult = new JSONObject();
61 expectedResult.put("msg", "123");
62 assertEquals(result.toString(), expectedResult.toString());
67 public void TestGenHttpResponseWithFourParam2() {
68 Map<String, Integer> codeMap = new HashMap<String, Integer>(5);
69 codeMap.put("httpStatusCode", -1);
70 codeMap.put("retCode", 1);
71 Map<String, Object> map = new HashMap<String, Object>(5);
75 JSONObject result = ResponseUtil.genHttpResponse(null, codeMap, msg1, map);
76 JSONObject expectedResult = new JSONObject();
77 expectedResult.put("msg", "123");
78 expectedResult.put("a", "-1");
79 assertEquals(result.toString(), expectedResult.toString());
83 public void testPrivateConstructor() throws Exception {
84 Constructor constructor = ResponseUtil.class.getDeclaredConstructor();
85 assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
87 constructor.setAccessible(true);
88 constructor.newInstance();