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.adapter.impl;
19 import static org.junit.Assert.assertTrue;
21 import java.util.HashMap;
24 import org.junit.Test;
25 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.adapter.impl.AdapterResourceManager;
26 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
28 import org.openo.baseservice.roa.util.restclient.HttpRest;
29 import org.openo.baseservice.roa.util.restclient.RestfulParametes;
30 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
34 import net.sf.json.JSONObject;
36 public class AdapterResourceManagerTest {
38 private AdapterResourceManager adapterResManager;
40 private JSONObject jsonObj;
43 * @Test public void testGetJujuVnfmInfo() throws Exception { Map paramsMap
44 * = new HashMap(); JSONObject resultObj = new JSONObject();
45 * resultObj.put("reason", "RestfulResponse is null.");
46 * resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
48 * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
49 * paramsMap.put("methodType","get");
51 * new MockUp<JujuVnfmRestfulUtil>(){
53 * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str)
54 * { return null; } }; adapterResManager = new AdapterResourceManager();
55 * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
56 * assertEquals(resultObj,jsonObj); }
60 * @Test public void testGetVnfdInfo() throws Exception { Map paramsMap =
61 * new HashMap(); JSONObject resultObj = new JSONObject();
62 * resultObj.put("reason", "RestfulResponse is null.");
63 * resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
65 * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
66 * paramsMap.put("methodType","get");
68 * new MockUp<JujuVnfmRestfulUtil>(){
70 * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str)
71 * { return null; } }; adapterResManager = new AdapterResourceManager();
72 * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
73 * assertEquals(resultObj,jsonObj); }
77 public void getJujuVnfmInfoTest() {
78 new MockUp<HttpRest>() {
80 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
81 RestfulResponse rsp = new RestfulResponse();
86 new MockUp<JSONObject>() {
88 public JSONObject fromObject(Object object) {
89 JSONObject json = new JSONObject();
93 Map<String, String> paramsMap = new HashMap<>();
94 JSONObject resultObj = new JSONObject();
95 resultObj.put("reason", "RestfulResponse is null.");
96 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
98 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
99 paramsMap.put("methodType", "get");
100 adapterResManager = new AdapterResourceManager();
101 jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
102 assertTrue(jsonObj != null);
106 public void getJujuVnfmInfoTest1() {
107 new MockUp<HttpRest>() {
109 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
110 RestfulResponse rsp = new RestfulResponse();
115 new MockUp<JSONObject>() {
117 public JSONObject fromObject(Object object) {
118 JSONObject json = new JSONObject();
122 Map<String, String> paramsMap = new HashMap<>();
123 JSONObject resultObj = new JSONObject();
124 resultObj.put("reason", "RestfulResponse is null.");
125 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
127 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
128 paramsMap.put("methodType", "get");
129 adapterResManager = new AdapterResourceManager();
130 jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap);
131 assertTrue(jsonObj != null);
135 public void getJujuVnfmInfoTestFalse() {
136 Map<String, String> paramsMap = new HashMap<>();
137 JSONObject resultObj = new JSONObject();
138 resultObj.put("reason", "RestfulResponse is null.");
139 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
141 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
142 paramsMap.put("methodType", "get");
143 adapterResManager = new AdapterResourceManager();
144 jsonObj = adapterResManager.getJujuVnfmInfo(null);
145 assertTrue(jsonObj.get("reason").equals("RestfulResponse is null."));
149 public void getVnfdInfoTest() {
150 Map<String, String> paramsMap = new HashMap<>();
151 JSONObject resultObj = new JSONObject();
152 resultObj.put("reason", "RestfulResponse is null.");
153 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
155 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
156 paramsMap.put("methodType", "get");
157 adapterResManager = new AdapterResourceManager();
158 // jsonObj = adapterResManager.getVnfdInfo("1111");
159 // assertTrue(jsonObj.get("reason").equals("RestfulResponse is null."));
163 public void getVnfdInfoTest1() {
164 new MockUp<HttpRest>() {
166 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
167 RestfulResponse rsp = new RestfulResponse();
172 new MockUp<JSONObject>() {
174 public JSONObject fromObject(Object object) {
175 JSONObject json = new JSONObject();
179 Map<String, String> paramsMap = new HashMap<>();
180 JSONObject resultObj = new JSONObject();
181 resultObj.put("reason", "RestfulResponse is null.");
182 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
184 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
185 paramsMap.put("methodType", "get");
186 adapterResManager = new AdapterResourceManager();
187 // jsonObj = adapterResManager.getVnfdInfo("1111");
188 // assertTrue(jsonObj != null);
192 public void getVnfdInfoTest2() {
193 new MockUp<HttpRest>() {
195 RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException {
196 RestfulResponse rsp = new RestfulResponse();
202 Map<String, String> paramsMap = new HashMap<>();
203 JSONObject resultObj = new JSONObject();
204 resultObj.put("reason", "RestfulResponse is null.");
205 resultObj.put("retCode", Constant.ERROR_STATUS_CODE);
207 paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111");
208 paramsMap.put("methodType", "get");
209 adapterResManager = new AdapterResourceManager();
210 // jsonObj = adapterResManager.getVnfdInfo("1111");
211 // assertTrue(jsonObj != null);