2 * Copyright 2017 Huawei Technologies Co., Ltd.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.openo.nfvo.resmanagement.service.rest;
\r
19 import static org.junit.Assert.assertNotNull;
\r
21 import javax.servlet.http.HttpServletRequest;
\r
23 import org.junit.Before;
\r
24 import org.junit.Test;
\r
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
\r
26 import org.openo.nfvo.resmanagement.common.VimUtil;
\r
27 import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
\r
28 import org.openo.nfvo.resmanagement.service.group.impl.ResOperateServiceImpl;
\r
29 import org.openo.nfvo.resmanagement.service.group.inf.ResOperateService;
\r
30 import org.springframework.mock.web.MockHttpServletRequest;
\r
33 import mockit.MockUp;
\r
34 import net.sf.json.JSONObject;
\r
42 * @version NFVO 0.5 Mar 16, 2017
\r
44 public class ResOperateRoaTest {
\r
46 private ResOperateRoa roa;
\r
48 private ResOperateService resOperateService;
\r
51 public void setUp() {
\r
52 roa = new ResOperateRoa();
\r
53 resOperateService = new ResOperateServiceImpl();
\r
54 roa.setResOperateService(resOperateService);
\r
58 public void testUpdateIResPool() throws ServiceException {
\r
59 new MockUp<RequestUtil>() {
\r
62 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
63 return new JSONObject();
\r
66 new MockUp<VimUtil>() {
\r
69 public JSONObject getVimById(String vimId) {
\r
70 JSONObject vimInfo = new JSONObject();
\r
71 vimInfo.put("tenant", "tenant");
\r
76 public String getTenantIdByName(String tenant, String vimId) {
\r
80 new MockUp<ResOperateServiceImpl>() {
\r
83 public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException {
\r
87 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
90 HttpServletRequest mock = new MockHttpServletRequest();
\r
91 JSONObject result = roa.updateIResPool(mock, "vimId");
\r
92 assertNotNull(result);
\r
96 public void testUpdateIResPoolFail() throws ServiceException {
\r
97 new MockUp<RequestUtil>() {
\r
100 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
101 return new JSONObject();
\r
104 new MockUp<VimUtil>() {
\r
107 public JSONObject getVimById(String vimId) {
\r
108 JSONObject vimInfo = new JSONObject();
\r
109 vimInfo.put("tenant", "tenant");
\r
114 public String getTenantIdByName(String tenant, String vimId) {
\r
118 HttpServletRequest mock = new MockHttpServletRequest();
\r
119 JSONObject result = roa.updateIResPool(mock, null);
\r
120 assertNotNull(result);
\r
124 public void testAddAllResPool() throws ServiceException {
\r
125 new MockUp<RequestUtil>() {
\r
128 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
129 return new JSONObject();
\r
132 new MockUp<ResOperateServiceImpl>() {
\r
135 public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException {
\r
139 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
142 HttpServletRequest mock = new MockHttpServletRequest();
\r
143 JSONObject result = roa.addAllResPool(mock, "tenantId", "vimId");
\r
144 assertNotNull(result);
\r
148 public void testAddAllResPoolFail() throws ServiceException {
\r
149 new MockUp<RequestUtil>() {
\r
152 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
153 return new JSONObject();
\r
156 HttpServletRequest mock = new MockHttpServletRequest();
\r
157 JSONObject result = roa.addAllResPool(mock, null, null);
\r
158 assertNotNull(result);
\r
162 public void testDeleteIRes() throws ServiceException {
\r
163 new MockUp<ResOperateServiceImpl>() {
\r
166 public int deleteIRes(String vimId) throws ServiceException {
\r
171 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
174 HttpServletRequest mock = new MockHttpServletRequest();
\r
175 JSONObject result = roa.deleteIRes(mock, "vimId");
\r
176 assertNotNull(result);
\r
180 public void testDeleteIResFail() throws ServiceException {
\r
181 new MockUp<ResOperateServiceImpl>() {
\r
184 public int deleteIRes(String vimId) throws ServiceException {
\r
185 throw new ServiceException();
\r
189 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
192 HttpServletRequest mock = new MockHttpServletRequest();
\r
193 JSONObject result = roa.deleteIRes(mock, null);
\r
194 assertNotNull(result);
\r