35126cd2b252a58bbda609503abaef7614287858
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.res.service.business.impl;
18
19 import static org.junit.Assert.assertTrue;
20
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;
27
28 import mockit.Mock;
29 import mockit.MockUp;
30
31 public class LocationBusinessImplTest {
32
33     private LocationBusinessImpl locationBusinessImpl;
34
35     @Before
36     public void setUp() throws ServiceException {
37         locationBusinessImpl = new LocationBusinessImpl();
38         locationBusinessImpl.setLocationDao(new LocationDaoImpl());
39     }
40
41     @Test
42     public void testGet() throws ServiceException {
43         new MockUp<LocationDaoImpl>() {
44
45             @Mock
46             public LocationEntity getLocation(String id) {
47                 LocationEntity localEntity = new LocationEntity();
48                 localEntity.setCountry("country");
49                 localEntity.setLocation("location");
50
51                 return localEntity;
52             }
53         };
54         assertTrue(locationBusinessImpl.getLocation("id") != null);
55     }
56
57     @Test
58     public void testGetBranch() throws ServiceException {
59
60         assertTrue(locationBusinessImpl.getLocation("") == null);
61     }
62
63     @Test(expected = ServiceException.class)
64     public void testAddLocationSelectiveExceptio() throws ServiceException {
65         locationBusinessImpl.addLocationSelective(null);
66     }
67
68     @Test
69     public void testAddLocationSelective() throws ServiceException {
70         new MockUp<LocationDaoImpl>() {
71
72             @Mock
73             public int addLocationSelective(LocationEntity locationEntity) {
74                 return 1;
75             }
76         };
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);
85     }
86
87     @Test
88     public void testAddLocationSelectiveBranch() throws ServiceException {
89         new MockUp<LocationDaoImpl>() {
90
91             @Mock
92             public int addLocationSelective(LocationEntity locationEntity) {
93                 return 1;
94             }
95         };
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);
104     }
105
106     @Test
107     public void testAddLocationSelectiveBranch1() throws ServiceException {
108         new MockUp<LocationDaoImpl>() {
109
110             @Mock
111             public int addLocationSelective(LocationEntity locationEntity) {
112                 return 1;
113             }
114         };
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);
123     }
124
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);
135     }
136
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);
147     }
148
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);
159     }
160
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);
171     }
172
173     @Test(expected = ServiceException.class)
174     public void testUpdateLocationSelective() throws ServiceException {
175         locationBusinessImpl.updateLocationSelective(null);
176     }
177
178     @Test(expected = ServiceException.class)
179     public void testAddLocation() throws ServiceException {
180         locationBusinessImpl.addLocation(null);
181     }
182
183     @Test
184     public void testUpdateLocation() throws ServiceException {
185         new MockUp<LocationDaoImpl>() {
186
187             @Mock
188             public int updateLocation(LocationEntity locationEntity) {
189                 return 1;
190             }
191         };
192         locationBusinessImpl.getLocationDao();
193         LocationEntity locationEntity = new LocationEntity();
194         locationEntity.setLatitude("1");
195         locationEntity.setLongitude("2");
196         locationBusinessImpl.updateLocation(locationEntity);
197     }
198
199     @Test(expected = ServiceException.class)
200     public void testUpdateLocationException() throws ServiceException {
201         new MockUp<LocationDaoImpl>() {
202
203             @Mock
204             public int updateLocation(LocationEntity locationEntity) {
205                 return 1;
206             }
207         };
208         locationBusinessImpl.getLocationDao();
209         LocationEntity locationEntity = new LocationEntity();
210         locationEntity.setLatitude("100");
211         locationEntity.setLongitude("2");
212         locationBusinessImpl.updateLocation(locationEntity);
213     }
214
215     @Test(expected = ServiceException.class)
216     public void testUpdateLocationException1() throws ServiceException {
217         locationBusinessImpl.getLocationDao();
218         locationBusinessImpl.updateLocation(null);
219     }
220 }