2 * Copyright 2016 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.res.service.base.openstack.impl;
19 import static org.junit.Assert.assertEquals;
21 import java.util.List;
23 import org.junit.Test;
24 import org.onap.vfc.nfvo.res.service.base.openstack.impl.VimImpl;
25 import org.onap.vfc.nfvo.res.service.business.impl.VimBusinessImpl;
26 import org.onap.vfc.nfvo.res.service.entity.VimEntity;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
31 import net.sf.json.JSONObject;
33 public class VimImplTest {
36 public void testAdd() throws ServiceException {
37 VimImpl vimImpl = new VimImpl();
38 vimImpl.setVimBusiness(new VimBusinessImpl());
39 new MockUp<VimBusinessImpl>() {
42 public int addVim(String id) throws ServiceException {
46 int result = vimImpl.add("id");
47 int exceptedResult = 1;
48 assertEquals(exceptedResult, result);
52 public void testAdd1() throws ServiceException {
53 VimImpl vimImpl = new VimImpl();
54 vimImpl.setVimBusiness(new VimBusinessImpl());
55 JSONObject json = new JSONObject();
56 json.put("id", "123");
57 new MockUp<VimBusinessImpl>() {
60 public int addVim(String id) throws ServiceException {
64 int result = vimImpl.add(json);
65 int exceptedResult = 1;
66 assertEquals(exceptedResult, result);
70 public void testUpdate() throws ServiceException {
71 VimImpl vimImpl = new VimImpl();
72 vimImpl.setVimBusiness(new VimBusinessImpl());
73 JSONObject json = new JSONObject();
74 json.put("id", "123");
75 json.put("vimId", "vim123");
76 int result = vimImpl.update(json);
77 int exceptedResult = 0;
78 assertEquals(exceptedResult, result);
82 public void testDelete() throws ServiceException {
83 VimImpl vimImpl = new VimImpl();
84 vimImpl.setVimBusiness(new VimBusinessImpl());
85 new MockUp<VimBusinessImpl>() {
88 public int deleteVim(String id) throws ServiceException {
92 int result = vimImpl.delete("id");
93 int exceptedResult = 1;
94 assertEquals(exceptedResult, result);
98 public void testGetVim() throws ServiceException {
99 VimImpl vimImpl = new VimImpl();
100 vimImpl.setVimBusiness(new VimBusinessImpl());
101 new MockUp<VimBusinessImpl>() {
104 public VimEntity getVim(String id) {
108 VimEntity result = vimImpl.getVim("id");
109 VimEntity exceptedResult = null;
110 assertEquals(exceptedResult, result);
114 public void testGetList() throws ServiceException {
115 VimImpl vimImpl = new VimImpl();
116 vimImpl.setVimBusiness(new VimBusinessImpl());
117 new MockUp<VimBusinessImpl>() {
120 public List<VimEntity> getVims() {
124 List<VimEntity> result = vimImpl.getList();
125 List<VimEntity> exceptedResult = null;
126 assertEquals(exceptedResult, result);
130 public void testSetVimBusiness() throws ServiceException {
131 VimImpl vimImpl = new VimImpl();
132 vimImpl.setVimBusiness(new VimBusinessImpl());