2 * Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.nfvo.jujuvnfmadapter.service.rest;
18 import static org.junit.Assert.assertNotNull;
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
26 import org.openo.nfvo.jujuvnfmadapter.common.StringUtil;
27 import org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.JujuClientManager;
28 import org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr;
29 import org.springframework.mock.web.MockHttpServletResponse;
33 import net.sf.json.JSONObject;
35 public class JujuClientRoaTest {
42 roa = new JujuClientRoa();
43 roa.setJujuClientManager(new JujuClientManager());
44 roa.getJujuClientManager();
49 public void setCharmUrlTest() throws ServiceException {
50 new MockUp<StringUtil>(){
52 public <T> T getJsonFromContexts(HttpServletRequest context) {
53 String reqJsonObject = "{}";
54 return (T)JSONObject.fromObject(reqJsonObject);
57 HttpServletRequest context = null;
58 HttpServletResponse resp = new MockHttpServletResponse();
59 String res = roa.setCharmUrl(context, resp);
63 public void getVnfStatusTest() throws ServiceException {
64 HttpServletRequest context = null;
65 HttpServletResponse resp = new MockHttpServletResponse();
66 String res = roa.getVnfStatus("appName", context,resp);
70 public void deploySerivceTestFail() throws ServiceException {
71 new MockUp<StringUtil>(){
73 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
77 HttpServletRequest context = null;
78 HttpServletResponse resp = new MockHttpServletResponse();
79 String res = roa.deploySerivce(context,resp);
83 public void deploySerivceTest() throws ServiceException {
84 new MockUp<StringUtil>(){
86 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
87 JSONObject reqJsonObject = new JSONObject();
88 reqJsonObject.put("charmPath", "/abc/xyz");
89 reqJsonObject.put("mem", "100");
90 reqJsonObject.put("appName", "test");
91 return (T)reqJsonObject;
94 HttpServletRequest context = null;
95 HttpServletResponse resp = new MockHttpServletResponse();
96 String res = roa.deploySerivce(context,resp);
101 public void destroySerivceTestFail() throws ServiceException {
102 new MockUp<StringUtil>(){
104 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
105 JSONObject reqJsonObject = new JSONObject();
106 reqJsonObject.put("charmPath", "/abc/xyz");
107 reqJsonObject.put("mem", "100");
108 reqJsonObject.put("appName", "test");
109 return (T)reqJsonObject;
112 HttpServletRequest context = null;
113 HttpServletResponse resp = new MockHttpServletResponse();
114 String res = roa.destroySerivce(context,resp);
118 // public void destroySerivce2TestFail() throws ServiceException {
119 // new MockUp<StringUtil>(){
121 // public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
122 // JSONObject reqJsonObject = new JSONObject();
123 // reqJsonObject.put("appName", "test");
124 // return (T)reqJsonObject;
127 // HttpServletRequest context = null;
128 // HttpServletResponse resp = new MockHttpServletResponse();
129 // String res = roa.destroySerivce(context,resp);
130 // assertNotNull(res);