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.openo.nfvo.jujuvnfmadapter.service.adapter.impl;
19 import static org.junit.Assert.assertTrue;
21 import java.util.HashMap;
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;
33 import net.sf.json.JSONObject;
35 public class AdapterResourceManagerTest {
37 private AdapterResourceManager adapterResManager;
39 private JSONObject jsonObj;
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);
47 * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
48 * paramsMap.put("methodType","get");
50 * new MockUp<JujuVnfmRestfulUtil>(){
52 * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str)
53 * { return null; } }; adapterResManager = new AdapterResourceManager();
54 * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
55 * assertEquals(resultObj,jsonObj); }
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);
64 * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
65 * paramsMap.put("methodType","get");
67 * new MockUp<JujuVnfmRestfulUtil>(){
69 * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str)
70 * { return null; } }; adapterResManager = new AdapterResourceManager();
71 * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
72 * assertEquals(resultObj,jsonObj); }
76 public void getJujuVnfmInfoTest() {
77 new MockUp<HttpRest>() {
79 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
80 RestfulResponse rsp = new RestfulResponse();
85 new MockUp<JSONObject>() {
87 public JSONObject fromObject(Object object) {
88 JSONObject json = new JSONObject();
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);
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);
105 public void getJujuVnfmInfoTest1() {
106 new MockUp<HttpRest>() {
108 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
109 RestfulResponse rsp = new RestfulResponse();
114 new MockUp<JSONObject>() {
116 public JSONObject fromObject(Object object) {
117 JSONObject json = new JSONObject();
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);
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);
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);
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."));
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);
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."));
162 public void getVnfdInfoTest1() {
163 new MockUp<HttpRest>() {
165 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
166 RestfulResponse rsp = new RestfulResponse();
171 new MockUp<JSONObject>() {
173 public JSONObject fromObject(Object object) {
174 JSONObject json = new JSONObject();
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);
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);
191 public void getVnfdInfoTest2() {
192 new MockUp<HttpRest>() {
194 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
195 RestfulResponse rsp = new RestfulResponse();
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);
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);