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.resmanagement.service.business.impl;
19 import static org.junit.Assert.assertTrue;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.openo.baseservice.remoteservice.exception.ServiceException;
24 import org.openo.nfvo.resmanagement.service.dao.impl.LocationDaoImpl;
25 import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
30 public class LocationBusinessImplTest {
32 private LocationBusinessImpl locationBusinessImpl;
35 public void setUp() throws ServiceException {
36 locationBusinessImpl = new LocationBusinessImpl();
37 locationBusinessImpl.setLocationDao(new LocationDaoImpl());
41 public void testGet() throws ServiceException {
42 new MockUp<LocationDaoImpl>() {
45 public LocationEntity getLocation(String id) {
46 LocationEntity localEntity = new LocationEntity();
47 localEntity.setCountry("country");
48 localEntity.setLocation("location");
53 assertTrue(locationBusinessImpl.getLocation("id") != null);
57 public void testGetBranch() throws ServiceException {
59 assertTrue(locationBusinessImpl.getLocation("") == null);
62 @Test(expected = ServiceException.class)
63 public void testAddLocationSelectiveExceptio() throws ServiceException {
64 locationBusinessImpl.addLocationSelective(null);
68 public void testAddLocationSelective() throws ServiceException {
69 new MockUp<LocationDaoImpl>() {
72 public int addLocationSelective(LocationEntity locationEntity) {
76 LocationEntity locationEntity = new LocationEntity();
77 locationEntity.setCountry("country");
78 locationEntity.setDescription("description");
79 locationEntity.setId("id");
80 locationEntity.setLatitude("1");
81 locationEntity.setLongitude("12");
82 locationEntity.setLocation("location");
83 locationBusinessImpl.addLocationSelective(locationEntity);
87 public void testAddLocationSelectiveBranch() throws ServiceException {
88 new MockUp<LocationDaoImpl>() {
91 public int addLocationSelective(LocationEntity locationEntity) {
95 LocationEntity locationEntity = new LocationEntity();
96 locationEntity.setCountry("country");
97 locationEntity.setDescription("description");
98 locationEntity.setId("");
99 locationEntity.setLatitude("1");
100 locationEntity.setLongitude("12");
101 locationEntity.setLocation("location");
102 locationBusinessImpl.addLocationSelective(locationEntity);
106 public void testAddLocationSelectiveBranch1() throws ServiceException {
107 new MockUp<LocationDaoImpl>() {
110 public int addLocationSelective(LocationEntity locationEntity) {
114 LocationEntity locationEntity = new LocationEntity();
115 locationEntity.setCountry("country");
116 locationEntity.setDescription("description");
117 locationEntity.setId(null);
118 locationEntity.setLatitude("1");
119 locationEntity.setLongitude("12");
120 locationEntity.setLocation("location");
121 locationBusinessImpl.addLocationSelective(locationEntity);
124 @Test(expected = ServiceException.class)
125 public void testAddLocationSelectiveException1() throws ServiceException {
126 LocationEntity locationEntity = new LocationEntity();
127 locationEntity.setCountry("");
128 locationEntity.setDescription("description");
129 locationEntity.setId("id");
130 locationEntity.setLatitude("1");
131 locationEntity.setLongitude("12");
132 locationEntity.setLocation("location");
133 locationBusinessImpl.addLocationSelective(locationEntity);
136 @Test(expected = ServiceException.class)
137 public void testAddLocationSelectiveException2() throws ServiceException {
138 LocationEntity locationEntity = new LocationEntity();
139 locationEntity.setCountry("country");
140 locationEntity.setDescription("description");
141 locationEntity.setId("id");
142 locationEntity.setLatitude("1");
143 locationEntity.setLongitude("12");
144 locationEntity.setLocation("");
145 locationBusinessImpl.addLocationSelective(locationEntity);
148 @Test(expected = ServiceException.class)
149 public void testAddLocationSelectiveException3() throws ServiceException {
150 LocationEntity locationEntity = new LocationEntity();
151 locationEntity.setCountry("country");
152 locationEntity.setDescription("description");
153 locationEntity.setId("id");
154 locationEntity.setLatitude("");
155 locationEntity.setLongitude("12");
156 locationEntity.setLocation("location");
157 locationBusinessImpl.addLocationSelective(locationEntity);
160 @Test(expected = ServiceException.class)
161 public void testAddLocationSelectiveException4() throws ServiceException {
162 LocationEntity locationEntity = new LocationEntity();
163 locationEntity.setCountry("country");
164 locationEntity.setDescription("description");
165 locationEntity.setId("id");
166 locationEntity.setLatitude("1");
167 locationEntity.setLongitude("");
168 locationEntity.setLocation("location");
169 locationBusinessImpl.addLocationSelective(locationEntity);
172 @Test(expected = ServiceException.class)
173 public void testUpdateLocationSelective() throws ServiceException {
174 locationBusinessImpl.updateLocationSelective(null);
177 @Test(expected = ServiceException.class)
178 public void testAddLocation() throws ServiceException {
179 locationBusinessImpl.addLocation(null);
183 public void testUpdateLocation() throws ServiceException {
184 new MockUp<LocationDaoImpl>() {
187 public int updateLocation(LocationEntity locationEntity) {
191 locationBusinessImpl.getLocationDao();
192 LocationEntity locationEntity = new LocationEntity();
193 locationEntity.setLatitude("1");
194 locationEntity.setLongitude("2");
195 locationBusinessImpl.updateLocation(locationEntity);
198 @Test(expected = ServiceException.class)
199 public void testUpdateLocationException() throws ServiceException {
200 new MockUp<LocationDaoImpl>() {
203 public int updateLocation(LocationEntity locationEntity) {
207 locationBusinessImpl.getLocationDao();
208 LocationEntity locationEntity = new LocationEntity();
209 locationEntity.setLatitude("100");
210 locationEntity.setLongitude("2");
211 locationBusinessImpl.updateLocation(locationEntity);
214 @Test(expected = ServiceException.class)
215 public void testUpdateLocationException1() throws ServiceException {
216 locationBusinessImpl.getLocationDao();
217 locationBusinessImpl.updateLocation(null);