4f02669b832a6b5605c9bcab409c28c05eb6208e
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / openo / nfvo / jujuvnfmadapter / service / rest / JujuClientRoaTest.java
1 /*
2  * Copyright 2016-2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openo.nfvo.jujuvnfmadapter.service.rest;
17
18 import static org.junit.Assert.assertNotNull;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22
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;
30
31 import mockit.Mock;
32 import mockit.MockUp;
33 import net.sf.json.JSONObject;
34
35 public class JujuClientRoaTest {
36
37     JujuClientRoa roa;
38
39
40     @Before
41     public void setUp(){
42         roa = new JujuClientRoa();
43         roa.setJujuClientManager(new JujuClientManager());
44         roa.getJujuClientManager();
45
46     }
47
48     @Test
49     public void setCharmUrlTest() throws ServiceException {
50        new MockUp<StringUtil>(){
51            @Mock
52            public <T> T getJsonFromContexts(HttpServletRequest context) {
53                String reqJsonObject = "{}";
54                return (T)JSONObject.fromObject(reqJsonObject);
55            }
56        };
57         HttpServletRequest context = null;
58         HttpServletResponse resp = new MockHttpServletResponse();
59         String res = roa.setCharmUrl(context, resp);
60         assertNotNull(res);
61     }
62     @Test
63     public void getVnfStatusTest() throws ServiceException {
64         HttpServletRequest context = null;
65         HttpServletResponse resp = new MockHttpServletResponse();
66         String res = roa.getVnfStatus("appName", context,resp);
67         assertNotNull(res);
68     }
69     @Test
70     public void deploySerivceTestFail() throws ServiceException {
71         new MockUp<StringUtil>(){
72             @Mock
73             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
74                 return null;
75             }
76         };
77         HttpServletRequest context = null;
78         HttpServletResponse resp = new MockHttpServletResponse();
79         String res = roa.deploySerivce(context,resp);
80         assertNotNull(res);
81     }
82     @Test
83     public void deploySerivceTest() throws ServiceException {
84         new MockUp<StringUtil>(){
85             @Mock
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;
92             }
93         };
94         HttpServletRequest context = null;
95         HttpServletResponse resp = new MockHttpServletResponse();
96         String res = roa.deploySerivce(context,resp);
97         assertNotNull(res);
98     }
99
100     @Test
101     public void destroySerivceTestFail() throws ServiceException {
102         new MockUp<StringUtil>(){
103             @Mock
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;
110             }
111         };
112         HttpServletRequest context = null;
113         HttpServletResponse resp = new MockHttpServletResponse();
114         String res = roa.destroySerivce(context,resp);
115         assertNotNull(res);
116     }
117 //    @Test
118 //    public void destroySerivce2TestFail() throws ServiceException {
119 //        new MockUp<StringUtil>(){
120 //            @Mock
121 //            public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
122 //                JSONObject reqJsonObject = new JSONObject();
123 //                reqJsonObject.put("appName", "test");
124 //                return (T)reqJsonObject;
125 //            }
126 //        };
127 //        HttpServletRequest context = null;
128 //        HttpServletResponse resp = new MockHttpServletResponse();
129 //        String res = roa.destroySerivce(context,resp);
130 //        assertNotNull(res);
131 //    }
132 }