5db06a8cd589f7f29d09a4870dc725e91b7427c3
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016-2017 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.base.openstack.impl;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.junit.Test;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
28 import org.openo.nfvo.resmanagement.service.business.impl.SitesBusinessImpl;
29 import org.openo.nfvo.resmanagement.service.entity.SitesEntity;
30
31 import mockit.Mock;
32 import mockit.MockUp;
33 import net.sf.json.JSONObject;
34
35 public class SitesImplTest {
36
37
38
39         @Test
40         public void testUpdate1() throws ServiceException {
41             SitesImpl sitesImpl = new SitesImpl();
42             sitesImpl.setSitesBusiness(new SitesBusinessImpl());
43             SitesEntity sitesEntity = new SitesEntity();
44             sitesEntity.setId("123");
45             new MockUp<SitesBusinessImpl>() {
46
47                 @Mock
48                 public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException {
49                     return 1;
50                 }
51             };
52             int result = sitesImpl.update(sitesEntity);
53             int exceptedResult = 1;
54             assertEquals(exceptedResult, result);
55         }
56
57     @Test
58     public void testUpdateResource() throws ServiceException {
59         SitesImpl sitesImpl = new SitesImpl();
60         sitesImpl.setSitesBusiness(new SitesBusinessImpl());
61         JSONObject json = new JSONObject();
62         json.put("id", "123");
63         json.put("vimId", "vim123");
64         new MockUp<SitesBusinessImpl>() {
65
66             @Mock
67             public int updateSiteResource(SitesEntity sitesEntity) throws ServiceException {
68                 return 1;
69             }
70         };
71         int result = sitesImpl.updateResource(json);
72         int exceptedResult = 1;
73         assertEquals(exceptedResult, result);
74     }
75
76     @Test
77     public void testUpdateStatusByVimId() throws ServiceException {
78         SitesImpl sitesImpl = new SitesImpl();
79         sitesImpl.setSitesBusiness(new SitesBusinessImpl());
80         JSONObject json = new JSONObject();
81         json.put("id", "123");
82         json.put("vimId", "vim123");
83         new MockUp<SitesBusinessImpl>() {
84
85             @Mock
86             public int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException {
87                 return 1;
88             }
89         };
90         int result = sitesImpl.updateStatusByVimId(json);
91         int exceptedResult = 1;
92         assertEquals(exceptedResult, result);
93     }
94
95     @Test
96     public void testGetList() throws ServiceException {
97         Map<String, Object> condition = new HashMap<>();
98         SitesImpl sitesImpl = new SitesImpl();
99         sitesImpl.setSitesBusiness(new SitesBusinessImpl());
100         new MockUp<SitesBusinessImpl>() {
101
102             @Mock
103             public List<SitesEntity> getSites(Map<String, Object> condition) {
104                 return null;
105             }
106         };
107         List<SitesEntity> result = sitesImpl.getList(condition);
108         List<SitesEntity> exceptedResult = null;
109         assertEquals(exceptedResult, result);
110     }
111
112     @Test
113     public void testGetNull() throws ServiceException {
114         Map<String, Object> condition = new HashMap<>();
115         SitesImpl sitesImpl = new SitesImpl();
116         sitesImpl.setSitesBusiness(new SitesBusinessImpl());
117         new MockUp<SitesBusinessImpl>() {
118
119             @Mock
120             public List<SitesEntity> getSites(Map<String, Object> condition) {
121                 return null;
122             }
123         };
124         SitesEntity result = sitesImpl.get(condition);
125         SitesEntity exceptedResult = null;
126         assertEquals(exceptedResult, result);
127     }
128
129     @Test
130     public void testGet() throws ServiceException {
131         Map<String, Object> condition = new HashMap<>();
132         SitesImpl sitesImpl = new SitesImpl();
133         sitesImpl.setSitesBusiness(new SitesBusinessImpl());
134         new MockUp<SitesBusinessImpl>() {
135
136             @Mock
137             public List<SitesEntity> getSites(Map<String, Object> condition) {
138                 List<SitesEntity> list = new ArrayList<SitesEntity>();
139                 return list;
140             }
141         };
142         SitesEntity sitesEntity = new SitesEntity();
143         sitesEntity.setId("123");
144         sitesImpl.deleteResByVimId("vimId");
145         SitesEntity result = sitesImpl.get(condition);
146     }
147
148 }