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 javax.servlet.http.HttpServletRequest;
\r
23 import org.junit.Before;
\r
24 import org.junit.Test;
\r
25 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
\r
26 import org.onap.vfc.nfvo.resmanagement.service.group.impl.GrantResServiceImpl;
\r
27 import org.onap.vfc.nfvo.resmanagement.service.group.inf.GrantResService;
\r
28 import org.onap.vfc.nfvo.resmanagement.service.rest.GrantResourseRoa;
\r
29 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
\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 GrantResourseRoaTest {
\r
46 private GrantResourseRoa roa;
\r
48 private GrantResService grantResService;
\r
51 public void setUp() {
\r
52 roa = new GrantResourseRoa();
\r
53 grantResService = new GrantResServiceImpl();
\r
54 roa.setGrantResService(grantResService);
\r
58 public void testGrantResource() throws ServiceException {
\r
59 new MockUp<RequestUtil>() {
\r
62 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
63 return new JSONObject();
\r
66 new MockUp<GrantResServiceImpl>() {
\r
69 public JSONObject grantResource(JSONObject object) throws ServiceException {
\r
70 return new JSONObject();
\r
73 HttpServletRequest mock = new MockHttpServletRequest();
\r
74 JSONObject result = roa.grantResource(mock);
\r
75 assertNotNull(result);
\r
78 @Test(expected = ServiceException.class)
\r
79 public void testGrantResourceByNull() throws ServiceException {
\r
80 new MockUp<RequestUtil>() {
\r
83 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
87 HttpServletRequest mock = new MockHttpServletRequest();
\r
88 JSONObject result = roa.grantResource(mock);
\r
89 assertNotNull(result);
\r
93 public void testGrantResourceFail() throws ServiceException {
\r
94 new MockUp<RequestUtil>() {
\r
97 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
98 return new JSONObject();
\r
101 new MockUp<GrantResServiceImpl>() {
\r
104 public JSONObject grantResource(JSONObject object) throws ServiceException {
\r
105 throw new ServiceException();
\r
108 HttpServletRequest mock = new MockHttpServletRequest();
\r
109 JSONObject result = roa.grantResource(mock);
\r
110 assertNotNull(result);
\r
114 public void testGrantResourceReal() throws ServiceException {
\r
115 new MockUp<RequestUtil>() {
\r
118 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
119 return new JSONObject();
\r
122 new MockUp<GrantResServiceImpl>() {
\r
125 public JSONObject grantResourceReal(JSONObject object) throws ServiceException {
\r
126 return new JSONObject();
\r
129 HttpServletRequest mock = new MockHttpServletRequest();
\r
130 JSONObject result = roa.grantResourceReal(mock);
\r
131 assertNotNull(result);
\r
134 @Test(expected = ServiceException.class)
\r
135 public void testGrantResourceRealByNull() throws ServiceException {
\r
136 new MockUp<RequestUtil>() {
\r
139 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
143 HttpServletRequest mock = new MockHttpServletRequest();
\r
144 roa.grantResourceReal(mock);
\r
148 public void testGrantResourceRealFail() throws ServiceException {
\r
149 new MockUp<RequestUtil>() {
\r
152 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
153 return new JSONObject();
\r
156 new MockUp<GrantResServiceImpl>() {
\r
159 public JSONObject grantResourceReal(JSONObject object) throws ServiceException {
\r
160 throw new ServiceException();
\r
163 HttpServletRequest mock = new MockHttpServletRequest();
\r
164 JSONObject result = roa.grantResourceReal(mock);
\r
165 assertNotNull(result);
\r