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.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.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
\r
30 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.HostImpl;
\r
31 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Host;
\r
32 import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity;
\r
33 import org.onap.vfc.nfvo.resmanagement.service.rest.HostRoa;
\r
34 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
\r
35 import org.springframework.mock.web.MockHttpServletRequest;
\r
38 import mockit.MockUp;
\r
39 import net.sf.json.JSONObject;
\r
47 * @version NFVO 0.5 Feb 9, 2017
\r
49 public class HostRoaTest {
\r
51 private HostRoa roa;
\r
56 public void setUp() {
\r
57 roa = new HostRoa();
\r
58 host = new HostImpl();
\r
63 public void testGetHosts() throws ServiceException {
\r
64 new MockUp<HostImpl>() {
\r
67 public List<HostEntity> getList(Map<String, Object> condition) throws ServiceException {
\r
68 return new ArrayList<HostEntity>();
\r
71 HttpServletRequest mock = new MockHttpServletRequest();
\r
72 JSONObject result = roa.getHosts(mock);
\r
73 assertNotNull(result);
\r
77 public void testGetHost() throws ServiceException {
\r
78 new MockUp<HostImpl>() {
\r
81 public List<HostEntity> getList(Map<String, Object> condition) throws ServiceException {
\r
82 return new ArrayList<HostEntity>();
\r
85 HttpServletRequest mock = new MockHttpServletRequest();
\r
86 JSONObject result = roa.getHost(mock, "id");
\r
87 assertNotNull(result);
\r
91 public void testAddHost() throws ServiceException {
\r
92 new MockUp<RequestUtil>() {
\r
95 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
96 return new JSONObject();
\r
99 new MockUp<HostImpl>() {
\r
102 public int add(JSONObject jsonObject) throws ServiceException {
\r
106 HttpServletRequest mock = new MockHttpServletRequest();
\r
107 JSONObject result = roa.addHost(mock);
\r
108 assertNotNull(result);
\r
112 public void testAddHostByException() throws ServiceException {
\r
113 new MockUp<RequestUtil>() {
\r
116 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
117 return new JSONObject();
\r
120 new MockUp<HostImpl>() {
\r
123 public int add(JSONObject jsonObject) throws ServiceException {
\r
124 throw new ServiceException();
\r
127 HttpServletRequest mock = new MockHttpServletRequest();
\r
128 JSONObject result = roa.addHost(mock);
\r
129 assertNotNull(result);
\r
133 public void testDeleteHost() throws ServiceException {
\r
134 new MockUp<HostImpl>() {
\r
137 public int delete(String id) throws ServiceException {
\r
141 HttpServletRequest mock = new MockHttpServletRequest();
\r
142 JSONObject result = roa.deleteHost(mock, "id");
\r
143 assertNotNull(result);
\r
147 public void testDeleteHostByException() throws ServiceException {
\r
148 new MockUp<HostImpl>() {
\r
151 public int delete(String id) throws ServiceException {
\r
152 throw new ServiceException();
\r
155 HttpServletRequest mock = new MockHttpServletRequest();
\r
156 JSONObject result = roa.deleteHost(mock, "id");
\r
157 assertNotNull(result);
\r
161 public void testUpdateHost() throws ServiceException {
\r
162 new MockUp<RequestUtil>() {
\r
165 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
166 return new JSONObject();
\r
169 new MockUp<HostImpl>() {
\r
172 public int update(JSONObject jsonObject) throws ServiceException {
\r
176 HttpServletRequest mock = new MockHttpServletRequest();
\r
177 JSONObject result = roa.updateHost(mock);
\r
178 assertNotNull(result);
\r
182 public void testUpdateHostByException() throws ServiceException {
\r
183 new MockUp<RequestUtil>() {
\r
186 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
187 return new JSONObject();
\r
190 new MockUp<HostImpl>() {
\r
193 public int update(JSONObject jsonObject) throws ServiceException {
\r
194 throw new ServiceException();
\r
197 HttpServletRequest mock = new MockHttpServletRequest();
\r
198 JSONObject result = roa.updateHost(mock);
\r
199 assertNotNull(result);
\r