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 java.util.ArrayList;
\r
22 import java.util.List;
\r
23 import java.util.Map;
\r
25 import javax.servlet.http.HttpServletRequest;
\r
27 import org.junit.Before;
\r
28 import org.junit.Test;
\r
29 import org.openo.baseservice.remoteservice.exception.ServiceException;
\r
30 import org.openo.nfvo.resmanagement.common.util.request.RequestUtil;
\r
31 import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity;
\r
32 import org.openo.nfvo.resmanagement.service.group.impl.VnfStatusServiceImpl;
\r
33 import org.openo.nfvo.resmanagement.service.group.inf.VnfStatusService;
\r
34 import org.springframework.mock.web.MockHttpServletRequest;
\r
37 import mockit.MockUp;
\r
38 import net.sf.json.JSONObject;
\r
46 * @version NFVO 0.5 Feb 10, 2017
\r
48 public class VnfStatusRoaTest {
\r
50 private VnfStatusRoa roa;
\r
52 private VnfStatusService vnfStatusService;
\r
55 public void setUp() {
\r
56 roa = new VnfStatusRoa();
\r
57 vnfStatusService = new VnfStatusServiceImpl();
\r
58 roa.setVnfStatusService(vnfStatusService);
\r
62 public void testGetVnfStatuss() throws ServiceException {
\r
63 new MockUp<VnfStatusServiceImpl>() {
\r
66 public List<VnfStatusEntity> getList(Map<String, Object> map) throws ServiceException {
\r
67 return new ArrayList<VnfStatusEntity>();
\r
70 HttpServletRequest mock = new MockHttpServletRequest();
\r
71 JSONObject result = roa.getVnfStatuss(mock);
\r
72 assertNotNull(result);
\r
76 public void testGetVnfStatus() throws ServiceException {
\r
77 new MockUp<VnfStatusServiceImpl>() {
\r
80 public List<VnfStatusEntity> getList(Map<String, Object> map) throws ServiceException {
\r
81 return new ArrayList<VnfStatusEntity>();
\r
84 HttpServletRequest mock = new MockHttpServletRequest();
\r
85 JSONObject result = roa.getVnfStatus(mock, "id");
\r
86 assertNotNull(result);
\r
90 public void testAddVnfStatus() throws ServiceException {
\r
91 new MockUp<RequestUtil>() {
\r
94 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
95 return new JSONObject();
\r
98 new MockUp<VnfStatusServiceImpl>() {
\r
101 public JSONObject addVnfStatus(JSONObject object) throws ServiceException {
\r
102 return new JSONObject();
\r
105 HttpServletRequest mock = new MockHttpServletRequest();
\r
106 JSONObject result = roa.addVnfStatus(mock);
\r
107 assertNotNull(result);
\r
111 public void testAddVnfStatusByException() throws ServiceException {
\r
112 new MockUp<RequestUtil>() {
\r
115 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
116 return new JSONObject();
\r
119 new MockUp<VnfStatusServiceImpl>() {
\r
122 public JSONObject addVnfStatus(JSONObject object) throws ServiceException {
\r
123 throw new ServiceException();
\r
126 HttpServletRequest mock = new MockHttpServletRequest();
\r
127 JSONObject result = roa.addVnfStatus(mock);
\r
128 assertNotNull(result);
\r
131 @Test(expected = ServiceException.class)
\r
132 public void testAddVnfStatusByNull() throws ServiceException {
\r
133 new MockUp<RequestUtil>() {
\r
136 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
140 HttpServletRequest mock = new MockHttpServletRequest();
\r
141 roa.addVnfStatus(mock);
\r
145 public void testDeleteVnfStatus() throws ServiceException {
\r
146 new MockUp<VnfStatusServiceImpl>() {
\r
149 public int delete(String id) throws ServiceException {
\r
153 HttpServletRequest mock = new MockHttpServletRequest();
\r
154 JSONObject result = roa.deleteVnfStatus(mock, "id");
\r
155 assertNotNull(result);
\r
159 public void testDeleteVnfStatusByException() throws ServiceException {
\r
160 new MockUp<VnfStatusServiceImpl>() {
\r
163 public int delete(String id) throws ServiceException {
\r
164 throw new ServiceException();
\r
167 HttpServletRequest mock = new MockHttpServletRequest();
\r
168 JSONObject result = roa.deleteVnfStatus(mock, "id");
\r
169 assertNotNull(result);
\r
172 @Test(expected = ServiceException.class)
\r
173 public void testDeleteVnfStatusByNull() throws ServiceException {
\r
174 HttpServletRequest mock = new MockHttpServletRequest();
\r
175 roa.deleteVnfStatus(mock, null);
\r