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.res.service.business.impl;
19 import static org.junit.Assert.assertTrue;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.onap.vfc.nfvo.res.service.business.impl.LocationBusinessImpl;
24 import org.onap.vfc.nfvo.res.service.dao.impl.LocationDaoImpl;
25 import org.onap.vfc.nfvo.res.service.entity.LocationEntity;
26 import org.openo.baseservice.remoteservice.exception.ServiceException;
31 public class LocationBusinessImplTest {
33 private LocationBusinessImpl locationBusinessImpl;
36 public void setUp() throws ServiceException {
37 locationBusinessImpl = new LocationBusinessImpl();
38 locationBusinessImpl.setLocationDao(new LocationDaoImpl());
42 public void testGet() throws ServiceException {
43 new MockUp<LocationDaoImpl>() {
46 public LocationEntity getLocation(String id) {
47 LocationEntity localEntity = new LocationEntity();
48 localEntity.setCountry("country");
49 localEntity.setLocation("location");
54 assertTrue(locationBusinessImpl.getLocation("id") != null);
58 public void testGetBranch() throws ServiceException {
60 assertTrue(locationBusinessImpl.getLocation("") == null);
63 @Test(expected = ServiceException.class)
64 public void testAddLocationSelectiveExceptio() throws ServiceException {
65 locationBusinessImpl.addLocationSelective(null);
69 public void testAddLocationSelective() throws ServiceException {
70 new MockUp<LocationDaoImpl>() {
73 public int addLocationSelective(LocationEntity locationEntity) {
77 LocationEntity locationEntity = new LocationEntity();
78 locationEntity.setCountry("country");
79 locationEntity.setDescription("description");
80 locationEntity.setId("id");
81 locationEntity.setLatitude("1");
82 locationEntity.setLongitude("12");
83 locationEntity.setLocation("location");
84 locationBusinessImpl.addLocationSelective(locationEntity);
88 public void testAddLocationSelectiveBranch() throws ServiceException {
89 new MockUp<LocationDaoImpl>() {
92 public int addLocationSelective(LocationEntity locationEntity) {
96 LocationEntity locationEntity = new LocationEntity();
97 locationEntity.setCountry("country");
98 locationEntity.setDescription("description");
99 locationEntity.setId("");
100 locationEntity.setLatitude("1");
101 locationEntity.setLongitude("12");
102 locationEntity.setLocation("location");
103 locationBusinessImpl.addLocationSelective(locationEntity);
107 public void testAddLocationSelectiveBranch1() throws ServiceException {
108 new MockUp<LocationDaoImpl>() {
111 public int addLocationSelective(LocationEntity locationEntity) {
115 LocationEntity locationEntity = new LocationEntity();
116 locationEntity.setCountry("country");
117 locationEntity.setDescription("description");
118 locationEntity.setId(null);
119 locationEntity.setLatitude("1");
120 locationEntity.setLongitude("12");
121 locationEntity.setLocation("location");
122 locationBusinessImpl.addLocationSelective(locationEntity);
125 @Test(expected = ServiceException.class)
126 public void testAddLocationSelectiveException1() throws ServiceException {
127 LocationEntity locationEntity = new LocationEntity();
128 locationEntity.setCountry("");
129 locationEntity.setDescription("description");
130 locationEntity.setId("id");
131 locationEntity.setLatitude("1");
132 locationEntity.setLongitude("12");
133 locationEntity.setLocation("location");
134 locationBusinessImpl.addLocationSelective(locationEntity);
137 @Test(expected = ServiceException.class)
138 public void testAddLocationSelectiveException2() throws ServiceException {
139 LocationEntity locationEntity = new LocationEntity();
140 locationEntity.setCountry("country");
141 locationEntity.setDescription("description");
142 locationEntity.setId("id");
143 locationEntity.setLatitude("1");
144 locationEntity.setLongitude("12");
145 locationEntity.setLocation("");
146 locationBusinessImpl.addLocationSelective(locationEntity);
149 @Test(expected = ServiceException.class)
150 public void testAddLocationSelectiveException3() throws ServiceException {
151 LocationEntity locationEntity = new LocationEntity();
152 locationEntity.setCountry("country");
153 locationEntity.setDescription("description");
154 locationEntity.setId("id");
155 locationEntity.setLatitude("");
156 locationEntity.setLongitude("12");
157 locationEntity.setLocation("location");
158 locationBusinessImpl.addLocationSelective(locationEntity);
161 @Test(expected = ServiceException.class)
162 public void testAddLocationSelectiveException4() throws ServiceException {
163 LocationEntity locationEntity = new LocationEntity();
164 locationEntity.setCountry("country");
165 locationEntity.setDescription("description");
166 locationEntity.setId("id");
167 locationEntity.setLatitude("1");
168 locationEntity.setLongitude("");
169 locationEntity.setLocation("location");
170 locationBusinessImpl.addLocationSelective(locationEntity);
173 @Test(expected = ServiceException.class)
174 public void testUpdateLocationSelective() throws ServiceException {
175 locationBusinessImpl.updateLocationSelective(null);
178 @Test(expected = ServiceException.class)
179 public void testAddLocation() throws ServiceException {
180 locationBusinessImpl.addLocation(null);
184 public void testUpdateLocation() throws ServiceException {
185 new MockUp<LocationDaoImpl>() {
188 public int updateLocation(LocationEntity locationEntity) {
192 locationBusinessImpl.getLocationDao();
193 LocationEntity locationEntity = new LocationEntity();
194 locationEntity.setLatitude("1");
195 locationEntity.setLongitude("2");
196 locationBusinessImpl.updateLocation(locationEntity);
199 @Test(expected = ServiceException.class)
200 public void testUpdateLocationException() throws ServiceException {
201 new MockUp<LocationDaoImpl>() {
204 public int updateLocation(LocationEntity locationEntity) {
208 locationBusinessImpl.getLocationDao();
209 LocationEntity locationEntity = new LocationEntity();
210 locationEntity.setLatitude("100");
211 locationEntity.setLongitude("2");
212 locationBusinessImpl.updateLocation(locationEntity);
215 @Test(expected = ServiceException.class)
216 public void testUpdateLocationException1() throws ServiceException {
217 locationBusinessImpl.getLocationDao();
218 locationBusinessImpl.updateLocation(null);