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.onap.vfc.nfvo.res.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.onap.vfc.nfvo.res.service.base.openstack.impl.HostImpl;
26 import org.onap.vfc.nfvo.res.service.business.impl.HostBusinessImpl;
27 import org.onap.vfc.nfvo.res.service.dao.impl.HostDaoImpl;
28 import org.onap.vfc.nfvo.res.service.entity.HostEntity;
29 import org.openo.baseservice.remoteservice.exception.ServiceException;
33 import net.sf.json.JSONObject;
35 public class HostImplTest {
38 public void testdeleteHostByVimId() throws ServiceException {
39 new MockUp<HostDaoImpl>() {
42 public int deleteHostByVimId(String vimId) {
47 HostImpl hostImpl = new HostImpl();
48 HostBusinessImpl hostBusiness = new HostBusinessImpl();
49 hostBusiness.setHostDao(new HostDaoImpl());
50 hostImpl.setHostBusiness(hostBusiness);
52 assertTrue(hostImpl.deleteResByVimId("vimId") == 1);
55 public void testupdateStatusByVimId() throws ServiceException {
56 HostImpl hostImpl = new HostImpl();
57 hostImpl.setHostBusiness(new HostBusinessImpl());
58 JSONObject json = new JSONObject();
59 json.put("id", "123");
60 json.put("vimId", "vim123");
61 new MockUp<HostBusinessImpl>() {
64 public int updateHostByVimId(HostEntity hostEntity) throws ServiceException {
68 int result = hostImpl.updateStatusByVimId(json);
69 int exceptedResult = 1;
70 assertEquals(exceptedResult, result);
74 public void testDelete() throws ServiceException {
75 HostImpl hostImpl = new HostImpl();
76 hostImpl.setHostBusiness(new HostBusinessImpl());
77 new MockUp<HostBusinessImpl>() {
79 public int deleteHost(String id) throws ServiceException {
84 int result = hostImpl.delete("id");
85 int exceptedResult = 1;
86 assertEquals(exceptedResult, result);
91 public void testAdd1() throws ServiceException {
92 HostImpl hostImpl = new HostImpl();
93 hostImpl.setHostBusiness(new HostBusinessImpl());
94 JSONObject json = new JSONObject();
96 new MockUp<HostBusinessImpl>() {
98 public int addHost(HostEntity hostEntity) throws ServiceException {
103 int result = hostImpl.add(json);
104 int exceptedResult = 1;
105 assertEquals(exceptedResult, result);
109 public void testupdate() throws ServiceException {
110 HostImpl hostImpl = new HostImpl();
111 hostImpl.setHostBusiness(new HostBusinessImpl());
112 HostEntity hostEntity = new HostEntity();
113 hostEntity.setId("123");
114 new MockUp<HostBusinessImpl>() {
116 public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
121 int result = hostImpl.update(hostEntity);
122 int exceptedResult = 1;
123 assertEquals(exceptedResult, result);
127 public void testUpdateResource() throws ServiceException {
128 HostImpl hostImpl = new HostImpl();
129 hostImpl.setHostBusiness(new HostBusinessImpl());
130 JSONObject json = new JSONObject();
131 json.put("id", "123");
132 json.put("vimId", "vim123");
133 new MockUp<HostBusinessImpl>() {
136 public int updateHostSelective(HostEntity hostEntity) throws ServiceException {
140 int result = hostImpl.update(json);
141 int exceptedResult = 1;
142 assertEquals(exceptedResult, result);
146 public void testGetList() throws ServiceException {
147 Map<String, Object> condition = new HashMap<>();
148 HostImpl hostImpl = new HostImpl();
149 hostImpl.setHostBusiness(new HostBusinessImpl());
150 new MockUp<HostBusinessImpl>() {
153 public List<HostEntity> getHosts(Map<String, Object> condition) {
157 List<HostEntity> result = hostImpl.getList(condition);
158 List<HostEntity> exceptedResult = null;
159 assertEquals(exceptedResult, result);