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.openo.nfvo.resmanagement.service.base.openstack.impl;
19 import static org.junit.Assert.assertTrue;
21 import org.junit.Test;
22 import org.openo.baseservice.remoteservice.exception.ServiceException;
23 import org.openo.nfvo.resmanagement.common.util.JsonUtil;
24 import org.openo.nfvo.resmanagement.service.business.impl.PortBusinessImpl;
25 import org.openo.nfvo.resmanagement.service.dao.impl.PortDaoImpl;
26 import org.openo.nfvo.resmanagement.service.entity.PortEntity;
30 import net.sf.json.JSONObject;
32 public class PortImplTest {
35 public void testAddBranch() throws ServiceException {
36 new MockUp<PortDaoImpl>() {
39 public PortEntity getPort(String id) {
44 public int addPort(PortEntity portEntity) {
48 PortImpl portImpl = new PortImpl();
49 PortBusinessImpl portBusiness = new PortBusinessImpl();
50 portBusiness.setPortDao(new PortDaoImpl());
51 portImpl.setPortBusiness(portBusiness);
52 JSONObject json = new JSONObject();
54 json.put("name", "name");
55 json.put("status", "status");
56 json.put("tenant_id", "tenant_id");
57 json.put("vimId", "vimId");
58 json.put("vimName", "vimName");
59 json.put("network_id", "network_id");
60 assertTrue(portImpl.add(json) == 1);
63 @Test(expected = ServiceException.class)
64 public void testAddBranch1() throws ServiceException {
66 PortImpl portImpl = new PortImpl();
67 PortBusinessImpl portBusiness = new PortBusinessImpl();
68 portBusiness.setPortDao(new PortDaoImpl());
69 portImpl.setPortBusiness(portBusiness);
70 PortEntity portEntity = null;
71 portImpl.add(portEntity);
74 @Test(expected = ServiceException.class)
75 public void testUpdateException() throws ServiceException {
77 PortImpl portImpl = new PortImpl();
78 PortBusinessImpl portBusiness = new PortBusinessImpl();
79 portBusiness.setPortDao(new PortDaoImpl());
80 portImpl.setPortBusiness(portBusiness);
81 PortEntity portEntity = null;
82 portImpl.update(portEntity);
86 public void testUpdate() throws ServiceException {
87 new MockUp<PortDaoImpl>() {
90 public int updatePortSelective(PortEntity portEntity) {
95 PortImpl portImpl = new PortImpl();
96 PortBusinessImpl portBusiness = new PortBusinessImpl();
97 portBusiness.setPortDao(new PortDaoImpl());
98 portImpl.setPortBusiness(portBusiness);
99 assertTrue(portImpl.update(new JSONObject()) == 1);
103 public void testdelete() throws ServiceException {
104 new MockUp<PortDaoImpl>() {
107 public int deletePort(String id) {
112 PortImpl portImpl = new PortImpl();
113 PortBusinessImpl portBusiness = new PortBusinessImpl();
114 portBusiness.setPortDao(new PortDaoImpl());
115 portImpl.setPortBusiness(portBusiness);
120 public void testDeleteResByVimId() throws ServiceException {
121 new MockUp<PortDaoImpl>() {
124 public int deletePortByVimId(String vimId) {
129 PortImpl portImpl = new PortImpl();
130 PortBusinessImpl portBusiness = new PortBusinessImpl();
131 portBusiness.setPortDao(new PortDaoImpl());
132 portImpl.setPortBusiness(portBusiness);
133 assertTrue(portImpl.deleteResByVimId("vimId") == 1);
136 @Test(expected = ServiceException.class)
137 public void testDeleteResByVimIdException() throws ServiceException {
138 PortImpl portImpl = new PortImpl();
139 PortBusinessImpl portBusiness = new PortBusinessImpl();
140 portBusiness.setPortDao(new PortDaoImpl());
141 portImpl.setPortBusiness(portBusiness);
142 portImpl.deleteResByVimId("");
145 @Test(expected = ServiceException.class)
146 public void testDelete() throws ServiceException {
147 PortImpl portImpl = new PortImpl();
148 PortBusinessImpl portBusiness = new PortBusinessImpl();
149 portBusiness.setPortDao(new PortDaoImpl());
150 portImpl.setPortBusiness(portBusiness);