2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl;
19 import static org.junit.Assert.*;
21 import java.util.HashMap;
22 import java.util.List;
25 import org.junit.Test;
26 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.NetworkImpl;
27 import org.onap.vfc.nfvo.resmanagement.service.business.impl.NetworkBusinessImpl;
28 import org.onap.vfc.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl;
29 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NetworkDao;
30 import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity;
31 import org.openo.baseservice.remoteservice.exception.ServiceException;
35 import net.sf.json.JSONObject;
37 public class NetworkImplTest {
41 public void testAddBranch() throws ServiceException {
42 new MockUp<NetworkDaoImpl>() {
45 public NetworkEntity getNetwork(String id) {
50 public int addNetwork(NetworkEntity networkEntity) {
54 NetworkImpl networkImpl = new NetworkImpl();
55 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
56 NetworkDao networkDao = new NetworkDaoImpl();
57 networkBusiness.setNetworkDao(networkDao);
58 networkImpl.setNetworkBusiness(networkBusiness);
59 JSONObject json = new JSONObject();
61 json.put("name", "name");
62 json.put("status", "status");
63 json.put("tenant_id", "tenant_id");
64 json.put("vimId", "vimId");
65 json.put("vimName", "vimName");
66 json.put("provider:physical_network", "provider:physical_network");
67 json.put("provider:network_type", "provider:network_type");
68 json.put("provider:segmentation_id", "provider:segmentation_id");
69 assertTrue(networkImpl.add(json) == 1);
73 public void testAddBranch1() throws ServiceException {
74 new MockUp<NetworkDaoImpl>() {
77 public NetworkEntity getNetwork(String id) {
82 public int addNetwork(NetworkEntity networkEntity) {
86 NetworkImpl networkImpl = new NetworkImpl();
87 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
88 NetworkDao networkDao = new NetworkDaoImpl();
89 networkBusiness.setNetworkDao(networkDao);
90 networkImpl.setNetworkBusiness(networkBusiness);
91 JSONObject json = new JSONObject();
93 json.put("name", "name");
94 json.put("status", "status");
95 json.put("tenant_id", "tenant_id");
96 json.put("vimId", "vimId");
97 json.put("vimName", "vimName");
98 json.put("provider:physical_network", "provider:physical_network");
99 json.put("provider:network_type", "provider:network_type");
100 json.put("provider:segmentation_id", "provider:segmentation_id");
101 assertTrue(networkImpl.add(json) == 1);
104 @Test(expected = ServiceException.class)
105 public void testAddBranch2() throws ServiceException {
106 new MockUp<NetworkDaoImpl>() {
108 public NetworkEntity getNetwork(String id) {
113 public int addNetwork(NetworkEntity networkEntity) {
117 NetworkImpl networkImpl = new NetworkImpl();
118 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
119 NetworkDao networkDao = new NetworkDaoImpl();
120 networkBusiness.setNetworkDao(networkDao);
121 networkImpl.setNetworkBusiness(networkBusiness);
122 NetworkEntity entity = null;
123 networkImpl.add(entity);
129 public void testDelete() throws ServiceException {
130 new MockUp<NetworkDaoImpl>() {
133 public int deleteNetwork(String id) {
137 NetworkImpl networkImpl = new NetworkImpl();
138 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
139 NetworkDao networkDao = new NetworkDaoImpl();
140 networkBusiness.setNetworkDao(networkDao);
141 networkImpl.setNetworkBusiness(networkBusiness);
142 assertTrue(networkImpl.delete("id") == 1);
145 @Test(expected = ServiceException.class)
146 public void testDelete1() throws ServiceException {
148 NetworkImpl networkImpl = new NetworkImpl();
149 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
150 NetworkDao networkDao = new NetworkDaoImpl();
151 networkBusiness.setNetworkDao(networkDao);
152 networkImpl.setNetworkBusiness(networkBusiness);
153 networkImpl.delete("");
156 @Test(expected = ServiceException.class)
157 public void testDeleteVimByIdException() throws ServiceException {
159 NetworkImpl networkImpl = new NetworkImpl();
160 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
161 NetworkDao networkDao = new NetworkDaoImpl();
162 networkBusiness.setNetworkDao(networkDao);
163 networkImpl.setNetworkBusiness(networkBusiness);
164 networkImpl.deleteResByVimId("");
168 public void testDeleteVimById() throws ServiceException {
169 new MockUp<NetworkDaoImpl>() {
172 public int deleteNetworkByVimId(String vimId) {
176 NetworkImpl networkImpl = new NetworkImpl();
177 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
178 NetworkDao networkDao = new NetworkDaoImpl();
179 networkBusiness.setNetworkDao(networkDao);
180 networkImpl.setNetworkBusiness(networkBusiness);
181 assertTrue(networkImpl.deleteResByVimId("vimId") == 1);
186 public void testUpdate() throws ServiceException {
187 new MockUp<NetworkDaoImpl>() {
190 public int updateNetworkSelective(NetworkEntity networkEntity) {
194 NetworkImpl networkImpl = new NetworkImpl();
195 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
196 NetworkDao networkDao = new NetworkDaoImpl();
197 networkBusiness.setNetworkDao(networkDao);
198 networkImpl.setNetworkBusiness(networkBusiness);
200 JSONObject json = new JSONObject();
202 json.put("name", "name");
203 json.put("status", "status");
204 json.put("tenant_id", "tenant_id");
205 json.put("vimId", "vimId");
206 json.put("vimName", "vimName");
207 json.put("provider:physical_network", "provider:physical_network");
208 json.put("provider:network_type", "provider:network_type");
209 json.put("provider:segmentation_id", "provider:segmentation_id");
210 assertTrue(networkImpl.update(json)==1);
216 public void testUpdateVimById() throws ServiceException {
217 new MockUp<NetworkDaoImpl>() {
220 public int updateNetworkByVimId(NetworkEntity NetworkEntity) {
224 NetworkImpl networkImpl = new NetworkImpl();
225 NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl();
226 NetworkDao networkDao = new NetworkDaoImpl();
227 networkBusiness.setNetworkDao(networkDao);
228 networkImpl.setNetworkBusiness(networkBusiness);
229 JSONObject json = new JSONObject();
231 json.put("name", "name");
232 json.put("status", "status");
233 json.put("tenant_id", "tenant_id");
234 json.put("vimId", "vimId");
235 json.put("vimName", "vimName");
236 json.put("provider:physical_network", "provider:physical_network");
237 json.put("provider:network_type", "provider:network_type");
238 json.put("provider:segmentation_id", "provider:segmentation_id");
239 assertTrue(networkImpl.updateStatusByVimId(json)==1);
244 public void testgetList() throws ServiceException {
245 Map<String, Object> condition = new HashMap<>();
246 NetworkImpl networkImpl = new NetworkImpl();
247 networkImpl.setNetworkBusiness(new NetworkBusinessImpl());
248 new MockUp<NetworkBusinessImpl>() {
251 public List<NetworkEntity> getNetworks(Map<String, Object> condition) {
255 List<NetworkEntity> result = networkImpl.getList(condition);
256 List<NetworkEntity> exceptedResult = null;
257 assertEquals(exceptedResult, result);
260 public void testadd() throws ServiceException {
261 NetworkImpl networkImpl = new NetworkImpl();
262 networkImpl.setNetworkBusiness(new NetworkBusinessImpl());
263 NetworkEntity networkEntity =new NetworkEntity();
264 networkEntity.setId("1");
265 new MockUp<NetworkBusinessImpl>() {
268 public int addNetwork(NetworkEntity networkEntity ) {
272 int result = networkImpl.add(networkEntity);
273 int exceptedResult = 1;
274 assertEquals(exceptedResult, result);