1e35569d23ea905a24eac63c759c0f7330502ac3
[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.assertEquals;
20 import static org.junit.Assert.assertTrue;
21
22 import java.util.List;
23
24 import org.junit.Test;
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
26 import org.openo.nfvo.resmanagement.service.dao.impl.VimDaoImpl;
27 import org.openo.nfvo.resmanagement.service.entity.VimEntity;
28
29 import mockit.Mock;
30 import mockit.MockUp;
31
32 /**
33  * <br/>
34  * <p>
35  * </p>
36  *
37  * @author
38  * @version NFVO 0.5 2016年8月18日
39  */
40 public class VimBusinessImplTest {
41
42     @Test
43     public void testGetVimIdIsNull() {
44         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
45         vimBusinessImpl.setVimDao(new VimDaoImpl());
46         VimEntity result = vimBusinessImpl.getVim(null);
47         VimEntity expectedResult = null;
48         assertEquals(expectedResult, result);
49     }
50
51     @Test
52     public void testGetVim() {
53         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
54         vimBusinessImpl.setVimDao(new VimDaoImpl());
55         VimEntity vimEntity = new VimEntity();
56         vimEntity.setId("123");
57         new MockUp<VimDaoImpl>() {
58
59             @Mock
60             public VimEntity getVim(String id) {
61                 VimEntity vimEntity = new VimEntity();
62                 vimEntity.setId("123");
63                 return vimEntity;
64             }
65         };
66         VimEntity result = vimBusinessImpl.getVim("id");
67         VimEntity expectedResult = vimEntity;
68         assertEquals(expectedResult.toString(), result.toString());
69     }
70
71     @Test
72     public void testGetVims() throws ServiceException {
73         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
74         vimBusinessImpl.setVimDao(new VimDaoImpl());
75         new MockUp<VimDaoImpl>() {
76
77             @Mock
78             public List<VimEntity> getVims() {
79                 return null;
80             }
81         };
82         List<VimEntity> result = vimBusinessImpl.getVims();
83         List<VimEntity> expectedResult = null;
84         assertEquals(expectedResult, result);
85     }
86
87     @Test
88     public void testDeleteVimEmpty() throws ServiceException {
89         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
90         vimBusinessImpl.setVimDao(new VimDaoImpl());
91         try {
92             vimBusinessImpl.deleteVim("");
93         } catch (ServiceException e) {
94             assertTrue(true);
95         }
96     }
97
98     @Test
99     public void testDeleteVim() throws ServiceException {
100         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
101         vimBusinessImpl.setVimDao(new VimDaoImpl());
102         new MockUp<VimDaoImpl>() {
103
104             @Mock
105             public int deleteVim(String id) {
106                 return 1;
107             }
108         };
109         int result = vimBusinessImpl.deleteVim("xian");
110         int expectedResult = 1;
111         assertEquals(expectedResult, result);
112     }
113
114     @Test
115     public void testAddVimExceptions() throws ServiceException {
116         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
117         vimBusinessImpl.setVimDao(new VimDaoImpl());
118         try {
119             vimBusinessImpl.addVim(null);
120         } catch (ServiceException e) {
121             assertTrue(true);
122         }
123     }
124
125     @Test
126     public void testAddVimExceptions1() throws ServiceException {
127         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
128         vimBusinessImpl.setVimDao(new VimDaoImpl());
129         new MockUp<VimDaoImpl>() {
130
131             @Mock
132             public VimEntity getVim(String id) {
133                 return new VimEntity();
134             }
135         };
136         try {
137             vimBusinessImpl.addVim("id");
138         } catch (ServiceException e) {
139             assertTrue(true);
140         }
141     }
142
143     @Test
144     public void testAddVimExceptions2() throws ServiceException {
145         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
146         vimBusinessImpl.setVimDao(new VimDaoImpl());
147         VimEntity vimEntity = new VimEntity();
148         vimEntity.setId("123");
149         try {
150             vimBusinessImpl.addVim("");
151         } catch (ServiceException e) {
152             assertTrue(true);
153         }
154     }
155
156     @Test
157     public void testAddVim() throws ServiceException {
158         VimBusinessImpl vimBusinessImpl = new VimBusinessImpl();
159         vimBusinessImpl.setVimDao(new VimDaoImpl());
160         new MockUp<VimDaoImpl>() {
161
162             @Mock
163             public VimEntity getVim(String id) {
164                 return null;
165             }
166
167             @Mock
168             public int addVim(VimEntity vimEntity) {
169                 return 1;
170             }
171         };
172         int result = vimBusinessImpl.addVim("123");
173         int expectedResult = 1;
174         assertEquals(expectedResult, result);
175     }
176
177 }