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.onap.vfc.nfvo.vnfm.gvnfm.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.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.StringUtil;
26 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.adapter.impl.JujuClientManager;
27 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.process.VnfMgr;
28 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest.JujuClientRoa;
29 import org.openo.baseservice.remoteservice.exception.ServiceException;
30 import org.springframework.mock.web.MockHttpServletResponse;
34 import net.sf.json.JSONObject;
36 public class JujuClientRoaTest {
43 roa = new JujuClientRoa();
44 roa.setJujuClientManager(new JujuClientManager());
45 roa.getJujuClientManager();
50 public void setCharmUrlTest() throws ServiceException {
51 new MockUp<StringUtil>(){
53 public <T> T getJsonFromContexts(HttpServletRequest context) {
54 String reqJsonObject = "{}";
55 return (T)JSONObject.fromObject(reqJsonObject);
58 HttpServletRequest context = null;
59 HttpServletResponse resp = new MockHttpServletResponse();
60 String res = roa.setCharmUrl(context, resp);
64 public void getVnfStatusTest() throws ServiceException {
65 HttpServletRequest context = null;
66 HttpServletResponse resp = new MockHttpServletResponse();
67 String res = roa.getVnfStatus("appName", context,resp);
71 public void deploySerivceTestFail() throws ServiceException {
72 new MockUp<StringUtil>(){
74 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
78 HttpServletRequest context = null;
79 HttpServletResponse resp = new MockHttpServletResponse();
80 String res = roa.deploySerivce(context,resp);
84 public void deploySerivceTest() throws ServiceException {
85 new MockUp<StringUtil>(){
87 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
88 JSONObject reqJsonObject = new JSONObject();
89 reqJsonObject.put("charmPath", "/abc/xyz");
90 reqJsonObject.put("mem", "100");
91 reqJsonObject.put("appName", "test");
92 return (T)reqJsonObject;
95 HttpServletRequest context = null;
96 HttpServletResponse resp = new MockHttpServletResponse();
97 String res = roa.deploySerivce(context,resp);
102 public void destroySerivceTestFail() throws ServiceException {
103 new MockUp<StringUtil>(){
105 public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
106 JSONObject reqJsonObject = new JSONObject();
107 reqJsonObject.put("charmPath", "/abc/xyz");
108 reqJsonObject.put("mem", "100");
109 reqJsonObject.put("appName", "test");
110 return (T)reqJsonObject;
113 HttpServletRequest context = null;
114 HttpServletResponse resp = new MockHttpServletResponse();
115 String res = roa.destroySerivce(context,resp);
119 // public void destroySerivce2TestFail() throws ServiceException {
120 // new MockUp<StringUtil>(){
122 // public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
123 // JSONObject reqJsonObject = new JSONObject();
124 // reqJsonObject.put("appName", "test");
125 // return (T)reqJsonObject;
128 // HttpServletRequest context = null;
129 // HttpServletResponse resp = new MockHttpServletResponse();
130 // String res = roa.destroySerivce(context,resp);
131 // assertNotNull(res);