9205d30fc8f674e8509af8e79f15054402fb1947
[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.base.openstack.impl;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.util.List;
22
23 import org.junit.Test;
24 import org.onap.vfc.nfvo.res.service.base.openstack.impl.VimImpl;
25 import org.onap.vfc.nfvo.res.service.business.impl.VimBusinessImpl;
26 import org.onap.vfc.nfvo.res.service.entity.VimEntity;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
28
29 import mockit.Mock;
30 import mockit.MockUp;
31 import net.sf.json.JSONObject;
32
33 public class VimImplTest {
34
35     @Test
36     public void testAdd() throws ServiceException {
37         VimImpl vimImpl = new VimImpl();
38         vimImpl.setVimBusiness(new VimBusinessImpl());
39         new MockUp<VimBusinessImpl>() {
40
41             @Mock
42             public int addVim(String id) throws ServiceException {
43                 return 1;
44             }
45         };
46         int result = vimImpl.add("id");
47         int exceptedResult = 1;
48         assertEquals(exceptedResult, result);
49     }
50
51     @Test
52     public void testAdd1() throws ServiceException {
53         VimImpl vimImpl = new VimImpl();
54         vimImpl.setVimBusiness(new VimBusinessImpl());
55         JSONObject json = new JSONObject();
56         json.put("id", "123");
57         new MockUp<VimBusinessImpl>() {
58
59             @Mock
60             public int addVim(String id) throws ServiceException {
61                 return 1;
62             }
63         };
64         int result = vimImpl.add(json);
65         int exceptedResult = 1;
66         assertEquals(exceptedResult, result);
67     }
68
69     @Test
70     public void testUpdate() throws ServiceException {
71         VimImpl vimImpl = new VimImpl();
72         vimImpl.setVimBusiness(new VimBusinessImpl());
73         JSONObject json = new JSONObject();
74         json.put("id", "123");
75         json.put("vimId", "vim123");
76         int result = vimImpl.update(json);
77         int exceptedResult = 0;
78         assertEquals(exceptedResult, result);
79     }
80
81     @Test
82     public void testDelete() throws ServiceException {
83         VimImpl vimImpl = new VimImpl();
84         vimImpl.setVimBusiness(new VimBusinessImpl());
85         new MockUp<VimBusinessImpl>() {
86
87             @Mock
88             public int deleteVim(String id) throws ServiceException {
89                 return 1;
90             }
91         };
92         int result = vimImpl.delete("id");
93         int exceptedResult = 1;
94         assertEquals(exceptedResult, result);
95     }
96
97     @Test
98     public void testGetVim() throws ServiceException {
99         VimImpl vimImpl = new VimImpl();
100         vimImpl.setVimBusiness(new VimBusinessImpl());
101         new MockUp<VimBusinessImpl>() {
102
103             @Mock
104             public VimEntity getVim(String id) {
105                 return null;
106             }
107         };
108         VimEntity result = vimImpl.getVim("id");
109         VimEntity exceptedResult = null;
110         assertEquals(exceptedResult, result);
111     }
112
113     @Test
114     public void testGetList() throws ServiceException {
115         VimImpl vimImpl = new VimImpl();
116         vimImpl.setVimBusiness(new VimBusinessImpl());
117         new MockUp<VimBusinessImpl>() {
118
119             @Mock
120             public List<VimEntity> getVims() {
121                 return null;
122             }
123         };
124         List<VimEntity> result = vimImpl.getList();
125         List<VimEntity> exceptedResult = null;
126         assertEquals(exceptedResult, result);
127     }
128
129     @Test
130     public void testSetVimBusiness() throws ServiceException {
131         VimImpl vimImpl = new VimImpl();
132         vimImpl.setVimBusiness(new VimBusinessImpl());
133     }
134
135 }