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