8792f528e2a18171de73f4a247271df3eb0958ba
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / common / ResultRequestUtilTest.java
1 /*
2  * Copyright 2016 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.vnfm.svnfm.vnfmadapter.common;
18
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertTrue;
21
22 import org.junit.Test;
23 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
24 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
25
26 import mockit.Mock;
27 import mockit.MockUp;
28 import net.sf.json.JSONObject;
29
30 public class ResultRequestUtilTest {
31
32     @Test
33     public void callTestInternalError() {
34         new MockUp<ConnectMgrVnfm>() {
35
36             @Mock
37             public int connect(JSONObject vnfmObj) {
38                 return 500;
39             }
40         };
41         
42         
43         JSONObject vnfmObject = new JSONObject();
44         String path = "http://localhost:8080";
45         String methodName = "get";
46         String paramsJson = "";
47         vnfmObject.put("url", path);
48         vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
49         vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
50         JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
51         assertTrue(resp.get("data").equals("connect fail."));
52     }
53
54     @Test
55     public void callTestConnectionErrot() {
56         new MockUp<ConnectMgrVnfm>() {
57
58             @Mock
59             public int connect(JSONObject vnfmObj) {
60                 return 200;
61             }
62         };
63         JSONObject vnfmObject = new JSONObject();
64         vnfmObject.put("url", "/test/123");
65         String path = "http://localhost:8080";
66         String methodName = "get";
67         String paramsJson = "";
68         JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
69         assertTrue(resp.get("data").equals("get connection error"));
70     }
71
72     @Test
73     public void callTest() {
74         new MockUp<ConnectMgrVnfm>() {
75
76             @Mock
77             public int connect(JSONObject vnfmObj) {
78                 return 200;
79             }
80
81             @Mock
82             public String getRoaRand() {
83                 return "1234";
84             }
85
86             @Mock
87             public String getAccessSession() {
88                 return "1234";
89             }
90
91         };
92
93         JSONObject vnfmObject = new JSONObject();
94         vnfmObject.put("url", "/test/123");
95         String path = "https://localhost:8080/%s";
96         String methodName = "get";
97         String paramsJson = "";
98         JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
99         assertTrue(resp.get("data").equals("get connection error"));
100     }
101     
102     
103     @Test
104     public void call() {
105     
106         JSONObject vnfmObject = new JSONObject();
107         vnfmObject.put("url","https://localhost:8080/%s" );
108         vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
109         vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
110          String path = "https://localhost:8080/%s";
111          String methodName = "get";
112          String paramsJson = "";
113           assertNotNull(ResultRequestUtil.call( vnfmObject, path,  methodName,  paramsJson,
114             "authModel"));
115         
116     }
117     
118         @Test
119         public void callSouth() {
120                 JSONObject vnfmObject = new JSONObject();
121                 vnfmObject.put("url", "https://localhost:8080/%s");
122                 vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
123                 vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
124                 String path = "https://localhost:8080/%s";
125                 String methodName = "get";
126                 String paramsJson = "";
127                 assertNotNull(ResultRequestUtil.callSouth(vnfmObject, path, methodName, paramsJson, "authModel"));
128         }
129
130 }