2 * Copyright 2016 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.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest;
19 import static org.junit.Assert.assertNotNull;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.StringUtil;
27 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException;
28 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.entity.JujuVnfmInfo;
29 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.process.VnfMgr;
30 import org.springframework.mock.web.MockHttpServletResponse;
34 import net.sf.json.JSONObject;
36 public class VnfRoaTest {
38 VnfRoa roa = new VnfRoa();
42 roa.setVnfMgr(new VnfMgr());
46 public void addVnfTestNull() throws ServiceException {
47 new MockUp<StringUtil>() {
50 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
54 HttpServletRequest context = null;
55 HttpServletResponse resp = new MockHttpServletResponse();
56 String vnfmId = "1234";
57 String res = roa.addVnf(context, resp, vnfmId);
62 public void addVnfTest() throws ServiceException {
63 new MockUp<StringUtil>() {
66 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
67 String vnfJsonStr = "{}";
68 return (T)JSONObject.fromObject(vnfJsonStr);
71 new MockUp<VnfMgr>() {
74 public JSONObject addVnf(JSONObject vnfObject, String vnfmId) {
75 JSONObject result = new JSONObject();
76 result.put("retCode", -1);
80 HttpServletRequest context = null;
81 HttpServletResponse resp = new MockHttpServletResponse();
82 String vnfmId = "1234";
83 String res = roa.addVnf(context, resp, vnfmId);
88 public void addVnfTestSucce() throws ServiceException {
89 new MockUp<StringUtil>() {
92 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
93 String vnfJsonStr = "{}";
94 return (T)JSONObject.fromObject(vnfJsonStr);
97 new MockUp<VnfMgr>() {
100 public JSONObject addVnf(JSONObject vnfObject, String vnfmId) {
101 JSONObject result = new JSONObject();
102 result.put("retCode", 1);
103 JSONObject data = new JSONObject();
104 data.put("result", "success");
105 result.put("data", data);
109 HttpServletRequest context = null;
110 HttpServletResponse resp = new MockHttpServletResponse();
111 String vnfmId = "1234";
112 String res = roa.addVnf(context, resp, vnfmId);
117 public void delVnfTestNull() throws ServiceException {
118 new MockUp<StringUtil>() {
121 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
125 new MockUp<VnfMgr>() {
128 private JujuVnfmInfo findByVnfId(String vnfId) {
129 JujuVnfmInfo info = new JujuVnfmInfo();
130 info.setVnfmId("1234");
134 HttpServletRequest context = null;
135 HttpServletResponse resp = new MockHttpServletResponse();
136 String vnfmId = "1234";
137 String res = roa.delVnf("vnfmId", resp, "vnfInstanceId", context);
142 public void delVnf2TestNull() throws ServiceException {
143 new MockUp<StringUtil>() {
146 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
150 HttpServletRequest context = null;
151 HttpServletResponse resp = new MockHttpServletResponse();
152 String vnfmId = "1234";
153 String res = roa.delVnf(null, resp, "vnfInstanceId", context);
158 public void delVnf3TestNull() throws ServiceException {
159 new MockUp<StringUtil>() {
162 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
166 HttpServletRequest context = null;
167 HttpServletResponse resp = new MockHttpServletResponse();
168 String vnfmId = "1234";
169 String res = roa.delVnf(vnfmId, resp, null, context);
174 public void delVnfSuccess() throws ServiceException {
175 new MockUp<StringUtil>() {
178 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
182 new MockUp<VnfMgr>() {
185 public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
186 JSONObject result = new JSONObject();
187 result.put("retCode", 1);
188 JSONObject data = new JSONObject();
189 data.put("result", "success");
190 result.put("data", data);
194 HttpServletRequest context = null;
195 HttpServletResponse resp = new MockHttpServletResponse();
196 String vnfmId = "1234";
197 String res = roa.delVnf(vnfmId, resp, "vnfInstanceId", context);
202 public void delVnfFail() throws ServiceException {
203 new MockUp<StringUtil>() {
206 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
210 new MockUp<VnfMgr>() {
213 public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
214 JSONObject result = new JSONObject();
215 result.put("retCode", -1);
219 HttpServletRequest context = null;
220 HttpServletResponse resp = new MockHttpServletResponse();
221 String vnfmId = "1234";
222 String res = roa.delVnf(null, resp, "vnfInstanceId", context);
227 public void getVnf1TestNull() throws ServiceException {
228 new MockUp<StringUtil>() {
231 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
235 new MockUp<VnfMgr>() {
238 private JujuVnfmInfo findByVnfId(String vnfId) {
239 JujuVnfmInfo info = new JujuVnfmInfo();
240 info.setVnfmId("1234");
244 HttpServletRequest context = null;
245 HttpServletResponse resp = new MockHttpServletResponse();
246 String vnfmId = "1234";
247 String res = roa.getVnf(vnfmId, resp, "vnfInstanceId", context);
252 public void getVnfSuccess() throws ServiceException {
253 new MockUp<StringUtil>() {
256 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
260 new MockUp<VnfMgr>() {
263 public JSONObject getVnf(String vnfId, String vnfmId) {
264 JSONObject result = new JSONObject();
265 result.put("retCode", 1);
266 JSONObject data = new JSONObject();
267 data.put("result", "success");
268 result.put("data", data);
272 HttpServletRequest context = null;
273 HttpServletResponse resp = new MockHttpServletResponse();
274 String vnfmId = "1234";
275 String res = roa.getVnf(vnfmId, resp, "vnfInstanceId", context);
280 public void getVnfFail() throws ServiceException {
281 new MockUp<StringUtil>() {
284 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
288 new MockUp<VnfMgr>() {
291 public JSONObject getVnf(String vnfId, String vnfmId) {
292 JSONObject result = new JSONObject();
293 result.put("retCode", -1);
297 HttpServletRequest context = null;
298 HttpServletResponse resp = new MockHttpServletResponse();
299 String vnfmId = "1234";
300 String res = roa.getVnf(vnfmId, resp, "vnfInstanceId", context);
305 public void getVnf2TestNull() throws ServiceException {
306 new MockUp<StringUtil>() {
309 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
313 HttpServletRequest context = null;
314 HttpServletResponse resp = new MockHttpServletResponse();
315 String vnfmId = "1234";
316 String res = roa.getVnf(null, resp, "vnfInstanceId", context);
321 public void getVnf3TestNull() throws ServiceException {
322 new MockUp<StringUtil>() {
325 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
329 HttpServletRequest context = null;
330 HttpServletResponse resp = new MockHttpServletResponse();
331 String vnfmId = "1234";
332 String res = roa.getVnf(vnfmId, resp, null, context);
337 public void getJobTestNull() throws ServiceException {
338 HttpServletResponse resp = new MockHttpServletResponse();
339 String res = roa.getJob("jobId", "vnfmId", resp, "responseId");
344 public void getJobTest2Null() throws ServiceException {
345 HttpServletResponse resp = new MockHttpServletResponse();
346 String res = roa.getJob(null, "vnfmId", resp, "responseId");
351 public void getJobTest3Null() throws ServiceException {
352 HttpServletResponse resp = new MockHttpServletResponse();
353 String res = roa.getJob("jobId", null, resp, "responseId");
358 public void getJobTestNormal() throws ServiceException {
359 new MockUp<VnfMgr>() {
362 public JSONObject getJob(String jobId, String vnfmId) {
363 JSONObject obj = new JSONObject();
364 JSONObject dataObj = new JSONObject();
365 dataObj.put("id", "1234");
366 dataObj.put("status", "Success");
367 obj.put("data", dataObj);
368 obj.put("retCode", 1);
373 HttpServletResponse resp = new MockHttpServletResponse();
374 String res = roa.getJob("jobId", "vnfmId", resp, "responseId");