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.assertTrue;
21 import org.junit.Test;
22 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
23 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.PortImpl;
24 import org.onap.vfc.nfvo.resmanagement.service.business.impl.PortBusinessImpl;
25 import org.onap.vfc.nfvo.resmanagement.service.dao.impl.PortDaoImpl;
26 import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
31 import net.sf.json.JSONObject;
33 public class PortImplTest {
36 public void testAddBranch() throws ServiceException {
37 new MockUp<PortDaoImpl>() {
40 public PortEntity getPort(String id) {
45 public int addPort(PortEntity portEntity) {
49 PortImpl portImpl = new PortImpl();
50 PortBusinessImpl portBusiness = new PortBusinessImpl();
51 portBusiness.setPortDao(new PortDaoImpl());
52 portImpl.setPortBusiness(portBusiness);
53 JSONObject json = new JSONObject();
55 json.put("name", "name");
56 json.put("status", "status");
57 json.put("tenant_id", "tenant_id");
58 json.put("vimId", "vimId");
59 json.put("vimName", "vimName");
60 json.put("network_id", "network_id");
61 assertTrue(portImpl.add(json) == 1);
64 @Test(expected = ServiceException.class)
65 public void testAddBranch1() throws ServiceException {
67 PortImpl portImpl = new PortImpl();
68 PortBusinessImpl portBusiness = new PortBusinessImpl();
69 portBusiness.setPortDao(new PortDaoImpl());
70 portImpl.setPortBusiness(portBusiness);
71 PortEntity portEntity = null;
72 portImpl.add(portEntity);
75 @Test(expected = ServiceException.class)
76 public void testUpdateException() throws ServiceException {
78 PortImpl portImpl = new PortImpl();
79 PortBusinessImpl portBusiness = new PortBusinessImpl();
80 portBusiness.setPortDao(new PortDaoImpl());
81 portImpl.setPortBusiness(portBusiness);
82 PortEntity portEntity = null;
83 portImpl.update(portEntity);
87 public void testUpdate() throws ServiceException {
88 new MockUp<PortDaoImpl>() {
91 public int updatePortSelective(PortEntity portEntity) {
96 PortImpl portImpl = new PortImpl();
97 PortBusinessImpl portBusiness = new PortBusinessImpl();
98 portBusiness.setPortDao(new PortDaoImpl());
99 portImpl.setPortBusiness(portBusiness);
100 assertTrue(portImpl.update(new JSONObject()) == 1);
104 public void testdelete() throws ServiceException {
105 new MockUp<PortDaoImpl>() {
108 public int deletePort(String id) {
113 PortImpl portImpl = new PortImpl();
114 PortBusinessImpl portBusiness = new PortBusinessImpl();
115 portBusiness.setPortDao(new PortDaoImpl());
116 portImpl.setPortBusiness(portBusiness);
121 public void testDeleteResByVimId() throws ServiceException {
122 new MockUp<PortDaoImpl>() {
125 public int deletePortByVimId(String vimId) {
130 PortImpl portImpl = new PortImpl();
131 PortBusinessImpl portBusiness = new PortBusinessImpl();
132 portBusiness.setPortDao(new PortDaoImpl());
133 portImpl.setPortBusiness(portBusiness);
134 assertTrue(portImpl.deleteResByVimId("vimId") == 1);
137 @Test(expected = ServiceException.class)
138 public void testDeleteResByVimIdException() throws ServiceException {
139 PortImpl portImpl = new PortImpl();
140 PortBusinessImpl portBusiness = new PortBusinessImpl();
141 portBusiness.setPortDao(new PortDaoImpl());
142 portImpl.setPortBusiness(portBusiness);
143 portImpl.deleteResByVimId("");
146 @Test(expected = ServiceException.class)
147 public void testDelete() throws ServiceException {
148 PortImpl portImpl = new PortImpl();
149 PortBusinessImpl portBusiness = new PortBusinessImpl();
150 portBusiness.setPortDao(new PortDaoImpl());
151 portImpl.setPortBusiness(portBusiness);