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.vnfmadapter.service.process;
19 import static org.junit.Assert.assertEquals;
21 import org.junit.Test;
22 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
23 import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
24 import org.openo.nfvo.vnfmadapter.service.constant.Constant;
28 import net.sf.json.JSONObject;
36 * @version NFVO 0.5 Aug 9, 2016
38 public class VnfResourceMgrTest {
41 public void testgrantVnfResource() {
44 "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
45 JSONObject vnfObj = JSONObject.fromObject(data);
46 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
47 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
49 JSONObject retJson = new JSONObject();
50 retJson.put("retCode", Constant.REST_FAIL);
51 retJson.put("errorMsg", "params parse exception");
52 assertEquals(retJson, result);
56 public void testgrantVnfResourceSuccess() {
57 new MockUp<VnfmRestfulUtil>() {
60 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
61 RestfulResponse rsp = new RestfulResponse();
63 rsp.setResponseJson(new JSONObject().toString());
68 JSONObject vnfObj = new JSONObject();
70 "{\"type\": \"instantiation\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"increase\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
71 vnfObj = JSONObject.fromObject(data);
72 VnfResourceMgr grantTest = new VnfResourceMgr();
73 JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
75 JSONObject retJson = new JSONObject();
76 assertEquals(retJson, result);
80 public void testgrantVnfResourceSuccess1() {
81 new MockUp<VnfmRestfulUtil>() {
84 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
85 RestfulResponse rsp = new RestfulResponse();
87 rsp.setResponseJson(new JSONObject().toString());
92 JSONObject vnfObj = new JSONObject();
94 "{\"type\": \"instantiation\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"decrease\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
95 vnfObj = JSONObject.fromObject(data);
96 VnfResourceMgr grantTest = new VnfResourceMgr();
97 JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
99 JSONObject retJson = new JSONObject();
100 assertEquals(retJson, result);
104 public void testgrantVnfResourceSuccess2() {
105 new MockUp<VnfmRestfulUtil>() {
108 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
109 RestfulResponse rsp = new RestfulResponse();
111 rsp.setResponseJson(new JSONObject().toString());
116 JSONObject vnfObj = new JSONObject();
118 "{\"type\": \"scale\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"decrease\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
119 vnfObj = JSONObject.fromObject(data);
120 VnfResourceMgr grantTest = new VnfResourceMgr();
121 JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
123 JSONObject retJson = new JSONObject();
124 assertEquals(retJson, result);
128 public void testgrantVnfResourceSuccess3() {
129 new MockUp<VnfmRestfulUtil>() {
132 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
133 RestfulResponse rsp = new RestfulResponse();
135 rsp.setResponseJson(new JSONObject().toString());
140 JSONObject vnfObj = new JSONObject();
142 "{\"type\": \"scale\",\"location\": \"RomaRespool\",\"version\":\"V500R001C20\",\"vendor\": \"V500R001C20B001\",\"tenant\": \"admin\",\"vnf_id\":\"NE=1304\",\"vnfm_id\": \"9a49755d-8050-4369-9e7d-0a0855097585\",\"project_id\":\"\",\"operation_right\": \"increase\",\"vnf_name\": \"wangyuans4\",\"vim_id\":\"\",\"dr_location\": \"RomaRespool\",\"nfvo_id\": \"\",\"vnf_type\": \"vNGFW\",\"plan_id\":\"V4\",\"plan_name\": \"V4\",\"vnfd_id\": \"vNGFW\",\"vm_list\": [{\"vm_flavor\":{\"location\": \"\",\"priority\": \"1\",\"storage\": [{\"vol_type\":\"local_volume\",\"vol_size\": \"200\"},{\"storage_type\": \"local_image\",\"disk_size\":\"80\"}],\"vdu_name\": \"OMU\",\"num_cpus\": \"4\",\"mem_size\": \"8192\"},\"init_number\":\"1\"}],\"ex_vim_list\": []}";
143 vnfObj = JSONObject.fromObject(data);
144 VnfResourceMgr grantTest = new VnfResourceMgr();
145 JSONObject result = grantTest.grantVnfResource(vnfObj, "1111", "abc");
147 JSONObject retJson = new JSONObject();
148 assertEquals(retJson, result);
152 public void testgrantVnfResourceByResMapNull() {
155 "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavors\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
156 JSONObject vnfObj = JSONObject.fromObject(data);
157 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
158 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
160 JSONObject retJson = new JSONObject();
161 retJson.put("retCode", Constant.REST_FAIL);
162 retJson.put("errorMsg", "resource params error");
163 assertEquals(retJson, result);
167 public void testgrantVnfResourceByTypeIsEmpty() {
169 "{\"type\": \"\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
170 JSONObject vnfObj = JSONObject.fromObject(data);
171 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
172 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
174 JSONObject retJson = new JSONObject();
175 retJson.put("retCode", Constant.REST_FAIL);
176 retJson.put("errorMsg", "basic params error");
177 assertEquals(retJson, result);
181 public void testgrantVnfResourceByVnfNameIsEmpty() {
183 "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
184 JSONObject vnfObj = JSONObject.fromObject(data);
185 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
186 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
188 JSONObject retJson = new JSONObject();
189 retJson.put("retCode", Constant.REST_FAIL);
190 retJson.put("errorMsg", "basic params error");
191 assertEquals(retJson, result);
195 public void testgrantVnfResourceByVnfIdIsEmpty() {
197 "{\"type\": \"instantiation\",\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
198 JSONObject vnfObj = JSONObject.fromObject(data);
199 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
200 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "", "vnfmId");
202 JSONObject retJson = new JSONObject();
203 retJson.put("retCode", Constant.REST_FAIL);
204 retJson.put("errorMsg", "basic params error");
205 assertEquals(retJson, result);
209 public void testgrantVnfResourceByRequestTypeIsEmpty() {
211 "{\"type\": \"instantiation\",\"operation_right\": \"\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
212 JSONObject vnfObj = JSONObject.fromObject(data);
213 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
214 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
216 JSONObject retJson = new JSONObject();
217 retJson.put("retCode", Constant.REST_FAIL);
218 retJson.put("errorMsg", "basic params error");
219 assertEquals(retJson, result);
223 public void testgrantVnfResourceByJSONException() {
225 "{\"operation_right\": \"increase\",\"vnf_name\": \"vnf_name\",\"vm_list\": [{\"vm_flavor\": {\"storage\": [{\"vol_type\": \"local_volume\",\"vol_size\": \"2\",\"storage_type\": \"local_image\",\"disk_size\": \"100\"}],\"num_cpus\": \"6\",\"mem_size\": \"8\"},\"init_number\": \"1\"}],\"version\": \"version\",\"template_id\": \"template_id\",\"template_name\": \"template_name\",\"plan_id\": \"plan_id\",\"plan_name\": \"plan_name\",\"project_id\": \"project_id\",\"project_name\": \"project_name\",\"creator\": \"creator\",\"status\": \"status\",\"tenant\": \"tenant\",\"parent_tenant\": \"parent_tenant\",\"vnfd_id\": \"vnfd_id\",\"location\": \"location\",\"dr_location\": \"dr_location\",\"nfvo_id\": \"nfvo_id\"}";
226 JSONObject vnfObj = JSONObject.fromObject(data);
227 VnfResourceMgr vnfResourceMgr = new VnfResourceMgr();
228 JSONObject result = vnfResourceMgr.grantVnfResource(vnfObj, "vnfId", "vnfmId");
230 JSONObject retJson = new JSONObject();
231 retJson.put("retCode", Constant.REST_FAIL);
232 retJson.put("errorMsg", "params parse exception");
233 assertEquals(retJson, result);