Update gvnfm-driver .gitreview file
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / gvnfm / 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.onap.vfc.nfvo.vnfm.gvnfm.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.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;
31
32 import mockit.Mock;
33 import mockit.MockUp;
34 import net.sf.json.JSONObject;
35
36 public class JujuClientRoaTest {
37
38     JujuClientRoa roa;
39
40
41     @Before
42     public void setUp(){
43         roa = new JujuClientRoa();
44         roa.setJujuClientManager(new JujuClientManager());
45         roa.getJujuClientManager();
46
47     }
48
49     @Test
50     public void setCharmUrlTest() throws ServiceException {
51        new MockUp<StringUtil>(){
52            @Mock
53            public <T> T getJsonFromContexts(HttpServletRequest context) {
54                String reqJsonObject = "{}";
55                return (T)JSONObject.fromObject(reqJsonObject);
56            }
57        };
58         HttpServletRequest context = null;
59         HttpServletResponse resp = new MockHttpServletResponse();
60         String res = roa.setCharmUrl(context, resp);
61         assertNotNull(res);
62     }
63     @Test
64     public void getVnfStatusTest() throws ServiceException {
65         HttpServletRequest context = null;
66         HttpServletResponse resp = new MockHttpServletResponse();
67         String res = roa.getVnfStatus("appName", context,resp);
68         assertNotNull(res);
69     }
70     @Test
71     public void deploySerivceTestFail() throws ServiceException {
72         new MockUp<StringUtil>(){
73             @Mock
74             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
75                 return null;
76             }
77         };
78         HttpServletRequest context = null;
79         HttpServletResponse resp = new MockHttpServletResponse();
80         String res = roa.deploySerivce(context,resp);
81         assertNotNull(res);
82     }
83     @Test
84     public void deploySerivceTest() throws ServiceException {
85         new MockUp<StringUtil>(){
86             @Mock
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;
93             }
94         };
95         HttpServletRequest context = null;
96         HttpServletResponse resp = new MockHttpServletResponse();
97         String res = roa.deploySerivce(context,resp);
98         assertNotNull(res);
99     }
100
101     @Test
102     public void destroySerivceTestFail() throws ServiceException {
103         new MockUp<StringUtil>(){
104             @Mock
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;
111             }
112         };
113         HttpServletRequest context = null;
114         HttpServletResponse resp = new MockHttpServletResponse();
115         String res = roa.destroySerivce(context,resp);
116         assertNotNull(res);
117     }
118 //    @Test
119 //    public void destroySerivce2TestFail() throws ServiceException {
120 //        new MockUp<StringUtil>(){
121 //            @Mock
122 //            public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
123 //                JSONObject reqJsonObject = new JSONObject();
124 //                reqJsonObject.put("appName", "test");
125 //                return (T)reqJsonObject;
126 //            }
127 //        };
128 //        HttpServletRequest context = null;
129 //        HttpServletResponse resp = new MockHttpServletResponse();
130 //        String res = roa.destroySerivce(context,resp);
131 //        assertNotNull(res);
132 //    }
133 }