31d8bcdfc1a512dad7633937a77fb41489c083cb
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / gvnfm / jujuvnfmadapter / service / rest / VnfRoaTest.java
1 /*
2  * Copyright 2016 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.*;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.core.Context;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.StringUtil;
28 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.entity.JujuVnfmInfo;
29 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.process.VnfMgr;
30 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest.VnfRoa;
31 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException;
32 import org.springframework.mock.web.MockHttpServletResponse;
33
34 import mockit.Mock;
35 import mockit.MockUp;
36 import net.sf.json.JSONObject;
37
38 public class VnfRoaTest {
39     
40     VnfRoa roa = new VnfRoa();
41     @Before
42     public void setUp(){
43         roa.setVnfMgr(new VnfMgr());
44     }
45     
46     @Test
47     public void addVnfTestNull() throws ServiceException{
48         new MockUp<StringUtil>(){
49             @Mock
50             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
51                 return null;
52             }
53         };
54         HttpServletRequest context = null;
55         HttpServletResponse resp = new MockHttpServletResponse();
56         String vnfmId = "1234";
57         String res = roa.addVnf(context, resp, vnfmId);
58         assertNotNull(res);
59     }
60     
61     @Test
62     public void addVnfTest() throws ServiceException{
63         new MockUp<StringUtil>(){
64             @Mock
65             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
66                 String vnfJsonStr = "{}";
67                 return (T)JSONObject.fromObject(vnfJsonStr);
68             }
69         };
70         HttpServletRequest context = null;
71         HttpServletResponse resp = new MockHttpServletResponse();
72         String vnfmId = "1234";
73         String res = roa.addVnf(context, resp, vnfmId);
74         assertNotNull(res);
75     }
76     @Test
77     public void delVnfTestNull() throws ServiceException{
78         new MockUp<StringUtil>(){
79             @Mock
80             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
81                 return null;
82             }
83         };
84         new MockUp<VnfMgr>(){
85             @Mock
86             private JujuVnfmInfo findByVnfId(String vnfId){
87                 JujuVnfmInfo info = new JujuVnfmInfo();
88                 info.setVnfmId("1234");
89                 return info;
90             }
91         };
92         HttpServletRequest context = null;
93         HttpServletResponse resp = new MockHttpServletResponse();
94         String vnfmId = "1234";
95         String res = roa.delVnf("vnfmId", resp, "vnfInstanceId",context);
96         assertNotNull(res);
97     }
98     @Test
99     public void delVnf2TestNull() throws ServiceException{
100         new MockUp<StringUtil>(){
101             @Mock
102             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
103                 return null;
104             }
105         };
106         HttpServletRequest context = null;
107         HttpServletResponse resp = new MockHttpServletResponse();
108         String vnfmId = "1234";
109         String res = roa.delVnf(null, resp, "vnfInstanceId",context);
110         assertNotNull(res);
111     }
112     @Test
113     public void delVnf3TestNull() throws ServiceException{
114         new MockUp<StringUtil>(){
115             @Mock
116             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
117                 return null;
118             }
119         };
120         HttpServletRequest context = null;
121         HttpServletResponse resp = new MockHttpServletResponse();
122         String vnfmId = "1234";
123         String res = roa.delVnf(vnfmId, resp, null,context);
124         assertNotNull(res);
125     }
126     @Test
127     public void getVnf1TestNull() throws ServiceException{
128         new MockUp<StringUtil>(){
129             @Mock
130             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
131                 return null;
132             }
133         };
134         new MockUp<VnfMgr>(){
135             @Mock
136             private JujuVnfmInfo findByVnfId(String vnfId){
137                 JujuVnfmInfo info = new JujuVnfmInfo();
138                 info.setVnfmId("1234");
139                 return info;
140             }
141         };
142         HttpServletRequest context = null;
143         HttpServletResponse resp = new MockHttpServletResponse();
144         String vnfmId = "1234";
145         String res = roa.getVnf(vnfmId, resp, "vnfInstanceId",context);
146         assertNotNull(res);
147     }
148     @Test
149     public void getVnf2TestNull() throws ServiceException{
150         new MockUp<StringUtil>(){
151             @Mock
152             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
153                 return null;
154             }
155         };
156         HttpServletRequest context = null;
157         HttpServletResponse resp = new MockHttpServletResponse();
158         String vnfmId = "1234";
159         String res = roa.getVnf(null, resp, "vnfInstanceId",context);
160         assertNotNull(res);
161     }
162     @Test
163     public void getVnf3TestNull() throws ServiceException{
164         new MockUp<StringUtil>(){
165             @Mock
166             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
167                 return null;
168             }
169         };
170         HttpServletRequest context = null;
171         HttpServletResponse resp = new MockHttpServletResponse();
172         String vnfmId = "1234";
173         String res = roa.getVnf(vnfmId, resp, null,context);
174         assertNotNull(res);
175     }
176     @Test
177     public void getJobTestNull() throws ServiceException{
178         HttpServletResponse resp = new MockHttpServletResponse();
179         String res = roa.getJob("jobId", "vnfmId", resp,"responseId");
180         assertNotNull(res);
181     }
182     @Test
183     public void getJobTest2Null() throws ServiceException{
184         HttpServletResponse resp = new MockHttpServletResponse();
185         String res = roa.getJob(null, "vnfmId", resp,"responseId");
186         assertNotNull(res);
187     }
188     @Test
189     public void getJobTest3Null() throws ServiceException{
190         HttpServletResponse resp = new MockHttpServletResponse();
191         String res = roa.getJob("jobId", null, resp,"responseId");
192         assertNotNull(res);
193     }
194     
195     @Test
196     public void getJobTestNormal() throws ServiceException{
197         new MockUp<VnfMgr>(){
198             @Mock
199             public JSONObject getJob(String jobId, String vnfmId) {
200                 JSONObject obj = new JSONObject();
201                 JSONObject dataObj = new JSONObject();
202                 dataObj.put("id", "1234");
203                 dataObj.put("status", "Success");
204                 obj.put("data", dataObj);
205                 obj.put("retCode", 1);
206                 return obj;
207             }
208             
209         };
210         HttpServletResponse resp = new MockHttpServletResponse();
211         String res = roa.getJob("jobId", "vnfmId", resp,"responseId");
212         assertNotNull(res);
213     }
214     
215
216 }