a62e61e4312c938b683d9e683054b7667461d76e
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016-2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.resmanagement.common.util.response;
18
19 import static org.junit.Assert.*;
20
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.Modifier;
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import org.junit.Test;
27 import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil;
28
29 import net.sf.json.JSONObject;
30
31 public class ResponseUtilTest {
32
33     @Test
34     public void TestGenHttpResponseWithTwoParam() {
35         int retCode1 = -1;
36         String msg1 = "123";
37         JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1);
38         JSONObject expectedResult = new JSONObject();
39         expectedResult.put("msg", "123");
40         assertEquals(result.toString(), expectedResult.toString());
41         ;
42     }
43
44     @Test
45     public void TestGenHttpResponseWithThreeParam() {
46         int retCode1 = -1;
47         String msg1 = "123";
48         JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null);
49         JSONObject expectedResult = new JSONObject();
50         expectedResult.put("msg", "123");
51         assertEquals(result.toString(), expectedResult.toString());
52         ;
53     }
54
55     @Test
56     public void TestGenHttpResponseWithFourParam1() {
57         int httpStatusCode = -1;
58         int retCode1 = -1;
59         String msg1 = "123";
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());
64         ;
65     }
66
67     @Test
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);
73         map.put("a", -1);
74         map.put("b", 1);
75         String msg1 = "123";
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());
81         ;
82     }
83     @Test
84     public void testPrivateConstructor() throws Exception {
85         Constructor constructor = ResponseUtil.class.getDeclaredConstructor();
86         assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers()));
87
88         constructor.setAccessible(true);
89         constructor.newInstance();
90     }
91 }