2 * Copyright 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.
16 package org.openo.nfvo.resmanagement.service.base.openstack.impl;
18 import static org.junit.Assert.*;
20 import java.util.HashMap;
21 import java.util.List;
24 import org.junit.Test;
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
26 import org.openo.nfvo.resmanagement.service.business.impl.HostBusinessImpl;
27 import org.openo.nfvo.resmanagement.service.dao.impl.HostDaoImpl;
28 import org.openo.nfvo.resmanagement.service.entity.HostEntity;
32 import net.sf.json.JSONObject;
34 public class HostImplTest {
37 public void testdeleteHostByVimId() throws ServiceException {
38 new MockUp<HostDaoImpl>() {
41 public int deleteHostByVimId(String vimId) {
46 HostImpl hostImpl = new HostImpl();
47 HostBusinessImpl hostBusiness = new HostBusinessImpl();
48 hostBusiness.setHostDao(new HostDaoImpl());
49 hostImpl.setHostBusiness(hostBusiness);
51 assertTrue(hostImpl.deleteResByVimId("vimId") == 1);
54 public void testupdateStatusByVimId() throws ServiceException {
55 HostImpl hostImpl = new HostImpl();
56 hostImpl.setHostBusiness(new HostBusinessImpl());
57 JSONObject json = new JSONObject();
58 json.put("id", "123");
59 json.put("vimId", "vim123");
60 new MockUp<HostBusinessImpl>() {
63 public int updateHostByVimId(HostEntity hostEntity) throws ServiceException {
67 int result = hostImpl.updateStatusByVimId(json);
68 int exceptedResult = 1;
69 assertEquals(exceptedResult, result);
73 public void testDelete() throws ServiceException {
74 HostImpl hostImpl = new HostImpl();
75 hostImpl.setHostBusiness(new HostBusinessImpl());
76 new MockUp<HostBusinessImpl>() {
78 public int deleteHost(String id) throws ServiceException {
83 int result = hostImpl.delete("id");
84 int exceptedResult = 1;
85 assertEquals(exceptedResult, result);
90 public void testAdd1() throws ServiceException {
91 HostImpl hostImpl = new HostImpl();
92 hostImpl.setHostBusiness(new HostBusinessImpl());
93 JSONObject json = new JSONObject();
95 new MockUp<HostBusinessImpl>() {
97 public int addHost(HostEntity hostEntity) throws ServiceException {
102 int result = hostImpl.add(json);
103 int exceptedResult = 1;
104 assertEquals(exceptedResult, result);
108 public void testupdate() throws ServiceException {
109 HostImpl hostImpl = new HostImpl();
110 hostImpl.setHostBusiness(new HostBusinessImpl());
111 HostEntity hostEntity = new HostEntity();
112 hostEntity.setId("123");
113 new MockUp<HostBusinessImpl>() {
115 public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
120 int result = hostImpl.update(hostEntity);
121 int exceptedResult = 1;
122 assertEquals(exceptedResult, result);
126 public void testUpdateResource() throws ServiceException {
127 HostImpl hostImpl = new HostImpl();
128 hostImpl.setHostBusiness(new HostBusinessImpl());
129 JSONObject json = new JSONObject();
130 json.put("id", "123");
131 json.put("vimId", "vim123");
132 new MockUp<HostBusinessImpl>() {
135 public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
139 int result = hostImpl.update(json);
140 int exceptedResult = 1;
141 assertEquals(exceptedResult, result);
145 public void testGetList() throws ServiceException {
146 Map<String, Object> condition = new HashMap<>();
147 HostImpl hostImpl = new HostImpl();
148 hostImpl.setHostBusiness(new HostBusinessImpl());
149 new MockUp<HostBusinessImpl>() {
152 public List<HostEntity> getHosts(Map<String, Object> condition) {
156 List<HostEntity> result = hostImpl.getList(condition);
157 List<HostEntity> exceptedResult = null;
158 assertEquals(exceptedResult, result);