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.openo.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.openo.baseservice.remoteservice.exception.ServiceException;
\r
30 import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
\r
31 import org.openo.nfvo.resmanagement.service.base.openstack.impl.LocationImpl;
\r
32 import org.openo.nfvo.resmanagement.service.base.openstack.impl.SitesImpl;
\r
33 import org.openo.nfvo.resmanagement.service.base.openstack.inf.Location;
\r
34 import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites;
\r
35 import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
\r
36 import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
\r
37 import org.springframework.mock.web.MockHttpServletRequest;
\r
40 import mockit.MockUp;
\r
41 import net.sf.json.JSONObject;
\r
49 * @version NFVO 0.5 Feb 9, 2017
\r
51 public class LocationRoaTest {
\r
53 private LocationRoa roa;
\r
55 private Location location;
\r
57 private Sites sites;
\r
60 public void setUp() {
\r
61 roa = new LocationRoa();
\r
62 location = new LocationImpl();
\r
63 sites = new SitesImpl();
\r
64 roa.setLocation(location);
\r
65 roa.setSites(sites);
\r
69 public void testGetLocationsbase() throws ServiceException {
\r
70 new MockUp<LocationImpl>() {
\r
73 public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
\r
74 return new ArrayList<LocationEntity>();
\r
77 HttpServletRequest mock = new MockHttpServletRequest();
\r
78 JSONObject result = roa.getLocationsbase(mock);
\r
79 assertNotNull(result);
\r
83 public void testGetLocationbase() throws ServiceException {
\r
84 new MockUp<LocationImpl>() {
\r
87 public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
\r
88 return new ArrayList<LocationEntity>();
\r
91 HttpServletRequest mock = new MockHttpServletRequest();
\r
92 JSONObject result = roa.getLocationbase(mock, "id");
\r
93 assertNotNull(result);
\r
97 public void testGetCountry() throws ServiceException {
\r
98 new MockUp<LocationImpl>() {
\r
101 public List<String> getCountry() throws ServiceException {
\r
102 return new ArrayList<String>();
\r
105 HttpServletRequest mock = new MockHttpServletRequest();
\r
106 JSONObject result = roa.getCountry(mock);
\r
107 assertNotNull(result);
\r
111 public void testGetLocationByCountry() throws ServiceException {
\r
112 new MockUp<LocationImpl>() {
\r
115 public List<String> getLocationByCountry(Map<String, Object> condition) throws ServiceException {
\r
116 return new ArrayList<String>();
\r
119 HttpServletRequest mock = new MockHttpServletRequest();
\r
120 JSONObject result = roa.getLocationByCountry(mock, "country");
\r
121 assertNotNull(result);
\r
125 public void testGetLocation() throws ServiceException {
\r
126 new MockUp<LocationImpl>() {
\r
129 public List<LocationEntity> get(Map<String, Object> condition) throws ServiceException {
\r
130 return new ArrayList<LocationEntity>();
\r
134 public List<JSONObject> getLocationInfo(List<LocationEntity> locationInfo) throws ServiceException {
\r
135 return new ArrayList<JSONObject>();
\r
138 HttpServletRequest mock = new MockHttpServletRequest();
\r
139 JSONObject result = roa.getLocation(mock, "locations");
\r
140 assertNotNull(result);
\r
144 public void testAddLocation() throws ServiceException {
\r
145 new MockUp<RequestUtil>() {
\r
148 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
149 return new JSONObject();
\r
152 new MockUp<LocationImpl>() {
\r
155 public int add(JSONObject jsonObject) throws ServiceException {
\r
159 HttpServletRequest mock = new MockHttpServletRequest();
\r
160 JSONObject result = roa.addLocation(mock);
\r
161 assertNotNull(result);
\r
165 public void testAddLocationByException() throws ServiceException {
\r
166 new MockUp<RequestUtil>() {
\r
169 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
170 return new JSONObject();
\r
173 new MockUp<LocationImpl>() {
\r
176 public int add(JSONObject jsonObject) throws ServiceException {
\r
177 throw new ServiceException();
\r
180 HttpServletRequest mock = new MockHttpServletRequest();
\r
181 JSONObject result = roa.addLocation(mock);
\r
182 assertNotNull(result);
\r
186 public void testDeleteLocationbase() throws ServiceException {
\r
187 new MockUp<LocationImpl>() {
\r
190 public int delete(String location) throws ServiceException {
\r
194 HttpServletRequest mock = new MockHttpServletRequest();
\r
195 JSONObject result = roa.deleteLocationbase(mock, "locations");
\r
196 assertNotNull(result);
\r
200 public void testDeleteLocationbaseByException() throws ServiceException {
\r
201 new MockUp<LocationImpl>() {
\r
204 public int delete(String location) throws ServiceException {
\r
205 throw new ServiceException();
\r
208 HttpServletRequest mock = new MockHttpServletRequest();
\r
209 JSONObject result = roa.deleteLocationbase(mock, "locations");
\r
210 assertNotNull(result);
\r
214 public void testDeleteLocation() throws ServiceException {
\r
215 new MockUp<RequestUtil>() {
\r
218 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
219 JSONObject object = new JSONObject();
\r
220 object.put("location", "location");
\r
221 object.put("id", "id");
\r
225 new MockUp<SitesImpl>() {
\r
228 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
232 new MockUp<LocationImpl>() {
\r
235 public int delete(String location) throws ServiceException {
\r
239 HttpServletRequest mock = new MockHttpServletRequest();
\r
240 JSONObject result = roa.deleteLocation(mock);
\r
241 assertNotNull(result);
\r
245 public void testDeleteLocationByException() throws ServiceException {
\r
246 new MockUp<RequestUtil>() {
\r
249 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
250 JSONObject object = new JSONObject();
\r
251 object.put("location", "location");
\r
252 object.put("id", "id");
\r
256 new MockUp<SitesImpl>() {
\r
259 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
263 new MockUp<LocationImpl>() {
\r
266 public int delete(String location) throws ServiceException {
\r
267 throw new ServiceException();
\r
270 HttpServletRequest mock = new MockHttpServletRequest();
\r
271 JSONObject result = roa.deleteLocation(mock);
\r
272 assertNotNull(result);
\r
276 public void testDeleteLocationBySitesEntity() throws ServiceException {
\r
277 new MockUp<RequestUtil>() {
\r
280 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
281 JSONObject object = new JSONObject();
\r
282 object.put("location", "location");
\r
283 object.put("id", "id");
\r
287 new MockUp<SitesImpl>() {
\r
290 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
291 return new SitesEntity();
\r
294 HttpServletRequest mock = new MockHttpServletRequest();
\r
295 JSONObject result = roa.deleteLocation(mock);
\r
296 assertNotNull(result);
\r
300 public void testUpdateLocation() throws ServiceException {
\r
301 new MockUp<RequestUtil>() {
\r
304 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
305 JSONObject object = new JSONObject();
\r
306 object.put("location", "location");
\r
310 new MockUp<SitesImpl>() {
\r
313 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
317 new MockUp<LocationImpl>() {
\r
320 public int update(JSONObject jsonObject) throws ServiceException {
\r
324 HttpServletRequest mock = new MockHttpServletRequest();
\r
325 JSONObject result = roa.updateLocation(mock);
\r
326 assertNotNull(result);
\r
330 public void testUpdateLocationByException() throws ServiceException {
\r
331 new MockUp<RequestUtil>() {
\r
334 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
335 JSONObject object = new JSONObject();
\r
336 object.put("location", "location");
\r
340 new MockUp<SitesImpl>() {
\r
343 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
347 new MockUp<LocationImpl>() {
\r
350 public int update(JSONObject jsonObject) throws ServiceException {
\r
351 throw new ServiceException();
\r
354 HttpServletRequest mock = new MockHttpServletRequest();
\r
355 JSONObject result = roa.updateLocation(mock);
\r
356 assertNotNull(result);
\r
360 public void testUpdateLocationBySitesEntity() throws ServiceException {
\r
361 new MockUp<RequestUtil>() {
\r
364 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
365 JSONObject object = new JSONObject();
\r
366 object.put("location", "location");
\r
370 new MockUp<SitesImpl>() {
\r
373 public SitesEntity get(Map<String, Object> condition) throws ServiceException {
\r
374 return new SitesEntity();
\r
377 new MockUp<LocationImpl>() {
\r
380 public int update(JSONObject jsonObject) throws ServiceException {
\r
384 HttpServletRequest mock = new MockHttpServletRequest();
\r
385 JSONObject result = roa.updateLocation(mock);
\r
386 assertNotNull(result);
\r