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.onap.vfc.nfvo.res.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.onap.vfc.nfvo.res.common.VimUtil;
\r
26 import org.onap.vfc.nfvo.res.common.util.request.RequestUtil;
\r
27 import org.onap.vfc.nfvo.res.service.group.impl.ResOperateServiceImpl;
\r
28 import org.onap.vfc.nfvo.res.service.group.inf.ResOperateService;
\r
29 import org.onap.vfc.nfvo.res.service.rest.ResOperateRoa;
\r
30 import org.openo.baseservice.remoteservice.exception.ServiceException;
\r
31 import org.springframework.mock.web.MockHttpServletRequest;
\r
34 import mockit.MockUp;
\r
35 import net.sf.json.JSONObject;
\r
43 * @version NFVO 0.5 Mar 16, 2017
\r
45 public class ResOperateRoaTest {
\r
47 private ResOperateRoa roa;
\r
49 private ResOperateService resOperateService;
\r
52 public void setUp() {
\r
53 roa = new ResOperateRoa();
\r
54 resOperateService = new ResOperateServiceImpl();
\r
55 roa.setResOperateService(resOperateService);
\r
59 public void testUpdateIResPool() throws ServiceException {
\r
60 new MockUp<RequestUtil>() {
\r
63 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
64 return new JSONObject();
\r
67 new MockUp<VimUtil>() {
\r
70 public JSONObject getVimById(String vimId) {
\r
71 JSONObject vimInfo = new JSONObject();
\r
72 vimInfo.put("tenant", "tenant");
\r
77 public String getTenantIdByName(String tenant, String vimId) {
\r
81 new MockUp<ResOperateServiceImpl>() {
\r
84 public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException {
\r
88 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
91 HttpServletRequest mock = new MockHttpServletRequest();
\r
92 JSONObject result = roa.updateIResPool(mock, "vimId");
\r
93 assertNotNull(result);
\r
97 public void testUpdateIResPoolFail() throws ServiceException {
\r
98 new MockUp<RequestUtil>() {
\r
101 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
102 return new JSONObject();
\r
105 new MockUp<VimUtil>() {
\r
108 public JSONObject getVimById(String vimId) {
\r
109 JSONObject vimInfo = new JSONObject();
\r
110 vimInfo.put("tenant", "tenant");
\r
115 public String getTenantIdByName(String tenant, String vimId) {
\r
119 HttpServletRequest mock = new MockHttpServletRequest();
\r
120 JSONObject result = roa.updateIResPool(mock, null);
\r
121 assertNotNull(result);
\r
125 public void testAddAllResPool() throws ServiceException {
\r
126 new MockUp<RequestUtil>() {
\r
129 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
130 return new JSONObject();
\r
133 new MockUp<ResOperateServiceImpl>() {
\r
136 public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException {
\r
140 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
143 HttpServletRequest mock = new MockHttpServletRequest();
\r
144 JSONObject result = roa.addAllResPool(mock, "tenantId", "vimId");
\r
145 assertNotNull(result);
\r
149 public void testAddAllResPoolFail() throws ServiceException {
\r
150 new MockUp<RequestUtil>() {
\r
153 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
154 return new JSONObject();
\r
157 HttpServletRequest mock = new MockHttpServletRequest();
\r
158 JSONObject result = roa.addAllResPool(mock, null, null);
\r
159 assertNotNull(result);
\r
163 public void testDeleteIRes() throws ServiceException {
\r
164 new MockUp<ResOperateServiceImpl>() {
\r
167 public int deleteIRes(String vimId) throws ServiceException {
\r
172 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
175 HttpServletRequest mock = new MockHttpServletRequest();
\r
176 JSONObject result = roa.deleteIRes(mock, "vimId");
\r
177 assertNotNull(result);
\r
181 public void testDeleteIResFail() throws ServiceException {
\r
182 new MockUp<ResOperateServiceImpl>() {
\r
185 public int deleteIRes(String vimId) throws ServiceException {
\r
186 throw new ServiceException();
\r
190 public void sendMsgMonitor(String operateType, String vimId) throws ServiceException {
\r
193 HttpServletRequest mock = new MockHttpServletRequest();
\r
194 JSONObject result = roa.deleteIRes(mock, null);
\r
195 assertNotNull(result);
\r