03f17b3a69a13f5b3bb6099a0edb8df02a933502
[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.openo.nfvo.resmanagement.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.openo.baseservice.remoteservice.exception.ServiceException;
24 import org.openo.nfvo.resmanagement.service.dao.impl.LocationDaoImpl;
25 import org.openo.nfvo.resmanagement.service.entity.LocationEntity;
26
27 import mockit.Mock;
28 import mockit.MockUp;
29
30 public class LocationBusinessImplTest {
31
32     private LocationBusinessImpl locationBusinessImpl;
33
34     @Before
35     public void setUp() throws ServiceException {
36         locationBusinessImpl = new LocationBusinessImpl();
37         locationBusinessImpl.setLocationDao(new LocationDaoImpl());
38     }
39
40     @Test
41     public void testGet() throws ServiceException {
42         new MockUp<LocationDaoImpl>() {
43
44             @Mock
45             public LocationEntity getLocation(String id) {
46                 LocationEntity localEntity = new LocationEntity();
47                 localEntity.setCountry("country");
48                 localEntity.setLocation("location");
49
50                 return localEntity;
51             }
52         };
53         assertTrue(locationBusinessImpl.getLocation("id") != null);
54     }
55
56     @Test
57     public void testGetBranch() throws ServiceException {
58
59         assertTrue(locationBusinessImpl.getLocation("") == null);
60     }
61
62     @Test(expected = ServiceException.class)
63     public void testAddLocationSelectiveExceptio() throws ServiceException {
64         locationBusinessImpl.addLocationSelective(null);
65     }
66
67     @Test
68     public void testAddLocationSelective() throws ServiceException {
69         new MockUp<LocationDaoImpl>() {
70
71             @Mock
72             public int addLocationSelective(LocationEntity locationEntity) {
73                 return 1;
74             }
75         };
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);
84     }
85
86     @Test
87     public void testAddLocationSelectiveBranch() throws ServiceException {
88         new MockUp<LocationDaoImpl>() {
89
90             @Mock
91             public int addLocationSelective(LocationEntity locationEntity) {
92                 return 1;
93             }
94         };
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);
103     }
104
105     @Test
106     public void testAddLocationSelectiveBranch1() throws ServiceException {
107         new MockUp<LocationDaoImpl>() {
108
109             @Mock
110             public int addLocationSelective(LocationEntity locationEntity) {
111                 return 1;
112             }
113         };
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);
122     }
123
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);
134     }
135
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);
146     }
147
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);
158     }
159
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);
170     }
171
172     @Test(expected = ServiceException.class)
173     public void testUpdateLocationSelective() throws ServiceException {
174         locationBusinessImpl.updateLocationSelective(null);
175     }
176
177     @Test(expected = ServiceException.class)
178     public void testAddLocation() throws ServiceException {
179         locationBusinessImpl.addLocation(null);
180     }
181
182     @Test
183     public void testUpdateLocation() throws ServiceException {
184         new MockUp<LocationDaoImpl>() {
185
186             @Mock
187             public int updateLocation(LocationEntity locationEntity) {
188                 return 1;
189             }
190         };
191         locationBusinessImpl.getLocationDao();
192         LocationEntity locationEntity = new LocationEntity();
193         locationEntity.setLatitude("1");
194         locationEntity.setLongitude("2");
195         locationBusinessImpl.updateLocation(locationEntity);
196     }
197
198     @Test(expected = ServiceException.class)
199     public void testUpdateLocationException() throws ServiceException {
200         new MockUp<LocationDaoImpl>() {
201
202             @Mock
203             public int updateLocation(LocationEntity locationEntity) {
204                 return 1;
205             }
206         };
207         locationBusinessImpl.getLocationDao();
208         LocationEntity locationEntity = new LocationEntity();
209         locationEntity.setLatitude("100");
210         locationEntity.setLongitude("2");
211         locationBusinessImpl.updateLocation(locationEntity);
212     }
213
214     @Test(expected = ServiceException.class)
215     public void testUpdateLocationException1() throws ServiceException {
216         locationBusinessImpl.getLocationDao();
217         locationBusinessImpl.updateLocation(null);
218     }
219 }