2 * Copyright 2017 Huawei Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.vfc.nfvo.resmanagement.service.rest;
\r
19 import static org.junit.Assert.assertNotNull;
\r
21 import java.util.ArrayList;
\r
22 import java.util.List;
\r
23 import java.util.Map;
\r
25 import javax.servlet.http.HttpServletRequest;
\r
27 import org.junit.Before;
\r
28 import org.junit.Test;
\r
29 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
\r
30 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.LocationImpl;
\r
31 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl;
\r
32 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Location;
\r
33 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites;
\r
34 import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity;
\r
35 import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity;
\r
36 import org.onap.vfc.nfvo.resmanagement.service.rest.LocationRoa;
\r
37 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
\r
38 import org.springframework.mock.web.MockHttpServletRequest;
\r
41 import mockit.MockUp;
\r
42 import net.sf.json.JSONObject;
\r
50 * @version NFVO 0.5 Feb 9, 2017
\r
52 public class LocationRoaTest {
\r
54 private LocationRoa roa;
\r
56 private Location location;
\r
58 private Sites sites;
\r
61 public void setUp() {
\r
62 roa = new LocationRoa();
\r
63 location = new LocationImpl();
\r
64 sites = new SitesImpl();
\r
65 roa.setLocation(location);
\r
66 roa.setSites(sites);
\r
70 public void testGetLocationsbase() throws ServiceException {
\r
71 new MockUp<LocationImpl>() {
\r
74 public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
\r
75 return new ArrayList<LocationEntity>();
\r
78 HttpServletRequest mock = new MockHttpServletRequest();
\r
79 JSONObject result = roa.getLocationsbase(mock);
\r
80 assertNotNull(result);
\r
84 public void testGetLocationbase() throws ServiceException {
\r
85 new MockUp<LocationImpl>() {
\r
88 public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
\r
89 return new ArrayList<LocationEntity>();
\r
92 HttpServletRequest mock = new MockHttpServletRequest();
\r
93 JSONObject result = roa.getLocationbase(mock, "id");
\r
94 assertNotNull(result);
\r
98 public void testGetCountry() throws ServiceException {
\r
99 new MockUp<LocationImpl>() {
\r
102 public List<String> getCountry() throws ServiceException {
\r
103 return new ArrayList<String>();
\r
106 HttpServletRequest mock = new MockHttpServletRequest();
\r
107 JSONObject result = roa.getCountry(mock);
\r
108 assertNotNull(result);
\r
112 public void testGetLocationByCountry() throws ServiceException {
\r
113 new MockUp<LocationImpl>() {
\r
116 public List<String> getLocationByCountry(Map<String, Object> condition) throws ServiceException {
\r
117 return new ArrayList<String>();
\r
120 HttpServletRequest mock = new MockHttpServletRequest();
\r
121 JSONObject result = roa.getLocationByCountry(mock, "country");
\r
122 assertNotNull(result);
\r
126 public void testGetLocation() throws ServiceException {
\r
127 new MockUp<LocationImpl>() {
\r
130 public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
\r
131 return new ArrayList<LocationEntity>();
\r
135 public List<JSONObject> getLocationInfo(List<LocationEntity> locationInfo) throws ServiceException {
\r
136 return new ArrayList<JSONObject>();
\r
139 HttpServletRequest mock = new MockHttpServletRequest();
\r
140 JSONObject result = roa.getLocation(mock, "locations");
\r
141 assertNotNull(result);
\r
145 public void testAddLocation() throws ServiceException {
\r
146 new MockUp<RequestUtil>() {
\r
149 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
150 return new JSONObject();
\r
153 new MockUp<LocationImpl>() {
\r
156 public int add(JSONObject jsonObject) throws ServiceException {
\r
160 HttpServletRequest mock = new MockHttpServletRequest();
\r
161 JSONObject result = roa.addLocation(mock);
\r
162 assertNotNull(result);
\r
166 public void testAddLocationByException() throws ServiceException {
\r
167 new MockUp<RequestUtil>() {
\r
170 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
171 return new JSONObject();
\r
174 new MockUp<LocationImpl>() {
\r
177 public int add(JSONObject jsonObject) throws ServiceException {
\r
178 throw new ServiceException();
\r
181 HttpServletRequest mock = new MockHttpServletRequest();
\r
182 JSONObject result = roa.addLocation(mock);
\r
183 assertNotNull(result);
\r
187 public void testDeleteLocationbase() throws ServiceException {
\r
188 new MockUp<LocationImpl>() {
\r
191 public int delete(String location) throws ServiceException {
\r
195 HttpServletRequest mock = new MockHttpServletRequest();
\r
196 JSONObject result = roa.deleteLocationbase(mock, "locations");
\r
197 assertNotNull(result);
\r
201 public void testDeleteLocationbaseByException() throws ServiceException {
\r
202 new MockUp<LocationImpl>() {
\r
205 public int delete(String location) throws ServiceException {
\r
206 throw new ServiceException();
\r
209 HttpServletRequest mock = new MockHttpServletRequest();
\r
210 JSONObject result = roa.deleteLocationbase(mock, "locations");
\r
211 assertNotNull(result);
\r
215 public void testDeleteLocation() throws ServiceException {
\r
216 new MockUp<RequestUtil>() {
\r
219 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
220 JSONObject object = new JSONObject();
\r
221 object.put("location", "location");
\r
222 object.put("id", "id");
\r
226 new MockUp<SitesImpl>() {
\r
229 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
233 new MockUp<LocationImpl>() {
\r
236 public int delete(String location) throws ServiceException {
\r
240 HttpServletRequest mock = new MockHttpServletRequest();
\r
241 JSONObject result = roa.deleteLocation(mock);
\r
242 assertNotNull(result);
\r
246 public void testDeleteLocationByException() throws ServiceException {
\r
247 new MockUp<RequestUtil>() {
\r
250 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
251 JSONObject object = new JSONObject();
\r
252 object.put("location", "location");
\r
253 object.put("id", "id");
\r
257 new MockUp<SitesImpl>() {
\r
260 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
264 new MockUp<LocationImpl>() {
\r
267 public int delete(String location) throws ServiceException {
\r
268 throw new ServiceException();
\r
271 HttpServletRequest mock = new MockHttpServletRequest();
\r
272 JSONObject result = roa.deleteLocation(mock);
\r
273 assertNotNull(result);
\r
277 public void testDeleteLocationBySitesEntity() throws ServiceException {
\r
278 new MockUp<RequestUtil>() {
\r
281 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
282 JSONObject object = new JSONObject();
\r
283 object.put("location", "location");
\r
284 object.put("id", "id");
\r
288 new MockUp<SitesImpl>() {
\r
291 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
292 return new SitesEntity();
\r
295 HttpServletRequest mock = new MockHttpServletRequest();
\r
296 JSONObject result = roa.deleteLocation(mock);
\r
297 assertNotNull(result);
\r
301 public void testUpdateLocation() throws ServiceException {
\r
302 new MockUp<RequestUtil>() {
\r
305 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
306 JSONObject object = new JSONObject();
\r
307 object.put("location", "location");
\r
311 new MockUp<SitesImpl>() {
\r
314 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
318 new MockUp<LocationImpl>() {
\r
321 public int update(JSONObject jsonObject) throws ServiceException {
\r
325 HttpServletRequest mock = new MockHttpServletRequest();
\r
326 JSONObject result = roa.updateLocation(mock);
\r
327 assertNotNull(result);
\r
331 public void testUpdateLocationByException() throws ServiceException {
\r
332 new MockUp<RequestUtil>() {
\r
335 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
336 JSONObject object = new JSONObject();
\r
337 object.put("location", "location");
\r
341 new MockUp<SitesImpl>() {
\r
344 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
348 new MockUp<LocationImpl>() {
\r
351 public int update(JSONObject jsonObject) throws ServiceException {
\r
352 throw new ServiceException();
\r
355 HttpServletRequest mock = new MockHttpServletRequest();
\r
356 JSONObject result = roa.updateLocation(mock);
\r
357 assertNotNull(result);
\r
361 public void testUpdateLocationBySitesEntity() throws ServiceException {
\r
362 new MockUp<RequestUtil>() {
\r
365 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
366 JSONObject object = new JSONObject();
\r
367 object.put("location", "location");
\r
371 new MockUp<SitesImpl>() {
\r
374 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
375 return new SitesEntity();
\r
378 new MockUp<LocationImpl>() {
\r
381 public int update(JSONObject jsonObject) throws ServiceException {
\r
385 HttpServletRequest mock = new MockHttpServletRequest();
\r
386 JSONObject result = roa.updateLocation(mock);
\r
387 assertNotNull(result);
\r