Update gvnfm-driver .gitreview file
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / openo / nfvo / jujuvnfmadapter / service / adapter / impl / AdapterResourceManagerTest.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.openo.nfvo.jujuvnfmadapter.service.adapter.impl;
18
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.junit.Test;
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
26 import org.openo.baseservice.roa.util.restclient.HttpRest;
27 import org.openo.baseservice.roa.util.restclient.RestfulParametes;
28 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
29 import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant;
30
31 import mockit.Mock;
32 import mockit.MockUp;
33 import net.sf.json.JSONObject;
34
35 public class AdapterResourceManagerTest {
36
37         private AdapterResourceManager adapterResManager;
38
39         private JSONObject jsonObj;
40
41         /*
42          * @Test public void testGetJujuVnfmInfo() throws Exception { Map paramsMap
43          * = new HashMap(); JSONObject resultObj = new JSONObject();
44          * resultObj.put("reason", "RestfulResponse is null.");
45          * resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
46          * 
47          * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
48          * paramsMap.put("methodType","get");
49          * 
50          * new MockUp<JujuVnfmRestfulUtil>(){
51          * 
52          * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str)
53          * { return null; } }; adapterResManager = new AdapterResourceManager();
54          * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
55          * assertEquals(resultObj,jsonObj); }
56          */
57
58         /*
59          * @Test public void testGetVnfdInfo() throws Exception { Map paramsMap =
60          * new HashMap(); JSONObject resultObj = new JSONObject();
61          * resultObj.put("reason", "RestfulResponse is null.");
62          * resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
63          * 
64          * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
65          * paramsMap.put("methodType","get");
66          * 
67          * new MockUp<JujuVnfmRestfulUtil>(){
68          * 
69          * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str)
70          * { return null; } }; adapterResManager = new AdapterResourceManager();
71          * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
72          * assertEquals(resultObj,jsonObj); }
73          */
74
75         @Test
76         public void getJujuVnfmInfoTest() {
77                 new MockUp<HttpRest>() {
78                         @Mock
79                         RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
80                                 RestfulResponse rsp = new RestfulResponse();
81                                 rsp.setStatus(200);
82                                 return rsp;
83                         }
84                 };
85                 new MockUp<JSONObject>() {
86                         @Mock
87                         public JSONObject fromObject(Object object) {
88                                 JSONObject json = new JSONObject();
89                                 return json;
90                         }
91                 };
92                 Map<String, String> paramsMap = new HashMap<>();
93                 JSONObject resultObj = new JSONObject();
94                 resultObj.put("reason", "RestfulResponse is null.");
95                 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
96
97                 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
98                 paramsMap.put("methodType", "get");
99                 adapterResManager = new AdapterResourceManager();
100                 jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
101                 assertTrue(jsonObj != null);
102         }
103
104         @Test
105         public void getJujuVnfmInfoTest1() {
106                 new MockUp<HttpRest>() {
107                         @Mock
108                         RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
109                                 RestfulResponse rsp = new RestfulResponse();
110                                 rsp.setStatus(504);
111                                 return rsp;
112                         }
113                 };
114                 new MockUp<JSONObject>() {
115                         @Mock
116                         public JSONObject fromObject(Object object) {
117                                 JSONObject json = new JSONObject();
118                                 return json;
119                         }
120                 };
121                 Map<String, String> paramsMap = new HashMap<>();
122                 JSONObject resultObj = new JSONObject();
123                 resultObj.put("reason", "RestfulResponse is null.");
124                 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
125
126                 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
127                 paramsMap.put("methodType", "get");
128                 adapterResManager = new AdapterResourceManager();
129                 jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
130                 assertTrue(jsonObj != null);
131         }
132
133         @Test
134         public void getJujuVnfmInfoTestFalse() {
135                 Map<String, String> paramsMap = new HashMap<>();
136                 JSONObject resultObj = new JSONObject();
137                 resultObj.put("reason", "RestfulResponse is null.");
138                 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
139
140                 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
141                 paramsMap.put("methodType", "get");
142                 adapterResManager = new AdapterResourceManager();
143                 jsonObj = adapterResManager.getJujuVnfmInfo(null);
144                 assertTrue(jsonObj.get("reason").equals("RestfulResponse is null."));
145         }
146
147         @Test
148         public void getVnfdInfoTest() {
149                 Map<String, String> paramsMap = new HashMap<>();
150                 JSONObject resultObj = new JSONObject();
151                 resultObj.put("reason", "RestfulResponse is null.");
152                 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
153
154                 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
155                 paramsMap.put("methodType", "get");
156                 adapterResManager = new AdapterResourceManager();
157 //              jsonObj = adapterResManager.getVnfdInfo("1111");
158 //              assertTrue(jsonObj.get("reason").equals("RestfulResponse is null."));
159         }
160
161         @Test
162         public void getVnfdInfoTest1() {
163                 new MockUp<HttpRest>() {
164                         @Mock
165                         RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
166                                 RestfulResponse rsp = new RestfulResponse();
167                                 rsp.setStatus(200);
168                                 return rsp;
169                         }
170                 };
171                 new MockUp<JSONObject>() {
172                         @Mock
173                         public JSONObject fromObject(Object object) {
174                                 JSONObject json = new JSONObject();
175                                 return json;
176                         }
177                 };
178                 Map<String, String> paramsMap = new HashMap<>();
179                 JSONObject resultObj = new JSONObject();
180                 resultObj.put("reason", "RestfulResponse is null.");
181                 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
182
183                 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
184                 paramsMap.put("methodType", "get");
185                 adapterResManager = new AdapterResourceManager();
186 //              jsonObj = adapterResManager.getVnfdInfo("1111");
187 //              assertTrue(jsonObj != null);
188         }
189
190         @Test
191         public void getVnfdInfoTest2() {
192                 new MockUp<HttpRest>() {
193                         @Mock
194                         RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
195                                 RestfulResponse rsp = new RestfulResponse();
196                                 rsp.setStatus(504);
197                                 return rsp;
198                         }
199                 };
200
201                 Map<String, String> paramsMap = new HashMap<>();
202                 JSONObject resultObj = new JSONObject();
203                 resultObj.put("reason", "RestfulResponse is null.");
204                 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
205
206                 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
207                 paramsMap.put("methodType", "get");
208                 adapterResManager = new AdapterResourceManager();
209 //              jsonObj = adapterResManager.getVnfdInfo("1111");
210 //              assertTrue(jsonObj != null);
211         }
212 }