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.util.request.RequestUtil;
\r
27 import org.openo.nfvo.resmanagement.service.group.impl.GrantResServiceImpl;
\r
28 import org.openo.nfvo.resmanagement.service.group.inf.GrantResService;
\r
29 import org.springframework.mock.web.MockHttpServletRequest;
\r
32 import mockit.MockUp;
\r
33 import net.sf.json.JSONObject;
\r
41 * @version NFVO 0.5 Mar 16, 2017
\r
43 public class GrantResourseRoaTest {
\r
45 private GrantResourseRoa roa;
\r
47 private GrantResService grantResService;
\r
50 public void setUp() {
\r
51 roa = new GrantResourseRoa();
\r
52 grantResService = new GrantResServiceImpl();
\r
53 roa.setGrantResService(grantResService);
\r
57 public void testGrantResource() throws ServiceException {
\r
58 new MockUp<RequestUtil>() {
\r
61 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
62 return new JSONObject();
\r
65 new MockUp<GrantResServiceImpl>() {
\r
68 public JSONObject grantResource(JSONObject object) throws ServiceException {
\r
69 return new JSONObject();
\r
72 HttpServletRequest mock = new MockHttpServletRequest();
\r
73 JSONObject result = roa.grantResource(mock);
\r
74 assertNotNull(result);
\r
77 @Test(expected = ServiceException.class)
\r
78 public void testGrantResourceByNull() throws ServiceException {
\r
79 new MockUp<RequestUtil>() {
\r
82 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
86 HttpServletRequest mock = new MockHttpServletRequest();
\r
87 JSONObject result = roa.grantResource(mock);
\r
88 assertNotNull(result);
\r
92 public void testGrantResourceFail() throws ServiceException {
\r
93 new MockUp<RequestUtil>() {
\r
96 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
97 return new JSONObject();
\r
100 new MockUp<GrantResServiceImpl>() {
\r
103 public JSONObject grantResource(JSONObject object) throws ServiceException {
\r
104 throw new ServiceException();
\r
107 HttpServletRequest mock = new MockHttpServletRequest();
\r
108 JSONObject result = roa.grantResource(mock);
\r
109 assertNotNull(result);
\r
113 public void testGrantResourceReal() throws ServiceException {
\r
114 new MockUp<RequestUtil>() {
\r
117 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
118 return new JSONObject();
\r
121 new MockUp<GrantResServiceImpl>() {
\r
124 public JSONObject grantResourceReal(JSONObject object) throws ServiceException {
\r
125 return new JSONObject();
\r
128 HttpServletRequest mock = new MockHttpServletRequest();
\r
129 JSONObject result = roa.grantResourceReal(mock);
\r
130 assertNotNull(result);
\r
133 @Test(expected = ServiceException.class)
\r
134 public void testGrantResourceRealByNull() throws ServiceException {
\r
135 new MockUp<RequestUtil>() {
\r
138 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
142 HttpServletRequest mock = new MockHttpServletRequest();
\r
143 roa.grantResourceReal(mock);
\r
147 public void testGrantResourceRealFail() throws ServiceException {
\r
148 new MockUp<RequestUtil>() {
\r
151 public JSONObject getJsonRequestBody(HttpServletRequest context) {
\r
152 return new JSONObject();
\r
155 new MockUp<GrantResServiceImpl>() {
\r
158 public JSONObject grantResourceReal(JSONObject object) throws ServiceException {
\r
159 throw new ServiceException();
\r
162 HttpServletRequest mock = new MockHttpServletRequest();
\r
163 JSONObject result = roa.grantResourceReal(mock);
\r
164 assertNotNull(result);
\r